Skip to content

Commit

Permalink
Tutorial 29: do not use alpha for opaque objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jan 4, 2025
1 parent e237c5a commit ca06208
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions Tutorials/Tutorial29_OIT/assets/alpha_blend.psh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ void main(in PSInput PSIn,
{
float4 Color;
Color.rgb = ComputeLighting(PSIn.Color.rgb, PSIn.Normal, g_Constants.LightDir.xyz);
Color.a = lerp(g_Constants.MinOpacity, g_Constants.MaxOpacity, PSIn.Color.a);
Color.rgb *= Color.a;
if (PSIn.Color.a < 0.0)
{
// Opaque
Color.a = 1.0;
}
else
{
// Transparent
Color.a = lerp(g_Constants.MinOpacity, g_Constants.MaxOpacity, PSIn.Color.a);
Color.rgb *= Color.a;
}

#if CONVERT_PS_OUTPUT_TO_GAMMA
// Use fast approximation for gamma correction.
Expand Down
2 changes: 1 addition & 1 deletion Tutorials/Tutorial29_OIT/src/Tutorial29_OIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ void Tutorial29_OIT::CreateInstanceBuffers()
{
Instance.TranslationAndScale = float4{offset_distr(gen), offset_distr(gen), offset_distr(gen), BaseScale * scale_distr(gen)};
float4 TransparentColor{color_distr(gen), color_distr(gen), color_distr(gen), alpha_distr(gen)};
float4 OpaqueColor{0.5, 0.5, 0.5, 1.0};
float4 OpaqueColor{0.5, 0.5, 0.5, -1.0};
Instance.Color = IsTransparent ? TransparentColor : OpaqueColor;
}
// Update instance data buffer
Expand Down
2 changes: 1 addition & 1 deletion Tutorials/Tutorial29_OIT/src/Tutorial29_OIT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Tutorial29_OIT final : public SampleBase
float4x4 m_ProjMatrix;
float4x4 m_ViewProjMatrix;
int m_GridSize = 10;
float m_PercentOpaque = 25;
float m_PercentOpaque = 10;
float m_MinOpacity = 0.2f;
float m_MaxOpacity = 1.0f;
Uint32 m_ThreadGroupSizeXY = 16;
Expand Down

0 comments on commit ca06208

Please sign in to comment.