alpha blending when rendering to a texture
Posted: 05 Jan 2017, 19:39
I am trying to render with transparency to a texture which is then embedded within my 3d scene..
The texture is generated, but the alpha values from the xaml surface is clamped to zero or one.. fully transparent anywhere the source alpha is zero or fully opaque with any alpha value greater than zero.
When I render the same xaml surface on top of my framebuffer as an overlay, it composes properly and background colors with alpha apply as expected..
I have the suspicion that the blend state inside IRenderer::Render() is something like:
blendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MAX;
blendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
and the alpha value from the source is not preserved in the destination buffer.
For rendering to an offline texture I would expect a blend state something like:
blendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
This should allow the alpha value to flow through to the destination.
Is there an option in the SDK to allow alpha to be applied to the output color buffer? Or is there a way to alter the applied blend state?
The texture is generated, but the alpha values from the xaml surface is clamped to zero or one.. fully transparent anywhere the source alpha is zero or fully opaque with any alpha value greater than zero.
When I render the same xaml surface on top of my framebuffer as an overlay, it composes properly and background colors with alpha apply as expected..
I have the suspicion that the blend state inside IRenderer::Render() is something like:
blendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MAX;
blendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
and the alpha value from the source is not preserved in the destination buffer.
For rendering to an offline texture I would expect a blend state something like:
blendStateDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
This should allow the alpha value to flow through to the destination.
Is there an option in the SDK to allow alpha to be applied to the output color buffer? Or is there a way to alter the applied blend state?