mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-15 07:00:58 +00:00
sRGB gamma correct rendering experiment
This commit is contained in:
parent
96aff1e923
commit
05f06b7131
14 changed files with 88 additions and 54 deletions
|
@ -52,6 +52,6 @@ void main( VS_IN vertex, out VS_OUT result ) {
|
|||
result.position.w = dot4( vertex.position, rpMVPmatrixW );
|
||||
|
||||
result.texcoord0.xy = vertex.texcoord.xy;
|
||||
result.texcoord1 = ( swizzleColor( vertex.color2 ) * 2.0 ) - 1.0;
|
||||
result.texcoord1 = ( ( vertex.color2 ) * 2.0 ) - 1.0;
|
||||
result.color = swizzleColor( vertex.color );
|
||||
}
|
||||
|
|
|
@ -55,5 +55,5 @@ void main( VS_IN vertex, out VS_OUT result ) {
|
|||
result.texcoord0 = toEye.xyz;
|
||||
result.texcoord1 = vNormal.xyz;
|
||||
|
||||
result.color = rpColor;
|
||||
result.color = sRGBAToLinearRGBA( rpColor );
|
||||
}
|
||||
|
|
|
@ -42,6 +42,6 @@ struct PS_OUT {
|
|||
};
|
||||
|
||||
void main( PS_IN fragment, out PS_OUT result ) {
|
||||
result.color = tex2D( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * rpColor;
|
||||
result.color = tex2D( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * sRGBAToLinearRGBA( rpColor );
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,6 @@ struct PS_OUT {
|
|||
};
|
||||
|
||||
void main( PS_IN fragment, out PS_OUT result ) {
|
||||
result.color = tex2D( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * rpColor;
|
||||
result.color = tex2D( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * sRGBAToLinearRGBA( rpColor );
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,58 @@ static float dot3( float4 a, float4 b ) { return dot( a.xyz, b.xyz ); }
|
|||
static float dot4( float4 a, float4 b ) { return dot( a, b ); }
|
||||
static float dot4( float2 a, float4 b ) { return dot( float4( a, 0, 1 ), b ); }
|
||||
|
||||
// RB begin
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#define DEG2RAD( a ) ( ( a ) * PI / 180.0f )
|
||||
#define RAD2DEG( a ) ( ( a ) * 180.0f / PI )
|
||||
|
||||
// ----------------------
|
||||
// sRGB <-> Linear RGB Color Conversion
|
||||
// ----------------------
|
||||
|
||||
half3 sRGBToLinearRGB( half3 rgb )
|
||||
{
|
||||
#if defined(USE_SRGB)
|
||||
return pow( rgb, half3( 2.2 ) );
|
||||
#else
|
||||
return rgb;
|
||||
#endif
|
||||
}
|
||||
|
||||
half4 sRGBAToLinearRGBA( half4 rgba )
|
||||
{
|
||||
#if defined(USE_SRGB)
|
||||
return pow( rgba, half4( 2.2 ) );
|
||||
#else
|
||||
return rgba;
|
||||
#endif
|
||||
}
|
||||
|
||||
half3 LinearRGBToSRGB( half3 rgb )
|
||||
{
|
||||
#if defined(USE_SRGB)
|
||||
return pow( rgb, half3( 1.0 ) / half3( 2.2 ) );
|
||||
#else
|
||||
return rgb;
|
||||
#endif
|
||||
}
|
||||
|
||||
half4 LinearRGBToSRGB( half4 rgba )
|
||||
{
|
||||
#if defined(USE_SRGB)
|
||||
rgba.rgb = pow( rgba.rgb, half3( 1.0 ) / half3( 2.2 ) );
|
||||
return rgba; //pow( rgba, half4( 1.0 ) / half4( 2.2 ) );
|
||||
#else
|
||||
return rgba;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// RB end
|
||||
|
||||
// ----------------------
|
||||
// YCoCg Color Conversion
|
||||
// ----------------------
|
||||
|
@ -173,33 +225,6 @@ float rand( float2 co ) {
|
|||
return frac( sin( dot( co.xy, float2( 12.9898, 78.233 ) ) ) * 43758.5453 );
|
||||
}
|
||||
|
||||
// RB begin
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#define DEG2RAD( a ) ( ( a ) * PI / 180.0f )
|
||||
#define RAD2DEG( a ) ( ( a ) * 180.0f / PI )
|
||||
|
||||
half3 sRGBToLinearRGB( half3 rgb )
|
||||
{
|
||||
#if defined(USE_SRGB)
|
||||
return pow( rgb, half3( 2.2 ) );
|
||||
#else
|
||||
return rgb;
|
||||
#endif
|
||||
}
|
||||
|
||||
half4 sRGBAToLinearRGBA( half4 rgba )
|
||||
{
|
||||
#if defined(USE_SRGB)
|
||||
return pow( rgba, half4( 2.2 ) );
|
||||
#else
|
||||
return rgba;
|
||||
#endif
|
||||
}
|
||||
// RB end
|
||||
|
||||
#define _half2( x ) half2( x )
|
||||
#define _half3( x ) half3( x )
|
||||
#define _half4( x ) half4( x )
|
||||
|
@ -209,7 +234,10 @@ half4 sRGBAToLinearRGBA( half4 rgba )
|
|||
|
||||
#define VPOS WPOS
|
||||
static float4 idtex2Dproj( sampler2D samp, float4 texCoords ) { return tex2Dproj( samp, texCoords.xyw ); }
|
||||
static float4 swizzleColor( float4 c ) { return c; }
|
||||
static float4 swizzleColor( float4 c )
|
||||
{
|
||||
return sRGBAToLinearRGBA( c );
|
||||
}
|
||||
static float2 vposToScreenPosTexCoord( float2 vpos ) { return vpos.xy * rpWindowCoord.xy; }
|
||||
|
||||
#define BRANCH
|
||||
|
|
|
@ -52,6 +52,6 @@ void main( VS_IN vertex, out VS_OUT result ) {
|
|||
result.position.w = dot4( vertex.position, rpMVPmatrixW );
|
||||
|
||||
result.texcoord0.xy = vertex.texcoord.xy;
|
||||
result.texcoord1 = ( swizzleColor( vertex.color2 ) * 2.0 ) - 1.0;
|
||||
result.texcoord1 = ( ( vertex.color2 ) * 2.0 ) - 1.0;
|
||||
result.color = swizzleColor( vertex.color );
|
||||
}
|
||||
|
|
|
@ -62,5 +62,5 @@ void main( PS_IN fragment, out PS_OUT result ) {
|
|||
screenTexCoord += ( localNormal * fragment.texcoord2.xy );
|
||||
screenTexCoord = saturate( screenTexCoord );
|
||||
|
||||
result.color = tex2D( samp0, screenTexCoord );
|
||||
result.color = sRGBAToLinearRGBA( tex2D( samp0, screenTexCoord ) );
|
||||
}
|
|
@ -64,5 +64,5 @@ void main( PS_IN fragment, out PS_OUT result ) {
|
|||
screenTexCoord += ( localNormal * fragment.texcoord2.xy );
|
||||
screenTexCoord = saturate( screenTexCoord );
|
||||
|
||||
result.color = tex2D( samp0, screenTexCoord );
|
||||
result.color = sRGBAToLinearRGBA( tex2D( samp0, screenTexCoord ) );
|
||||
}
|
|
@ -53,8 +53,8 @@ struct PS_OUT {
|
|||
|
||||
void main( PS_IN fragment, out PS_OUT result ) {
|
||||
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
|
||||
half4 lightFalloff = sRGBAToLinearRGBA( idtex2Dproj( samp1, fragment.texcoord2 ) );
|
||||
half4 lightProj = sRGBAToLinearRGBA( idtex2Dproj( samp2, fragment.texcoord3 ) );
|
||||
half4 lightFalloff = ( idtex2Dproj( samp1, fragment.texcoord2 ) );
|
||||
half4 lightProj = ( idtex2Dproj( samp2, fragment.texcoord3 ) );
|
||||
half4 YCoCG = tex2D( samp3, fragment.texcoord4.xy );
|
||||
half4 specMap = sRGBAToLinearRGBA( tex2D( samp4, fragment.texcoord5.xy ) );
|
||||
|
||||
|
|
|
@ -63,10 +63,10 @@ struct PS_OUT
|
|||
void main( PS_IN fragment, out PS_OUT result )
|
||||
{
|
||||
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
|
||||
half4 lightFalloff = sRGBAToLinearRGBA( idtex2Dproj( samp1, fragment.texcoord2 ) );
|
||||
half4 lightProj = sRGBAToLinearRGBA( idtex2Dproj( samp2, fragment.texcoord3 ) );
|
||||
half4 lightFalloff = ( idtex2Dproj( samp1, fragment.texcoord2 ) );
|
||||
half4 lightProj = ( idtex2Dproj( samp2, fragment.texcoord3 ) );
|
||||
half4 YCoCG = tex2D( samp3, fragment.texcoord4.xy );
|
||||
half4 specMap = sRGBAToLinearRGBA( tex2D( samp4, fragment.texcoord5.xy ) );
|
||||
half4 specMap = ( tex2D( samp4, fragment.texcoord5.xy ) );
|
||||
|
||||
half3 lightVector = normalize( fragment.texcoord0.xyz );
|
||||
half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) );
|
||||
|
@ -100,8 +100,8 @@ 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 diffuseColor = diffuseMap * sRGBToLinearRGB( rpDiffuseModifier.xyz );
|
||||
half3 specularColor = specMap.xyz * specularContribution * sRGBToLinearRGB( rpSpecularModifier.xyz * 1.0 );
|
||||
half3 lightColor = lightProj.xyz * lightFalloff.xyz;
|
||||
|
||||
half rim = 1.0f - saturate( hDotN );
|
||||
|
|
|
@ -43,5 +43,5 @@ struct PS_OUT
|
|||
|
||||
void main( PS_IN fragment, out PS_OUT result )
|
||||
{
|
||||
result.color = fragment.color;
|
||||
result.color = sRGBAToLinearRGBA( fragment.color );
|
||||
}
|
|
@ -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-2015 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -127,7 +128,8 @@ ID_INLINE void idImage::DeriveOpts()
|
|||
opts.gammaMips = true;
|
||||
break;
|
||||
case TD_LIGHT:
|
||||
opts.format = FMT_RGB565;
|
||||
// RB: don't destroy lighting
|
||||
opts.format = FMT_RGBA8; //FMT_RGB565;
|
||||
opts.gammaMips = true;
|
||||
break;
|
||||
case TD_LOOKUP_TABLE_MONO:
|
||||
|
|
|
@ -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-2014 Robert Beckebans
|
||||
Copyright (C) 2013-2015 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -355,10 +355,12 @@ void idImage::AllocImage()
|
|||
PurgeImage();
|
||||
|
||||
int sRGB = r_useSRGB.GetInteger();
|
||||
|
||||
|
||||
switch( opts.format )
|
||||
{
|
||||
case FMT_RGBA8:
|
||||
//internalFormat = GL_RGBA8;
|
||||
//internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
|
||||
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
|
@ -376,12 +378,14 @@ void idImage::AllocImage()
|
|||
break;
|
||||
case FMT_ALPHA:
|
||||
#if defined( USE_CORE_PROFILE )
|
||||
#if 1
|
||||
if( ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) )
|
||||
{
|
||||
internalFormat = GL_SRGB8_ALPHA8;
|
||||
dataFormat = GL_ALPHA;
|
||||
internalFormat = GL_SRGB;
|
||||
dataFormat = GL_RED;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
internalFormat = GL_R8;
|
||||
dataFormat = GL_RED;
|
||||
|
@ -423,14 +427,14 @@ void idImage::AllocImage()
|
|||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_DXT1:
|
||||
//internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
//internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case FMT_DXT5:
|
||||
//internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) && opts.colorFormat != CFM_YCOCG_DXT5 && opts.colorFormat != CFM_NORMAL_DXT5 ) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
//internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
dataFormat = GL_RGBA;
|
||||
dataType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
|
|
@ -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-2014 Robert Beckebans
|
||||
Copyright (C) 2013-2015 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -552,7 +552,7 @@ idStr StripDeadCode( const idStr& in, const char* name, const idStrList& compile
|
|||
{
|
||||
src.AddDefine( "USE_HALF_LAMBERT" );
|
||||
}
|
||||
|
||||
|
||||
if( r_useSRGB.GetBool() )
|
||||
{
|
||||
src.AddDefine( "USE_SRGB" );
|
||||
|
|
Loading…
Reference in a new issue