0
我想在directX 11中渲染透明像素,我不確定是否應該使着色或混合狀態自動執行此操作。 早些時候我認爲它是自動完成的,但我的透明紋理呈現爲一種純粹的顏色,忽略了每個紋理元素。 原始紋理是(7,7,7,139),渲染的顏色是(38,47,56,255)。DirectX 11透明混合缺少每一個其他紋素
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;
像素着色
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;
}
當我這樣做時,屏幕變黑,但我猜這可以通過配置混合描述來解決。感謝您的幫助:D – Anthony
是的,修復它。只想說一個巨大的謝謝:)我一直在這個尷尬的時間長度。上帝保佑,照顧<3 – Anthony
不客氣。 –