I'm trying to render transparent pixels in directX 11 and I'm not sure if I'm supposed to make a shader or if the blend state does this automatically. Earlier I thought it was done automatically but my transparent texture is rendering as a solid color that misses every over texel. The original texture is (7, 7, 7, 139) and the rendered color is (38, 47, 56, 255).
blendStateDescription.AlphaToCoverageEnable = TRUE;
blendStateDescription.IndependentBlendEnable = FALSE;
blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
pixel shader
float4 TexturePixelShader(PixelInputType input) : SV_TARGET {
float4 textureColor;
textureColor = shaderTexture.Sample(SampleType, input.tex);
//discard pink for sprite transparency
if(textureColor.r == 1.0f && textureColor.g == 0.0f && textureColor.b == 1.0f) {
discard;
}
//set the colour white as the specified pixel colour
if(textureColor.r == 1.0f && textureColor.g == 1.0f && textureColor.b == 1.0f) {
textureColor = textureColor * pixelColor;
}
return textureColor;
}