Skip to content

Commit

Permalink
PBR Renderer: added PSO flag to enable/disable tone mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 23, 2023
1 parent 3e9fa6b commit 572060c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
6 changes: 4 additions & 2 deletions PBR/interface/PBR_Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ class PBR_Renderer
PSO_FLAG_USE_TEXTURE_ATLAS = 1u << 14u,
PSO_FLAG_CONVERT_OUTPUT_TO_SRGB = 1u << 15u,
PSO_FLAG_ENABLE_CUSTOM_DATA_OUTPUT = 1u << 16u,
PSO_FLAG_ENABLE_TONE_MAPPING = 1u << 17u,

PSO_FLAG_LAST = PSO_FLAG_ENABLE_CUSTOM_DATA_OUTPUT,
PSO_FLAG_LAST = PSO_FLAG_ENABLE_TONE_MAPPING,

PSO_FLAG_VERTEX_ATTRIBS =
PSO_FLAG_USE_VERTEX_COLORS |
Expand All @@ -236,7 +237,8 @@ class PBR_Renderer
PSO_FLAG_USE_PHYS_DESC_MAP |
PSO_FLAG_USE_AO_MAP |
PSO_FLAG_USE_EMISSIVE_MAP |
PSO_FLAG_USE_IBL,
PSO_FLAG_USE_IBL |
PSO_FLAG_ENABLE_TONE_MAPPING,

PSO_FLAG_ALL = PSO_FLAG_LAST * 2u - 1u,
};
Expand Down
3 changes: 2 additions & 1 deletion PBR/src/GLTF_PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ GLTF_PBR_Renderer::GLTF_PBR_Renderer(IRenderDevice* pDevice,
m_SupportedPSOFlags |=
PSO_FLAG_ENABLE_DEBUG_VIEW |
PSO_FLAG_USE_TEXTURE_ATLAS |
PSO_FLAG_CONVERT_OUTPUT_TO_SRGB;
PSO_FLAG_CONVERT_OUTPUT_TO_SRGB |
PSO_FLAG_ENABLE_TONE_MAPPING;

{
GraphicsPipelineDesc GraphicsDesc;
Expand Down
3 changes: 2 additions & 1 deletion PBR/src/PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ ShaderMacroHelper PBR_Renderer::DefineMacros(PSO_FLAGS PSOFlags) const
Macros.Add("DEBUG_VIEW_SPECULAR_IBL", static_cast<int>(DebugViewType::SpecularIBL));
// clang-format on

static_assert(PSO_FLAG_LAST == 1u << 16u, "Did you add new PSO Flag? You may need to handle it here.");
static_assert(PSO_FLAG_LAST == 1u << 17u, "Did you add new PSO Flag? You may need to handle it here.");
#define ADD_PSO_FLAG_MACRO(Flag) Macros.Add(#Flag, (PSOFlags & PSO_FLAG_##Flag) != PSO_FLAG_NONE)
ADD_PSO_FLAG_MACRO(USE_VERTEX_COLORS);
ADD_PSO_FLAG_MACRO(USE_VERTEX_NORMALS);
Expand All @@ -634,6 +634,7 @@ ShaderMacroHelper PBR_Renderer::DefineMacros(PSO_FLAGS PSOFlags) const
ADD_PSO_FLAG_MACRO(USE_TEXTURE_ATLAS);
ADD_PSO_FLAG_MACRO(CONVERT_OUTPUT_TO_SRGB);
ADD_PSO_FLAG_MACRO(ENABLE_CUSTOM_DATA_OUTPUT);
ADD_PSO_FLAG_MACRO(ENABLE_TONE_MAPPING);
#undef ADD_PSO_FLAG_MACRO

Macros.Add("TEX_COLOR_CONVERSION_MODE_NONE", CreateInfo::TEX_COLOR_CONVERSION_MODE_NONE);
Expand Down
27 changes: 17 additions & 10 deletions Shaders/PBR/private/RenderPBR.psh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "BasicStructures.fxh"
#include "PBR_Shading.fxh"
#include "ToneMapping.fxh"

#if ENABLE_TONE_MAPPING
# include "ToneMapping.fxh"
#endif

#include "VSOutputStruct.generated"
// struct VSOutput
Expand Down Expand Up @@ -416,15 +419,19 @@ void main(in VSOutput VSOut,
}
# endif

// Perform tone mapping
ToneMappingAttribs TMAttribs;
TMAttribs.iToneMappingMode = TONE_MAPPING_MODE_UNCHARTED2;
TMAttribs.bAutoExposure = false;
TMAttribs.fMiddleGray = g_PBRAttribs.Renderer.MiddleGray;
TMAttribs.bLightAdaptation = false;
TMAttribs.fWhitePoint = g_PBRAttribs.Renderer.WhitePoint;
TMAttribs.fLuminanceSaturation = 1.0;
color = ToneMap(color, TMAttribs, g_PBRAttribs.Renderer.AverageLogLum);
#if ENABLE_TONE_MAPPING
{
// Perform tone mapping
ToneMappingAttribs TMAttribs;
TMAttribs.iToneMappingMode = TONE_MAPPING_MODE;
TMAttribs.bAutoExposure = false;
TMAttribs.fMiddleGray = g_PBRAttribs.Renderer.MiddleGray;
TMAttribs.bLightAdaptation = false;
TMAttribs.fWhitePoint = g_PBRAttribs.Renderer.WhitePoint;
TMAttribs.fLuminanceSaturation = 1.0;
color = ToneMap(color, TMAttribs, g_PBRAttribs.Renderer.AverageLogLum);
}
#endif

// Add highlight color
color = lerp(color, g_PBRAttribs.Renderer.HighlightColor.rgb, g_PBRAttribs.Renderer.HighlightColor.a);
Expand Down
27 changes: 17 additions & 10 deletions shaders_inc/RenderPBR.psh.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"\n"
"#include \"BasicStructures.fxh\"\n"
"#include \"PBR_Shading.fxh\"\n"
"#include \"ToneMapping.fxh\"\n"
"\n"
"#if ENABLE_TONE_MAPPING\n"
"# include \"ToneMapping.fxh\"\n"
"#endif\n"
"\n"
"#include \"VSOutputStruct.generated\"\n"
"// struct VSOutput\n"
Expand Down Expand Up @@ -416,15 +419,19 @@
" }\n"
"# endif\n"
"\n"
" // Perform tone mapping\n"
" ToneMappingAttribs TMAttribs;\n"
" TMAttribs.iToneMappingMode = TONE_MAPPING_MODE_UNCHARTED2;\n"
" TMAttribs.bAutoExposure = false;\n"
" TMAttribs.fMiddleGray = g_PBRAttribs.Renderer.MiddleGray;\n"
" TMAttribs.bLightAdaptation = false;\n"
" TMAttribs.fWhitePoint = g_PBRAttribs.Renderer.WhitePoint;\n"
" TMAttribs.fLuminanceSaturation = 1.0;\n"
" color = ToneMap(color, TMAttribs, g_PBRAttribs.Renderer.AverageLogLum);\n"
"#if ENABLE_TONE_MAPPING\n"
" {\n"
" // Perform tone mapping\n"
" ToneMappingAttribs TMAttribs;\n"
" TMAttribs.iToneMappingMode = TONE_MAPPING_MODE_UNCHARTED2;\n"
" TMAttribs.bAutoExposure = false;\n"
" TMAttribs.fMiddleGray = g_PBRAttribs.Renderer.MiddleGray;\n"
" TMAttribs.bLightAdaptation = false;\n"
" TMAttribs.fWhitePoint = g_PBRAttribs.Renderer.WhitePoint;\n"
" TMAttribs.fLuminanceSaturation = 1.0;\n"
" color = ToneMap(color, TMAttribs, g_PBRAttribs.Renderer.AverageLogLum);\n"
" }\n"
"#endif\n"
"\n"
" // Add highlight color\n"
" color = lerp(color, g_PBRAttribs.Renderer.HighlightColor.rgb, g_PBRAttribs.Renderer.HighlightColor.a);\n"
Expand Down

0 comments on commit 572060c

Please sign in to comment.