From f6b9f0e0fb060d5fe5d07613ee41da6ce104ce52 Mon Sep 17 00:00:00 2001 From: Chris Santora Date: Thu, 20 May 2021 17:02:26 -0700 Subject: [PATCH] Reversed the debug view for displacement to show height instead of depth. Also add a LerpInverse utility, though I ended up not using it with these changes, it should be handle elsewhere. --- .../Types/StandardMultilayerPBR_ForwardPass.azsl | 7 +++++-- Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/Math.azsli | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl index 88a3ca29c0..41658b114a 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl @@ -342,8 +342,11 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float if(o_debugDrawMode == DebugDrawMode::Displacement) { - float depth = GetNormalizedDepth(-MaterialSrg::m_displacementMax, -MaterialSrg::m_displacementMin, IN.m_uv[MaterialSrg::m_parallaxUvIndex], float2(0,0), float2(0,0)); - return DebugOutput(float3(depth,depth,depth)); + float startDepth = -MaterialSrg::m_displacementMax; + float stopDepth = -MaterialSrg::m_displacementMin; + float depth = GetNormalizedDepth(startDepth, stopDepth, IN.m_uv[MaterialSrg::m_parallaxUvIndex], float2(0,0), float2(0,0)); + float height = 1 - saturate(depth); + return DebugOutput(float3(height,height,height)); } if(o_debugDrawMode == DebugDrawMode::FinalBlendWeights) diff --git a/Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/Math.azsli b/Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/Math.azsli index 2381febed0..0bd115d3cc 100644 --- a/Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/Math.azsli +++ b/Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/Math.azsli @@ -225,3 +225,16 @@ float NextRandomFloatUniform(inout uint seed) seed = Xorshift(seed); return (float)seed / 4294967295.0f; } + +//! Returns the inverse of lerp, 't', such that value = lerp(a, b, t), or returns 0 when a == b. +float LerpInverse(float a, float b, float value) +{ + if(abs(a - b) <= EPSILON) + { + return 0.0; + } + else + { + return (value - a) / (b - a); + } +} \ No newline at end of file