Skip to content

Commit

Permalink
PBR shader: added highlight color
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 2, 2023
1 parent 8ac6c1e commit d5742f4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions PBR/interface/GLTF_PBR_Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class GLTF_PBR_Renderer : public PBR_Renderer

/// White point value used by tone mapping
float WhitePoint = 3.f;

/// Highlight color that is applied to the mesh after tone mapping
float4 HighlightColor = float4{0, 0, 0, 0};
};

/// GLTF Model shader resource binding information
Expand Down
1 change: 1 addition & 0 deletions PBR/src/GLTF_PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ void GLTF_PBR_Renderer::Render(IDeviceContext* pCtx,
RendererParams.MiddleGray = m_RenderParams.MiddleGray;
RendererParams.WhitePoint = m_RenderParams.WhitePoint;
RendererParams.IBLScale = m_RenderParams.IBLScale;
RendererParams.HighlightColor = m_RenderParams.HighlightColor;
RendererParams.PrefilteredCubeMipLevels = m_Settings.UseIBL ? static_cast<float>(m_pPrefilteredEnvMapSRV->GetTexture()->GetDesc().MipLevels) : 0.f;
}

Expand Down
5 changes: 5 additions & 0 deletions Shaders/PBR/private/RenderPBR.psh
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void main(in PbrVsOutput VSOut,
color += Emissive.rgb * g_PBRAttribs.Material.EmissiveFactor.rgb * g_PBRAttribs.Renderer.EmissionScale;
#endif

// Perform tone mapping
ToneMappingAttribs TMAttribs;
TMAttribs.iToneMappingMode = TONE_MAPPING_MODE_UNCHARTED2;
TMAttribs.bAutoExposure = false;
Expand All @@ -263,6 +264,10 @@ void main(in PbrVsOutput VSOut,
TMAttribs.fWhitePoint = g_PBRAttribs.Renderer.WhitePoint;
TMAttribs.fLuminanceSaturation = 1.0;
color = ToneMap(color, TMAttribs, g_PBRAttribs.Renderer.AverageLogLum);

// Add highlight color
color = lerp(color, g_PBRAttribs.Renderer.HighlightColor.rgb, g_PBRAttribs.Renderer.HighlightColor.a);

OutColor = float4(color, BaseColor.a);

#if ALLOW_DEBUG_VIEW
Expand Down
1 change: 1 addition & 0 deletions Shaders/PBR/public/PBR_Structures.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct PBRRendererShaderParameters
float EmissionScale;

float4 WireframeColor;
float4 HighlightColor;

uint MeshId;
uint Padding0;
Expand Down
1 change: 1 addition & 0 deletions shaders_inc/PBR_Structures.fxh.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
" float EmissionScale;\n"
"\n"
" float4 WireframeColor;\n"
" float4 HighlightColor;\n"
"\n"
" uint MeshId;\n"
" uint Padding0;\n"
Expand Down
5 changes: 5 additions & 0 deletions shaders_inc/RenderPBR.psh.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
" color += Emissive.rgb * g_PBRAttribs.Material.EmissiveFactor.rgb * g_PBRAttribs.Renderer.EmissionScale;\n"
"#endif\n"
"\n"
" // Perform tone mapping\n"
" ToneMappingAttribs TMAttribs;\n"
" TMAttribs.iToneMappingMode = TONE_MAPPING_MODE_UNCHARTED2;\n"
" TMAttribs.bAutoExposure = false;\n"
Expand All @@ -263,6 +264,10 @@
" TMAttribs.fWhitePoint = g_PBRAttribs.Renderer.WhitePoint;\n"
" TMAttribs.fLuminanceSaturation = 1.0;\n"
" color = ToneMap(color, TMAttribs, g_PBRAttribs.Renderer.AverageLogLum);\n"
"\n"
" // Add highlight color\n"
" color = lerp(color, g_PBRAttribs.Renderer.HighlightColor.rgb, g_PBRAttribs.Renderer.HighlightColor.a);\n"
"\n"
" OutColor = float4(color, BaseColor.a);\n"
"\n"
"#if ALLOW_DEBUG_VIEW\n"
Expand Down

0 comments on commit d5742f4

Please sign in to comment.