Skip to content

Commit

Permalink
PBR Renderer: added texture coords and direct lighting debug views
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 20, 2023
1 parent d6075d6 commit a1e7ed5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 70 deletions.
34 changes: 18 additions & 16 deletions PBR/interface/PBR_Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,24 @@ class PBR_Renderer
/// Debug view type
enum class DebugViewType : int
{
None = 0,
BaseColor = 1,
Transparency = 2,
NormalMap = 3,
Occlusion = 4,
Emissive = 5,
Metallic = 6,
Roughness = 7,
DiffuseColor = 8,
SpecularColor = 9,
Reflectance90 = 10,
MeshNormal = 11,
PerturbedNormal = 12,
NdotV = 13,
DiffuseIBL = 14,
SpecularIBL = 15,
None,
Texcoord0,
BaseColor,
Transparency,
NormalMap,
Occlusion,
Emissive,
Metallic,
Roughness,
DiffuseColor,
SpecularColor,
Reflectance90,
MeshNormal,
PerturbedNormal,
NdotV,
DirectLighting,
DiffuseIBL,
SpecularIBL,
NumDebugViews
};

Expand Down
62 changes: 42 additions & 20 deletions PBR/src/PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,26 +530,48 @@ void PBR_Renderer::CreatePSO(IRenderDevice* pDevice, IRenderStateCache* pStateCa
ShaderCI.pShaderSourceStreamFactory = &DiligentFXShaderSourceStreamFactory::GetInstance();

ShaderMacroHelper Macros;
Macros.AddShaderMacro("MAX_JOINT_COUNT", static_cast<int>(m_Settings.MaxJointCount));
Macros.AddShaderMacro("ALLOW_DEBUG_VIEW", m_Settings.AllowDebugView);
Macros.AddShaderMacro("CONVERT_OUTPUT_TO_SRGB", m_Settings.ConvertOutputToSRGB);
Macros.AddShaderMacro("TONE_MAPPING_MODE", "TONE_MAPPING_MODE_UNCHARTED2");
Macros.AddShaderMacro("PBR_USE_IBL", m_Settings.UseIBL);
Macros.AddShaderMacro("PBR_USE_AO", m_Settings.UseAO);
Macros.AddShaderMacro("PBR_USE_EMISSIVE", m_Settings.UseEmissive);
Macros.AddShaderMacro("USE_TEXTURE_ATLAS", m_Settings.UseTextureAtlas);
Macros.AddShaderMacro("PBR_WORKFLOW_METALLIC_ROUGHNESS", PBR_WORKFLOW_METALL_ROUGH);
Macros.AddShaderMacro("PBR_WORKFLOW_SPECULAR_GLOSINESS", PBR_WORKFLOW_SPEC_GLOSS);
Macros.AddShaderMacro("PBR_ALPHA_MODE_OPAQUE", ALPHA_MODE_OPAQUE);
Macros.AddShaderMacro("PBR_ALPHA_MODE_MASK", ALPHA_MODE_MASK);
Macros.AddShaderMacro("PBR_ALPHA_MODE_BLEND", ALPHA_MODE_BLEND);
Macros.AddShaderMacro("USE_IBL_ENV_MAP_LOD", true);
Macros.AddShaderMacro("USE_HDR_IBL_CUBEMAPS", true);
Macros.AddShaderMacro("USE_SEPARATE_METALLIC_ROUGHNESS_TEXTURES", m_Settings.UseSeparateMetallicRoughnessTextures);

Macros.AddShaderMacro("TEX_COLOR_CONVERSION_MODE_NONE", CreateInfo::TEX_COLOR_CONVERSION_MODE_NONE);
Macros.AddShaderMacro("TEX_COLOR_CONVERSION_MODE_SRGB_TO_LINEAR", CreateInfo::TEX_COLOR_CONVERSION_MODE_SRGB_TO_LINEAR);
Macros.AddShaderMacro("TEX_COLOR_CONVERSION_MODE", m_Settings.TexColorConversionMode);
Macros.Add("MAX_JOINT_COUNT", static_cast<int>(m_Settings.MaxJointCount));
Macros.Add("ALLOW_DEBUG_VIEW", m_Settings.AllowDebugView);
Macros.Add("CONVERT_OUTPUT_TO_SRGB", m_Settings.ConvertOutputToSRGB);
Macros.Add("TONE_MAPPING_MODE", "TONE_MAPPING_MODE_UNCHARTED2");
Macros.Add("PBR_USE_IBL", m_Settings.UseIBL);
Macros.Add("PBR_USE_AO", m_Settings.UseAO);
Macros.Add("PBR_USE_EMISSIVE", m_Settings.UseEmissive);
Macros.Add("USE_TEXTURE_ATLAS", m_Settings.UseTextureAtlas);
Macros.Add("PBR_WORKFLOW_METALLIC_ROUGHNESS", PBR_WORKFLOW_METALL_ROUGH);
Macros.Add("PBR_WORKFLOW_SPECULAR_GLOSINESS", PBR_WORKFLOW_SPEC_GLOSS);
Macros.Add("PBR_ALPHA_MODE_OPAQUE", ALPHA_MODE_OPAQUE);
Macros.Add("PBR_ALPHA_MODE_MASK", ALPHA_MODE_MASK);
Macros.Add("PBR_ALPHA_MODE_BLEND", ALPHA_MODE_BLEND);
Macros.Add("USE_IBL_ENV_MAP_LOD", true);
Macros.Add("USE_HDR_IBL_CUBEMAPS", true);
Macros.Add("USE_SEPARATE_METALLIC_ROUGHNESS_TEXTURES", m_Settings.UseSeparateMetallicRoughnessTextures);

// clang-format off
Macros.Add("DEBUG_VIEW_NONE", static_cast<int>(DebugViewType::None));
Macros.Add("DEBUG_VIEW_TEXCOORD0", static_cast<int>(DebugViewType::Texcoord0));
Macros.Add("DEBUG_VIEW_BASE_COLOR", static_cast<int>(DebugViewType::BaseColor));
Macros.Add("DEBUG_VIEW_TRANSPARENCY", static_cast<int>(DebugViewType::Transparency));
Macros.Add("DEBUG_VIEW_NORMAL_MAP", static_cast<int>(DebugViewType::NormalMap));
Macros.Add("DEBUG_VIEW_OCCLUSION", static_cast<int>(DebugViewType::Occlusion));
Macros.Add("DEBUG_VIEW_EMISSIVE", static_cast<int>(DebugViewType::Emissive));
Macros.Add("DEBUG_VIEW_METALLIC", static_cast<int>(DebugViewType::Metallic));
Macros.Add("DEBUG_VIEW_ROUGHNESS", static_cast<int>(DebugViewType::Roughness));
Macros.Add("DEBUG_VIEW_DIFFUSE_COLOR", static_cast<int>(DebugViewType::DiffuseColor));
Macros.Add("DEBUG_VIEW_SPECULAR_COLOR", static_cast<int>(DebugViewType::SpecularColor));
Macros.Add("DEBUG_VIEW_REFLECTANCE90", static_cast<int>(DebugViewType::Reflectance90));
Macros.Add("DEBUG_VIEW_MESH_NORMAL", static_cast<int>(DebugViewType::MeshNormal));
Macros.Add("DEBUG_VIEW_PERTURBED_NORMAL", static_cast<int>(DebugViewType::PerturbedNormal));
Macros.Add("DEBUG_VIEW_NDOTV", static_cast<int>(DebugViewType::NdotV));
Macros.Add("DEBUG_VIEW_DIRECT_LIGHTING", static_cast<int>(DebugViewType::DirectLighting));
Macros.Add("DEBUG_VIEW_DIFFUSE_IBL", static_cast<int>(DebugViewType::DiffuseIBL));
Macros.Add("DEBUG_VIEW_SPECULAR_IBL", static_cast<int>(DebugViewType::SpecularIBL));
// clang-format on


Macros.Add("TEX_COLOR_CONVERSION_MODE_NONE", CreateInfo::TEX_COLOR_CONVERSION_MODE_NONE);
Macros.Add("TEX_COLOR_CONVERSION_MODE_SRGB_TO_LINEAR", CreateInfo::TEX_COLOR_CONVERSION_MODE_SRGB_TO_LINEAR);
Macros.Add("TEX_COLOR_CONVERSION_MODE", m_Settings.TexColorConversionMode);

ShaderCI.Macros = Macros;
RefCntAutoPtr<IShader> pVS;
Expand Down
37 changes: 20 additions & 17 deletions Shaders/PBR/private/RenderPBR.psh
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ void main(in PbrVsOutput VSOut,
VSOut.Normal, TSNormal, g_PBRAttribs.Material.NormalTextureUVSelector >= 0.0, IsFrontFace);
float3 view = normalize(g_CameraAttribs.f4Position.xyz - VSOut.WorldPos.xyz); // Direction from surface point to camera

float3 color = float3(0.0, 0.0, 0.0);
color += ApplyDirectionalLight(g_LightAttribs.f4Direction.xyz, g_LightAttribs.f4Intensity.rgb, SrfInfo, perturbedNormal, view);

float3 DirectLighting = ApplyDirectionalLight(g_LightAttribs.f4Direction.xyz, g_LightAttribs.f4Intensity.rgb, SrfInfo, perturbedNormal, view);
float3 color = DirectLighting;

//#ifdef USE_PUNCTUAL
// for (int i = 0; i < LIGHT_COUNT; ++i)
Expand Down Expand Up @@ -278,22 +279,24 @@ void main(in PbrVsOutput VSOut,
{
switch (g_PBRAttribs.Renderer.DebugViewType)
{
case 1: OutColor.rgba = BaseColor; break;
case 2: OutColor.rgba = float4(BaseColor.a, BaseColor.a, BaseColor.a, 1.0); break;
case 3: OutColor.rgb = TSNormal.xyz; break;
case 4: OutColor.rgb = Occlusion * float3(1.0, 1.0, 1.0); break;
case 5: OutColor.rgb = Emissive.rgb; break;
case 6: OutColor.rgb = metallic * float3(1.0, 1.0, 1.0); break;
case 7: OutColor.rgb = SrfInfo.PerceptualRoughness * float3(1.0, 1.0, 1.0); break;
case 8: OutColor.rgb = SrfInfo.DiffuseColor; break;
case 9: OutColor.rgb = SrfInfo.Reflectance0; break;
case 10: OutColor.rgb = SrfInfo.Reflectance90; break;
case 11: OutColor.rgb = abs(VSOut.Normal / max(length(VSOut.Normal), 1e-3)); break;
case 12: OutColor.rgb = abs(perturbedNormal); break;
case 13: OutColor.rgb = dot(perturbedNormal, view) * float3(1.0, 1.0, 1.0); break;
case DEBUG_VIEW_BASE_COLOR: OutColor.rgba = BaseColor; break;
case DEBUG_VIEW_TEXCOORD0: OutColor.rgb = float3(VSOut.UV0, 0.0); break;
case DEBUG_VIEW_TRANSPARENCY: OutColor.rgba = float4(BaseColor.a, BaseColor.a, BaseColor.a, 1.0); break;
case DEBUG_VIEW_NORMAL_MAP: OutColor.rgb = TSNormal.xyz; break;
case DEBUG_VIEW_OCCLUSION: OutColor.rgb = Occlusion * float3(1.0, 1.0, 1.0); break;
case DEBUG_VIEW_EMISSIVE: OutColor.rgb = Emissive.rgb; break;
case DEBUG_VIEW_METALLIC: OutColor.rgb = metallic * float3(1.0, 1.0, 1.0); break;
case DEBUG_VIEW_ROUGHNESS: OutColor.rgb = SrfInfo.PerceptualRoughness * float3(1.0, 1.0, 1.0); break;
case DEBUG_VIEW_DIFFUSE_COLOR: OutColor.rgb = SrfInfo.DiffuseColor; break;
case DEBUG_VIEW_SPECULAR_COLOR: OutColor.rgb = SrfInfo.Reflectance0; break;
case DEBUG_VIEW_REFLECTANCE90: OutColor.rgb = SrfInfo.Reflectance90; break;
case DEBUG_VIEW_MESH_NORMAL: OutColor.rgb = abs(VSOut.Normal / max(length(VSOut.Normal), 1e-3)); break;
case DEBUG_VIEW_PERTURBED_NORMAL: OutColor.rgb = abs(perturbedNormal); break;
case DEBUG_VIEW_NDOTV: OutColor.rgb = dot(perturbedNormal, view) * float3(1.0, 1.0, 1.0); break;
case DEBUG_VIEW_DIRECT_LIGHTING: OutColor.rgb = DirectLighting; break;
#if PBR_USE_IBL
case 14: OutColor.rgb = IBLContrib.f3Diffuse; break;
case 15: OutColor.rgb = IBLContrib.f3Specular; break;
case DEBUG_VIEW_DIFFUSE_IBL: OutColor.rgb = IBLContrib.f3Diffuse; break;
case DEBUG_VIEW_SPECULAR_IBL: OutColor.rgb = IBLContrib.f3Specular; break;
#endif
}
}
Expand Down
37 changes: 20 additions & 17 deletions shaders_inc/RenderPBR.psh.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@
" VSOut.Normal, TSNormal, g_PBRAttribs.Material.NormalTextureUVSelector >= 0.0, IsFrontFace);\n"
" float3 view = normalize(g_CameraAttribs.f4Position.xyz - VSOut.WorldPos.xyz); // Direction from surface point to camera\n"
"\n"
" float3 color = float3(0.0, 0.0, 0.0);\n"
" color += ApplyDirectionalLight(g_LightAttribs.f4Direction.xyz, g_LightAttribs.f4Intensity.rgb, SrfInfo, perturbedNormal, view);\n"
"\n"
" float3 DirectLighting = ApplyDirectionalLight(g_LightAttribs.f4Direction.xyz, g_LightAttribs.f4Intensity.rgb, SrfInfo, perturbedNormal, view);\n"
" float3 color = DirectLighting;\n"
"\n"
"//#ifdef USE_PUNCTUAL\n"
"// for (int i = 0; i < LIGHT_COUNT; ++i)\n"
Expand Down Expand Up @@ -278,22 +279,24 @@
" {\n"
" switch (g_PBRAttribs.Renderer.DebugViewType)\n"
" {\n"
" case 1: OutColor.rgba = BaseColor; break;\n"
" case 2: OutColor.rgba = float4(BaseColor.a, BaseColor.a, BaseColor.a, 1.0); break;\n"
" case 3: OutColor.rgb = TSNormal.xyz; break;\n"
" case 4: OutColor.rgb = Occlusion * float3(1.0, 1.0, 1.0); break;\n"
" case 5: OutColor.rgb = Emissive.rgb; break;\n"
" case 6: OutColor.rgb = metallic * float3(1.0, 1.0, 1.0); break;\n"
" case 7: OutColor.rgb = SrfInfo.PerceptualRoughness * float3(1.0, 1.0, 1.0); break;\n"
" case 8: OutColor.rgb = SrfInfo.DiffuseColor; break;\n"
" case 9: OutColor.rgb = SrfInfo.Reflectance0; break;\n"
" case 10: OutColor.rgb = SrfInfo.Reflectance90; break;\n"
" case 11: OutColor.rgb = abs(VSOut.Normal / max(length(VSOut.Normal), 1e-3)); break;\n"
" case 12: OutColor.rgb = abs(perturbedNormal); break;\n"
" case 13: OutColor.rgb = dot(perturbedNormal, view) * float3(1.0, 1.0, 1.0); break;\n"
" case DEBUG_VIEW_BASE_COLOR: OutColor.rgba = BaseColor; break;\n"
" case DEBUG_VIEW_TEXCOORD0: OutColor.rgb = float3(VSOut.UV0, 0.0); break;\n"
" case DEBUG_VIEW_TRANSPARENCY: OutColor.rgba = float4(BaseColor.a, BaseColor.a, BaseColor.a, 1.0); break;\n"
" case DEBUG_VIEW_NORMAL_MAP: OutColor.rgb = TSNormal.xyz; break;\n"
" case DEBUG_VIEW_OCCLUSION: OutColor.rgb = Occlusion * float3(1.0, 1.0, 1.0); break;\n"
" case DEBUG_VIEW_EMISSIVE: OutColor.rgb = Emissive.rgb; break;\n"
" case DEBUG_VIEW_METALLIC: OutColor.rgb = metallic * float3(1.0, 1.0, 1.0); break;\n"
" case DEBUG_VIEW_ROUGHNESS: OutColor.rgb = SrfInfo.PerceptualRoughness * float3(1.0, 1.0, 1.0); break;\n"
" case DEBUG_VIEW_DIFFUSE_COLOR: OutColor.rgb = SrfInfo.DiffuseColor; break;\n"
" case DEBUG_VIEW_SPECULAR_COLOR: OutColor.rgb = SrfInfo.Reflectance0; break;\n"
" case DEBUG_VIEW_REFLECTANCE90: OutColor.rgb = SrfInfo.Reflectance90; break;\n"
" case DEBUG_VIEW_MESH_NORMAL: OutColor.rgb = abs(VSOut.Normal / max(length(VSOut.Normal), 1e-3)); break;\n"
" case DEBUG_VIEW_PERTURBED_NORMAL: OutColor.rgb = abs(perturbedNormal); break;\n"
" case DEBUG_VIEW_NDOTV: OutColor.rgb = dot(perturbedNormal, view) * float3(1.0, 1.0, 1.0); break;\n"
" case DEBUG_VIEW_DIRECT_LIGHTING: OutColor.rgb = DirectLighting; break;\n"
"#if PBR_USE_IBL\n"
" case 14: OutColor.rgb = IBLContrib.f3Diffuse; break;\n"
" case 15: OutColor.rgb = IBLContrib.f3Specular; break;\n"
" case DEBUG_VIEW_DIFFUSE_IBL: OutColor.rgb = IBLContrib.f3Diffuse; break;\n"
" case DEBUG_VIEW_SPECULAR_IBL: OutColor.rgb = IBLContrib.f3Specular; break;\n"
"#endif\n"
" }\n"
" }\n"
Expand Down

0 comments on commit a1e7ed5

Please sign in to comment.