From 16f4188e2b1fab4a6312e313a84583055f992476 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Mon, 20 Apr 2020 20:48:13 +0200 Subject: [PATCH] Improved r_hdrDebug which shows F-stops like in Filament --- base/renderprogs/BRDF.inc.hlsl | 2 +- base/renderprogs/ambient_lighting_IBL.ps.hlsl | 8 ++--- base/renderprogs/interactionSM.ps.hlsl | 1 + base/renderprogs/tonemap.ps.hlsl | 33 +++++++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/base/renderprogs/BRDF.inc.hlsl b/base/renderprogs/BRDF.inc.hlsl index a87f9e71..0bfc1601 100644 --- a/base/renderprogs/BRDF.inc.hlsl +++ b/base/renderprogs/BRDF.inc.hlsl @@ -2,7 +2,7 @@ =========================================================================== Doom 3 BFG Edition GPL Source Code -Copyright (C) 2014 Robert Beckebans +Copyright (C) 2014-2020 Robert Beckebans This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). diff --git a/base/renderprogs/ambient_lighting_IBL.ps.hlsl b/base/renderprogs/ambient_lighting_IBL.ps.hlsl index 6195e33d..5cf1c968 100644 --- a/base/renderprogs/ambient_lighting_IBL.ps.hlsl +++ b/base/renderprogs/ambient_lighting_IBL.ps.hlsl @@ -33,11 +33,11 @@ If you have questions concerning this license or the applicable additional terms uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface normal map uniform sampler2D samp1 : register(s1); // texture 3 is the per-surface specular or roughness/metallic/AO mixer map uniform sampler2D samp2 : register(s2); // texture 2 is the per-surface baseColor map -uniform sampler2D samp3 : register(s3); // texture 4 is the light falloff texture -uniform sampler2D samp4 : register(s4); // texture 5 is the light projection texture +uniform sampler2D samp3 : register(s3); // texture 4 is the BRDF LUT +uniform sampler2D samp4 : register(s4); // texture 5 is unused -uniform samplerCUBE samp7 : register(s7); // texture 0 is the cube map -uniform samplerCUBE samp8 : register(s8); // texture 0 is the cube map +uniform samplerCUBE samp7 : register(s7); // texture 6 is the irradiance cube map +uniform samplerCUBE samp8 : register(s8); // texture 7 is the radiance cube map struct PS_IN { half4 position : VPOS; diff --git a/base/renderprogs/interactionSM.ps.hlsl b/base/renderprogs/interactionSM.ps.hlsl index 61b3d136..3c6fdff8 100644 --- a/base/renderprogs/interactionSM.ps.hlsl +++ b/base/renderprogs/interactionSM.ps.hlsl @@ -222,6 +222,7 @@ void main( PS_IN fragment, out PS_OUT result ) } shadow *= stepSize; + #elif 1 const float2 poissonDisk[12] = float2[]( diff --git a/base/renderprogs/tonemap.ps.hlsl b/base/renderprogs/tonemap.ps.hlsl index 9b53ef3e..d23f705f 100644 --- a/base/renderprogs/tonemap.ps.hlsl +++ b/base/renderprogs/tonemap.ps.hlsl @@ -208,8 +208,37 @@ void main( PS_IN fragment, out PS_OUT result ) #endif #if defined(HDR_DEBUG) - //color = tex2D( samp1, float2( L, 0.0 ) ); - color = tex2D( samp1, float2( dot( LUMINANCE_SRGB, color ), 0.0 ) ); + // https://google.github.io/filament/Filament.md.html#figure_luminanceviz + + const float3 debugColors[16] = float3[]( + float3(0.0, 0.0, 0.0), // black + float3(0.0, 0.0, 0.1647), // darkest blue + float3(0.0, 0.0, 0.3647), // darker blue + float3(0.0, 0.0, 0.6647), // dark blue + float3(0.0, 0.0, 0.9647), // blue + float3(0.0, 0.9255, 0.9255), // cyan + float3(0.0, 0.5647, 0.0), // dark green + float3(0.0, 0.7843, 0.0), // green + float3(1.0, 1.0, 0.0), // yellow + float3(0.90588, 0.75294, 0.0), // yellow-orange + float3(1.0, 0.5647, 0.0), // orange + float3(1.0, 0.0, 0.0), // bright red + float3(0.8392, 0.0, 0.0), // red + float3(1.0, 0.0, 1.0), // magenta + float3(0.6, 0.3333, 0.7882), // purple + float3(1.0, 1.0, 1.0) // white + ); + + // The 5th color in the array (cyan) represents middle gray (18%) + // Every stop above or below middle gray causes a color shift + float v = log2( Y / 0.18 ); + v = clamp( v + 5.0, 0.0, 15.0 ); + int index = int( floor( v ) ); + + color.rgb = lerp( debugColors[index], debugColors[ min(15, index + 1) ], fract( v ) ); + + //color = tex2D( samp1, float2( L, 0.0 ) ); + //color = tex2D( samp1, float2( dot( LUMINANCE_SRGB, color ), 0.0 ) ); #endif result.color = color;