Jump to content
  • Advertisement
Sign in to follow this  
SavHarOct

DX11 No blending, something missing?

This topic is 455 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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;
}

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!