Skip to content

Commit 769afe4

Browse files
PBR Renderer: compute total transmittance in alpha channel
1 parent 8ebf20c commit 769afe4

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

PBR/src/PBR_Renderer.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,33 +2051,32 @@ void PBR_Renderer::CreatePSO(PsoHashMapType& PsoHashMap,
20512051
else if (AlphaMode == ALPHA_MODE_BLEND)
20522052
{
20532053
VERIFY(!IsUnshaded, "Unshaded mode should use OpaquePSO. The PSOKey's ctor sets the alpha mode to opaque.");
2054+
RT0.BlendEnable = True;
20542055
if (OITLayerCount > 0)
20552056
{
20562057
// Use additive blending for OIT
2057-
RT0.BlendEnable = True;
2058-
RT0.SrcBlend = BLEND_FACTOR_ONE;
2059-
RT0.DestBlend = BLEND_FACTOR_ONE;
2060-
RT0.BlendOp = BLEND_OPERATION_ADD;
2061-
RT0.SrcBlendAlpha = BLEND_FACTOR_ONE;
2062-
RT0.DestBlendAlpha = BLEND_FACTOR_ONE;
2063-
RT0.BlendOpAlpha = BLEND_OPERATION_ADD;
2064-
// NB: Do NOT overwrite RenderTargetWriteMask
2058+
RT0.SrcBlend = BLEND_FACTOR_ONE;
2059+
RT0.DestBlend = BLEND_FACTOR_ONE;
2060+
RT0.BlendOp = BLEND_OPERATION_ADD;
20652061

20662062
// Disable depth writes, but keep depth testing enabled
20672063
GraphicsPipeline.DepthStencilDesc.DepthWriteEnable = False;
20682064
}
20692065
else
20702066
{
20712067
// Premultiplied alpha blending
2072-
RT0.BlendEnable = True;
2073-
RT0.SrcBlend = BLEND_FACTOR_ONE;
2074-
RT0.DestBlend = BLEND_FACTOR_INV_SRC_ALPHA;
2075-
RT0.BlendOp = BLEND_OPERATION_ADD;
2076-
RT0.SrcBlendAlpha = BLEND_FACTOR_ONE;
2077-
RT0.DestBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA;
2078-
RT0.BlendOpAlpha = BLEND_OPERATION_ADD;
2079-
// NB: Do NOT overwrite RenderTargetWriteMask
2068+
RT0.SrcBlend = BLEND_FACTOR_ONE;
2069+
RT0.DestBlend = BLEND_FACTOR_INV_SRC_ALPHA;
2070+
RT0.BlendOp = BLEND_OPERATION_ADD;
20802071
}
2072+
2073+
// Compute total transmittance, e.g. (1.0 - A0) * (1.0 - A1) ... * (1.0 - An),
2074+
// in alpha channel.
2075+
RT0.SrcBlendAlpha = BLEND_FACTOR_ZERO; // SrcA * 0
2076+
RT0.DestBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA; // DstA * (1.0 - SrcA)
2077+
RT0.BlendOpAlpha = BLEND_OPERATION_ADD;
2078+
2079+
// NB: Do NOT overwrite RenderTargetWriteMask
20812080
}
20822081
else
20832082
{

Shaders/PBR/private/RenderPBR.psh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ PSOutput main(in VSOutput VSOut,
618618
#endif
619619

620620
OutColor.rgb *= Transmittance;
621+
if (BasicAttribs.AlphaMode != PBR_ALPHA_MODE_BLEND)
622+
{
623+
// Write 0 alpha to indicate full opacity
624+
OutColor.a = 0.0;
625+
}
621626

622627
#if CONVERT_OUTPUT_TO_SRGB
623628
{

0 commit comments

Comments
 (0)