From c40765ef249aaebe26f0ef59ce5c5f2b98ba526e Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Fri, 1 May 2020 13:01:39 +0200 Subject: [PATCH] Fixed way too bright ambient lights in HDR mode --- base/renderprogs/interaction.ps.hlsl | 2 +- base/renderprogs/interactionAmbient.ps.hlsl | 6 ++++-- base/renderprogs/interactionAmbient_skinned.ps.hlsl | 13 +++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/base/renderprogs/interaction.ps.hlsl b/base/renderprogs/interaction.ps.hlsl index 2f43d497..e2e15806 100644 --- a/base/renderprogs/interaction.ps.hlsl +++ b/base/renderprogs/interaction.ps.hlsl @@ -179,7 +179,7 @@ void main( PS_IN fragment, out PS_OUT result ) const half specularPower = 10.0f; // RB: added abs - half3 specularContribution = _half3( pow( hdotN, specularPower ) ); + half3 specularContribution = _half3( pow( abs( hDotN ), specularPower ) ); half3 diffuseColor = diffuseMap * sRGBToLinearRGB( rpDiffuseModifier.xyz ); half3 specularColor = specMap.xyz * specularContribution * sRGBToLinearRGB( rpSpecularModifier.xyz ); diff --git a/base/renderprogs/interactionAmbient.ps.hlsl b/base/renderprogs/interactionAmbient.ps.hlsl index 3734b42e..608b7904 100644 --- a/base/renderprogs/interactionAmbient.ps.hlsl +++ b/base/renderprogs/interactionAmbient.ps.hlsl @@ -3,6 +3,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. +Copyright (C) 2013-2020 Robert Beckebans This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -57,7 +58,8 @@ void main( PS_IN fragment, out PS_OUT result ) half4 lightFalloff = idtex2Dproj( samp3, fragment.texcoord2 ); half4 lightProj = idtex2Dproj( samp4, fragment.texcoord3 ); half4 YCoCG = tex2D( samp2, fragment.texcoord4.xy ); - half4 specMap = sRGBAToLinearRGBA( tex2D( samp1, fragment.texcoord5.xy ) ); + half4 specMapSRGB = tex2D( samp1, fragment.texcoord5.xy ); + half4 specMap = sRGBAToLinearRGBA( specMapSRGB ); const half3 ambientLightVector = half3( 0.5f, 9.5f - 0.385f, 0.8925f ); half3 lightVector = normalize( ambientLightVector ); @@ -94,7 +96,7 @@ void main( PS_IN fragment, out PS_OUT result ) half3 diffuseColor = diffuseMap * sRGBToLinearRGB( rpDiffuseModifier.xyz ); half3 specularColor = specMap.xyz * specularContribution * sRGBToLinearRGB( rpSpecularModifier.xyz ); - half3 lightColor = 1.0 * lightProj.xyz * lightFalloff.xyz; + half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz ); result.color.xyz = ( diffuseColor + specularColor ) * lightColor * fragment.color.xyz; result.color.w = 1.0; diff --git a/base/renderprogs/interactionAmbient_skinned.ps.hlsl b/base/renderprogs/interactionAmbient_skinned.ps.hlsl index 0872015e..608b7904 100644 --- a/base/renderprogs/interactionAmbient_skinned.ps.hlsl +++ b/base/renderprogs/interactionAmbient_skinned.ps.hlsl @@ -3,7 +3,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. -Copyright (C) 2013 Robert Beckebans +Copyright (C) 2013-2020 Robert Beckebans This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -58,11 +58,12 @@ void main( PS_IN fragment, out PS_OUT result ) half4 lightFalloff = idtex2Dproj( samp3, fragment.texcoord2 ); half4 lightProj = idtex2Dproj( samp4, fragment.texcoord3 ); half4 YCoCG = tex2D( samp2, fragment.texcoord4.xy ); - half4 specMap = tex2D( samp1, fragment.texcoord5.xy ); + half4 specMapSRGB = tex2D( samp1, fragment.texcoord5.xy ); + half4 specMap = sRGBAToLinearRGBA( specMapSRGB ); const half3 ambientLightVector = half3( 0.5f, 9.5f - 0.385f, 0.8925f ); half3 lightVector = normalize( ambientLightVector ); - half3 diffuseMap = ConvertYCoCgToRGB( YCoCG ); + half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) ); half3 localNormal; // RB begin @@ -93,9 +94,9 @@ void main( PS_IN fragment, out PS_OUT result ) // RB: added abs half3 specularContribution = _half3( pow( abs( hDotN ), specularPower ) ); - half3 diffuseColor = diffuseMap * rpDiffuseModifier.xyz; - half3 specularColor = specMap.xyz * specularContribution * rpSpecularModifier.xyz; - half3 lightColor = 1.0 * lightProj.xyz * lightFalloff.xyz; + half3 diffuseColor = diffuseMap * sRGBToLinearRGB( rpDiffuseModifier.xyz ); + half3 specularColor = specMap.xyz * specularContribution * sRGBToLinearRGB( rpSpecularModifier.xyz ); + half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz ); result.color.xyz = ( diffuseColor + specularColor ) * lightColor * fragment.color.xyz; result.color.w = 1.0;