directxtransparencydirectx-11alphablendingcolor-blending

How can I adjust the transparency with DirectX 11?


I'm trying to make transparent object like a colored glass or water and I succeeded in making it. but I don't know how to adjust it's tranparency. Am I trying to do the impossible?

The scene is rendered with simple calculation of color and lighting. and not using texture mapping in this program

I tried changing Blend state desc, blend factor, samplemask

but I'm not sure it was right.

Here is my Blendstate desc

BlendStateDesc.AlphaToCoverageEnable = false;
BlendStateDesc.IndependentBlendEnable = false;
BlendStateDesc.RenderTarget[0].BlendEnable = true;
BlendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_COLOR;
BlendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
BlendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
BlendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
BlendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
BlendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
BlendStateDesc.RenderTarget[0].RenderTargetWriteMask 
=D3D11_COLOR_WRITE_ENABLE_ALL;

and setting

float bf[] = { 0.f,0.f,0.f,0.f };

pDeviceContext->OMSetBlendState(m_pd3dBlendState, bf, 0xffffffff);

Solution

  • I will assume this is DX11 and that the part you are missing is actually in your shader.

    In your pixel shader, you will be returning a float4 rgba. The "a" value will control the values applied to the calculation. This value is between 0 and 1. If you could post your pixel shader code, that would help confirm/deny the solution.