Fixed linear RGB -> sRGB gamma ramp after tone mapping

This commit is contained in:
Robert Beckebans 2022-03-15 16:58:07 +01:00
parent 91ae3aa3ed
commit 07bef6e114
10 changed files with 19 additions and 194 deletions

View file

@ -257,7 +257,7 @@ void idImage::AllocImage()
break;
case FMT_ALPHA:
format = nvrhi::Format::R8_UINT;
format = nvrhi::Format::R8_UNORM;
break;
case FMT_L8A8:
@ -265,11 +265,11 @@ void idImage::AllocImage()
break;
case FMT_LUM8:
format = nvrhi::Format::R8_UINT;
format = nvrhi::Format::R8_UNORM;
break;
case FMT_INT8:
format = nvrhi::Format::R8_UINT;
format = nvrhi::Format::R8_UNORM;
break;
case FMT_R8:

View file

@ -408,9 +408,9 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device )
{ BUILTIN_SHADOW_DEBUG, "builtin/debug/shadowDebug", "", { {"USE_GPU_SKINNING", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_SHADOW_DEBUG_SKINNED, "builtin/debug/shadowDebug", "_skinned", { {"USE_GPU_SKINNING", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_BLENDLIGHT, "builtin/fog/blendlight", "", { { "USE_LINEAR_RGB", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_FOG, "builtin/fog/fog", "", { {"USE_GPU_SKINNING", "0" }, { "USE_LINEAR_RGB", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_FOG },
{ BUILTIN_FOG_SKINNED, "builtin/fog/fog", "_skinned", { {"USE_GPU_SKINNING", "1" }, { "USE_LINEAR_RGB", "0" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_FOG },
{ BUILTIN_BLENDLIGHT, "builtin/fog/blendlight", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_FOG, "builtin/fog/fog", "", { {"USE_GPU_SKINNING", "0" } }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_FOG },
{ BUILTIN_FOG_SKINNED, "builtin/fog/fog", "_skinned", { {"USE_GPU_SKINNING", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_FOG },
{ BUILTIN_SKYBOX, "builtin/legacy/skybox", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_WOBBLESKY, "builtin/legacy/wobblesky", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
{ BUILTIN_POSTPROCESS, "builtin/post/postprocess", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },

View file

@ -328,7 +328,7 @@ idCVar r_showLightGrid( "r_showLightGrid", "0", CVAR_RENDERER | CVAR_INTEGER, "s
idCVar r_useLightGrid( "r_useLightGrid", "1", CVAR_RENDERER | CVAR_BOOL, "" );
idCVar r_exposure( "r_exposure", "-0.5", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_FLOAT, "HDR exposure or LDR brightness [-4.0 .. 4.0]", -4.0f, 4.0f );
idCVar r_exposure( "r_exposure", "0.5", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_FLOAT, "HDR exposure or LDR brightness [-4.0 .. 4.0]", -4.0f, 4.0f );
// RB end
const char* fileExten[4] = { "tga", "png", "jpg", "exr" };

View file

@ -51,11 +51,5 @@ void main( PS_IN fragment, out PS_OUT result )
{
float4 c = idtex2Dproj( samp0, t_Light1, fragment.texcoord0 ) * t_Light2.Sample( samp1, fragment.texcoord1 ) * rpColor;
#if USE_LINEAR_RGB
c = clamp( c, 0.0, 1.0 );
c = float4( Linear1( c.r ), Linear1( c.g ), Linear1( c.b ), Linear1( c.a ) );
#endif
result.color = c;
result.color = sRGBAToLinearRGBA( c );
}

View file

@ -52,12 +52,6 @@ void main( PS_IN fragment, out PS_OUT result )
{
float4 c = t_Fog1.Sample( samp0, fragment.texcoord0 ) * t_Fog2.Sample( samp1, fragment.texcoord1 ) * rpColor;
#if USE_LINEAR_RGB
c = clamp( c, 0.0, 1.0 );
c = float4( Linear1( c.r ), Linear1( c.g ), Linear1( c.b ), Linear1( c.a ) );
#endif
result.color = c;
result.color = sRGBAToLinearRGBA( c );
}

View file

@ -1,60 +0,0 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2020 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "global_inc.hlsl"
// *INDENT-OFF*
uniform sampler2D samp0 : register(s0);
uniform sampler2D samp1 : register(s1);
struct PS_IN {
float4 position : VPOS;
float2 texcoord0 : TEXCOORD0_centroid;
float2 texcoord1 : TEXCOORD1_centroid;
};
struct PS_OUT {
float4 color : COLOR;
};
// *INDENT-ON*
void main( PS_IN fragment, out PS_OUT result )
{
float4 c = tex2D( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * rpColor;
#if USE_LINEAR_RGB
c = clamp( c, 0.0, 1.0 );
c = float4( Linear1( c.r ), Linear1( c.g ), Linear1( c.b ), Linear1( c.a ) );
#endif
result.color = c;
}

View file

@ -1,103 +0,0 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2014 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "global_inc.hlsl"
uniform matrices_ubo { float4 matrices[408]; };
// *INDENT-OFF*
struct VS_IN {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR0;
float4 color2 : COLOR1;
};
struct VS_OUT {
float4 position : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};
// *INDENT-ON*
void main( VS_IN vertex, out VS_OUT result )
{
//--------------------------------------------------------------
// GPU transformation of the normal / binormal / bitangent
//
// multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 )
//--------------------------------------------------------------
const float w0 = vertex.color2.x;
const float w1 = vertex.color2.y;
const float w2 = vertex.color2.z;
const float w3 = vertex.color2.w;
float4 matX, matY, matZ; // must be float4 for vec4
int joint = int( vertex.color.x * 255.1 * 3.0 );
matX = matrices[int( joint + 0 )] * w0;
matY = matrices[int( joint + 1 )] * w0;
matZ = matrices[int( joint + 2 )] * w0;
joint = int( vertex.color.y * 255.1 * 3.0 );
matX += matrices[int( joint + 0 )] * w1;
matY += matrices[int( joint + 1 )] * w1;
matZ += matrices[int( joint + 2 )] * w1;
joint = int( vertex.color.z * 255.1 * 3.0 );
matX += matrices[int( joint + 0 )] * w2;
matY += matrices[int( joint + 1 )] * w2;
matZ += matrices[int( joint + 2 )] * w2;
joint = int( vertex.color.w * 255.1 * 3.0 );
matX += matrices[int( joint + 0 )] * w3;
matY += matrices[int( joint + 1 )] * w3;
matZ += matrices[int( joint + 2 )] * w3;
float4 modelPosition;
modelPosition.x = dot4( matX, vertex.position );
modelPosition.y = dot4( matY, vertex.position );
modelPosition.z = dot4( matZ, vertex.position );
modelPosition.w = 1.0;
// end of skinning
// start of fog portion
result.position.x = dot4( modelPosition, rpMVPmatrixX );
result.position.y = dot4( modelPosition, rpMVPmatrixY );
result.position.z = dot4( modelPosition, rpMVPmatrixZ );
result.position.w = dot4( modelPosition, rpMVPmatrixW );
result.texcoord0.x = dot4( modelPosition, rpTexGen0S );
result.texcoord0.y = dot4( modelPosition, rpTexGen0T );
result.texcoord1.x = dot4( modelPosition, rpTexGen1S );
result.texcoord1.y = dot4( modelPosition, rpTexGen1T );
}

View file

@ -143,12 +143,10 @@ void main(
o_rgba.rgb = ACESFilm( o_rgba.rgb );
}
#if 0
// Gamma correction since we are not rendering to an sRGB render target.
const float hdrGamma = 2.2;
float gamma = 1.0 / hdrGamma;
o_rgba.r = pow( o_rgba.r, gamma );
o_rgba.g = pow( o_rgba.g, gamma );
o_rgba.b = pow( o_rgba.b, gamma );
#endif
}

View file

@ -175,9 +175,11 @@ float PhotoLuma( float3 c )
return dot( c, photoLuma );
}
// RB: Conditional sRGB -> linear conversion. It is the default for all 3D rendering
// and only shaders for 2D rendering of GUIs define USE_SRGB to work directly on the ldr render target
float3 sRGBToLinearRGB( float3 c )
{
#if ( defined( USE_LINEAR_RGB ) && USE_LINEAR_RGB ) && ( !defined( USE_SRGB ) || !USE_SRGB )
#if !defined( USE_SRGB ) || !USE_SRGB
c = clamp( c, 0.0, 1.0 );
return Linear3( c );
@ -188,7 +190,7 @@ float3 sRGBToLinearRGB( float3 c )
float4 sRGBAToLinearRGBA( float4 c )
{
#if ( defined( USE_LINEAR_RGB ) && USE_LINEAR_RGB ) && ( !defined( USE_SRGB ) || !USE_SRGB )
#if !defined( USE_SRGB ) || !USE_SRGB
c = clamp( c, 0.0, 1.0 );
return float4( Linear1( c.r ), Linear1( c.g ), Linear1( c.b ), Linear1( c.a ) );
@ -199,7 +201,7 @@ float4 sRGBAToLinearRGBA( float4 c )
float3 LinearRGBToSRGB( float3 c )
{
#if ( defined( USE_LINEAR_RGB ) && USE_LINEAR_RGB ) && ( !defined( USE_SRGB ) || !USE_SRGB )
#if !defined( USE_SRGB ) || !USE_SRGB
c = clamp( c, 0.0, 1.0 );
return Srgb3( c );
@ -210,7 +212,7 @@ float3 LinearRGBToSRGB( float3 c )
float4 LinearRGBToSRGB( float4 c )
{
#if ( defined( USE_LINEAR_RGB ) && USE_LINEAR_RGB ) && ( !defined( USE_SRGB ) || !USE_SRGB )
#if !defined( USE_SRGB ) || !USE_SRGB
c = clamp( c, 0.0, 1.0 );
return float4( Srgb1( c.r ), Srgb1( c.g ), Srgb1( c.b ), c.a );

View file

@ -87,10 +87,10 @@ builtin/SSGI/DeepGBufferRadiosity_blur.ps.hlsl -T ps_5_0
builtin/SSGI/DeepGBufferRadiosity_radiosity.vs.hlsl -T vs_5_0
builtin/SSGI/DeepGBufferRadiosity_radiosity.ps.hlsl -T ps_5_0
builtin/fog/blendLight.vs.hlsl -T vs_5_0 -D USE_LINEAR_RGB={0,1}
builtin/fog/blendLight.ps.hlsl -T ps_5_0 -D USE_LINEAR_RGB={0,1}
builtin/fog/fog.vs.hlsl -T vs_5_0 -D USE_GPU_SKINNING={0,1} -D USE_LINEAR_RGB={0,1}
builtin/fog/fog.ps.hlsl -T ps_5_0 -D USE_GPU_SKINNING={0,1} -D USE_LINEAR_RGB={0,1}
builtin/fog/blendLight.vs.hlsl -T vs_5_0
builtin/fog/blendLight.ps.hlsl -T ps_5_0
builtin/fog/fog.vs.hlsl -T vs_5_0 -D USE_GPU_SKINNING={0,1}
builtin/fog/fog.ps.hlsl -T ps_5_0 -D USE_GPU_SKINNING={0,1}
builtin/video/bink.vs.hlsl -T vs_5_0
builtin/video/bink.ps.hlsl -T ps_5_0