No blending, something missing?

Started by
4 comments, last by SavHarOct 7 years ago
Hi, new here. I have been dealing with the Frank Luna's programming book codes for a while, and I am having problems with the blending part. My code has been changed to not use the Effect11 framework. Instead I have been using pre-compiled PS/VS shaders (or compiled shaders during built time) and managing resources/shaders using a solution he posted in his blog due Win8+ no longer supporting the D3DX11 library, I am also using DirecXTK for texture loading. Those are the changes made vs the original code.
I think I have everything set up but it doesn't seem to work, no blending. I omitted all the irrelevant code
RenderStates.cpp (RenderStates is a static class)



ComPtr<ID3D11BlendState> RenderStates::transBlendSt = 0;
ComPtr<ID3D11BlendState> RenderStates::normalBlendSt = 0;

void RenderStates::InitAll(ID3D11Device* dev)
{
D3D11_BLEND_DESC desc1 = {0};
desc1.AlphaToCoverageEnable = false;
desc1.IndependentBlendEnable = false;
desc1.RenderTarget[0].BlendEnable = true;
desc1.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
desc1.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
desc1.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc1.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
desc1.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
desc1.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc1.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;


//Transparent Blend State
HR( dev->CreateBlendState(&desc1, &transBlendSt) );


D3D11_BLEND_DESC desc2 = {0};
desc2.AlphaToCoverageEnable = true;
desc2.IndependentBlendEnable = false;
desc2.RenderTarget[0].BlendEnable = false;
desc2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;


//Normal Blend State
HR( dev->CreateBlendState(&desc2, &normalBlendSt) );


} 
Main.cpp


bool InitD3D::Init()
{ 
   RenderStates::InitAll(md3dDevice);
}

//Its using the DirectXTK texture loading function
void InitD3D::LoadTextures()
{ 
  HRESULT h = CoInitialize(NULL);
 h = DirectX::CreateDDSTextureFromFile(md3dDevice, L"Directory.../Textures/grass.dds", nullptr, &mHillTex);
 if(!SUCCEEDED(h))
 {
  MessageBox(0, L"Failed loading texture ", L"Loading Texture", 0);
  return;
 }

  h = DirectX::CreateDDSTextureFromFile(md3dDevice, L"Directory.../Textures/water1.dds", nullptr, &mWavesTex);
  if(!SUCCEEDED(h))
 {
   MessageBox(0, L"Failed loading texture ", L"Loading Texture", 0);
   return;
  }
}


void InitD3D::DrawScene()
{

md3dImmediateContext->OMSetBlendState(RenderStates::normalBlendSt.Get(), 0, 0xffffffff);

/* Other resources for the Hill set here */

md3dImmediateContext->PSSetShaderResources(0, 1, mHillTex.GetAddressOf()); //Hill texture/SRV

/* Draw Hills here */


float blendF[] = {0.0f, 0.0f, 0.0f, 0.0f};
md3dImmediateContext->OMSetBlendState(RenderStates::transBlendSt.Get(), blendF, 0xffffffff);

/* Other resources for the Waves set here */

md3dImmediateContext->PSSetShaderResources(0, 1, mWavesTex.GetAddressOf()); //Wave texture/SRV

/* Draw Waves here */

}
My results
90MT7U5.png
Can anyone can help to figure out what I might be missing here? if you need any other part of the code or anything else let me know. Thank you.
Advertisement

Sorry to ask the obvious, but what does the alpha channel of your wave texture look like? What does the pixel shader used for the waves output in the alpha channel?

Sorry to ask the obvious, but what does the alpha channel of your wave texture look like? What does the pixel shader used for the waves output in the alpha channel?

Interesting questions to me, might reveal what I am missing.

1. The texture used for the wave is a .dds file which is provided by the author of the book, I haven't modified it or anything. I am not sure whether if has alpha channel or not. Anyway I could find that out?

2. This is what my pixel shader looks like, no operations using alpha channel other that using the alpha component of the texture and the diffuse material.


float4 main(VertexOut vin) : SV_TARGET
{
	vin.NormW = normalize(vin.NormW);
	float3 toEye = normalize(gEyePos - vin.PosW);

    float4 ambient = float4(0.0f, 0.0f, 0.0f, 0.0f);
	float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
	float4 specular = float4(0.0f, 0.0f, 0.0f, 0.0f);

	
	float4 A, D, S;
	[unroll]
	for(int i = 0; i < 3; i++)
	{
	  ComputeDirectionalLight(gMaterial, dirLight[i], vin.NormW, toEye, A, D, S);
	  ambient += A;
	  diffuse += D;
	  specular += S;
	}
	
    float4 TexColor = diffuseMap.Sample(anisotropic, vin.TexC0); //Sample from the texture

	float4 LitColor = TexColor * (ambient + diffuse) + specular;

	LitColor.a = gMaterial.Diffuse.a * TexColor.a;

	return LitColor;
}

The texture used for the wave is a .dds file which is provided by the author of the book, I haven't modified it or anything. I am not sure whether if has alpha channel or not. Anyway I could find that out?

Use a tool that can view DDS textures, like DDSView: https://github.com/Microsoft/DirectXTex

Your pixel shader looks like it supports an alpha channel in the Diffuse color property of your material. What are you passing for that value?

You can use visual studio to check DDS textures too. https://msdn.microsoft.com/en-us/library/hh873119.aspx

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

The texture used for the wave is a .dds file which is provided by the author of the book, I haven't modified it or anything. I am not sure whether if has alpha channel or not. Anyway I could find that out?

Use a tool that can view DDS textures, like DDSView: https://github.com/Microsoft/DirectXTex

Your pixel shader looks like it supports an alpha channel in the Diffuse color property of your material. What are you passing for that value?

Thanks both of you, the alpha channel is a completely blank image (white).


	//Land material properties
	mLandMaterial.Diffuse  = XMFLOAT4(0.48f, 0.77f, 0.46f, 1.0f);

	//Wave material properties
	mWaveMaterial.Diffuse  = XMFLOAT4(0.137f, 0.42f, 0.556f, 1.0f); 

And just 1 is what get passed to it, I have tried omitting that operation as well on the PS and still no difference. Its really strange.

This topic is closed to new replies.

Advertisement