Always render 2D GUIs in sRGB color space

This commit is contained in:
Robert Beckebans 2016-01-18 22:21:32 +01:00
parent 9c324b53d1
commit fb618feeca
7 changed files with 73 additions and 43 deletions

View file

@ -72,5 +72,5 @@ void main( PS_IN fragment, out PS_OUT result ) {
float4 envMap = texCUBE( samp0, reflectionVector );
result.color = float4( envMap.xyz, 1.0f ) * fragment.color;
result.color = float4( sRGBToLinearRGB( envMap.xyz ), 1.0f ) * fragment.color;
}

View file

@ -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-2016 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -133,7 +133,7 @@ static float dot4( float2 a, float4 b ) { return dot( float4( a, 0, 1 ), b ); }
half3 sRGBToLinearRGB( half3 rgb )
{
#if defined(USE_LINEAR_RGB)
#if defined( USE_LINEAR_RGB ) && !defined( USE_SRGB )
return max( pow( rgb, half3( 2.2 ) ), half3( 0.0 ) );
#else
return rgb;
@ -142,7 +142,7 @@ half3 sRGBToLinearRGB( half3 rgb )
half4 sRGBAToLinearRGBA( half4 rgba )
{
#if defined(USE_LINEAR_RGB)
#if defined( USE_LINEAR_RGB ) && !defined( USE_SRGB )
return float4( max( pow( rgba.rgb, half3( 2.2 ) ), half3( 0.0 ) ), rgba.a );
#else
return rgba;
@ -151,7 +151,7 @@ half4 sRGBAToLinearRGBA( half4 rgba )
half3 LinearRGBToSRGB( half3 rgb )
{
#if defined(USE_LINEAR_RGB)
#if defined( USE_LINEAR_RGB ) && !defined( USE_SRGB )
return pow( rgb, half3( 1.0 ) / half3( 2.2 ) );
#else
return rgb;
@ -160,7 +160,7 @@ half3 LinearRGBToSRGB( half3 rgb )
half4 LinearRGBToSRGB( half4 rgba )
{
#if defined(USE_LINEAR_RGB)
#if defined( USE_LINEAR_RGB ) && !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
@ -227,11 +227,9 @@ float rand( float2 co ) {
#define square( x ) ( x * x )
static const half4 LUMINANCE_VECTOR = half4( 0.2125, 0.7154, 0.0721, 0.0 );
static const half4 LUMINANCE_SRGB = half4( 0.2125, 0.7154, 0.0721, 0.0 );
static const half4 LUMINANCE_LINEAR = half4( 0.299, 0.587, 0.144, 0.0 );
#define _half2( x ) half2( x )
#define _half3( x ) half3( x )
#define _half4( x ) half4( x )

View file

@ -41,5 +41,5 @@ struct PS_OUT {
};
void main( PS_IN fragment, out PS_OUT result ) {
result.color = texCUBE( samp0, fragment.texcoord0 ) * fragment.color;
result.color = sRGBAToLinearRGBA( texCUBE( samp0, fragment.texcoord0 ) ) * fragment.color;
}

View file

@ -90,8 +90,8 @@ void idRenderProgManager::Init()
bool requireGPUSkinningSupport;
} builtins[] =
{
{ BUILTIN_GUI, "gui.vfp", 0, false },
{ BUILTIN_COLOR, "color.vfp", 0, false },
{ BUILTIN_GUI, "gui.vfp", "", 0, false },
{ BUILTIN_COLOR, "color.vfp", "", 0, false },
// RB begin
{ BUILTIN_COLOR_SKINNED, "color", "_skinned", BIT( USE_GPU_SKINNING ), true },
{ BUILTIN_VERTEX_COLOR, "vertex_color.vfp", "", 0, false },
@ -101,10 +101,11 @@ void idRenderProgManager::Init()
{ BUILTIN_SMALL_GEOMETRY_BUFFER_SKINNED, "gbuffer", "_skinned", BIT( USE_GPU_SKINNING ), true },
// RB end
// { BUILTIN_SIMPLESHADE, "simpleshade.vfp", 0, false },
{ BUILTIN_TEXTURED, "texture.vfp", 0, false },
{ BUILTIN_TEXTURE_VERTEXCOLOR, "texture_color.vfp", 0, false },
{ BUILTIN_TEXTURE_VERTEXCOLOR_SKINNED, "texture_color_skinned.vfp", 0, true },
{ BUILTIN_TEXTURE_TEXGEN_VERTEXCOLOR, "texture_color_texgen.vfp", 0, false },
{ BUILTIN_TEXTURED, "texture.vfp", "", 0, false },
{ BUILTIN_TEXTURE_VERTEXCOLOR, "texture_color.vfp", "", 0, false },
{ BUILTIN_TEXTURE_VERTEXCOLOR_SRGB, "texture_color.vfp", "", BIT( USE_SRGB ), false },
{ BUILTIN_TEXTURE_VERTEXCOLOR_SKINNED, "texture_color_skinned.vfp", "", 0, true },
{ BUILTIN_TEXTURE_TEXGEN_VERTEXCOLOR, "texture_color_texgen.vfp", "", 0, false },
// RB begin
{ BUILTIN_INTERACTION, "interaction.vfp", "", 0, false },
{ BUILTIN_INTERACTION_SKINNED, "interaction", "_skinned", BIT( USE_GPU_SKINNING ), true },
@ -117,26 +118,26 @@ void idRenderProgManager::Init()
{ BUILTIN_INTERACTION_SHADOW_MAPPING_PARALLEL, "interactionSM", "_parallel", BIT( LIGHT_PARALLEL ), false },
{ BUILTIN_INTERACTION_SHADOW_MAPPING_PARALLEL_SKINNED, "interactionSM", "_parallel_skinned", BIT( USE_GPU_SKINNING ) | BIT( LIGHT_PARALLEL ), true },
// RB end
{ BUILTIN_ENVIRONMENT, "environment.vfp", 0, false },
{ BUILTIN_ENVIRONMENT_SKINNED, "environment_skinned.vfp", 0, true },
{ BUILTIN_BUMPY_ENVIRONMENT, "bumpyenvironment.vfp", 0, false },
{ BUILTIN_BUMPY_ENVIRONMENT_SKINNED, "bumpyenvironment_skinned.vfp", 0, true },
{ BUILTIN_ENVIRONMENT, "environment.vfp", "", 0, false },
{ BUILTIN_ENVIRONMENT_SKINNED, "environment_skinned.vfp", "", 0, true },
{ BUILTIN_BUMPY_ENVIRONMENT, "bumpyenvironment.vfp", "", 0, false },
{ BUILTIN_BUMPY_ENVIRONMENT_SKINNED, "bumpyenvironment_skinned.vfp", "", 0, true },
{ BUILTIN_DEPTH, "depth.vfp", 0, false },
{ BUILTIN_DEPTH_SKINNED, "depth_skinned.vfp", 0, true },
{ BUILTIN_DEPTH, "depth.vfp", "", 0, false },
{ BUILTIN_DEPTH_SKINNED, "depth_skinned.vfp", "", 0, true },
{ BUILTIN_SHADOW, "shadow.vfp", 0, false },
{ BUILTIN_SHADOW_SKINNED, "shadow_skinned.vfp", 0, true },
{ BUILTIN_SHADOW, "shadow.vfp", "", 0, false },
{ BUILTIN_SHADOW_SKINNED, "shadow_skinned.vfp", "", 0, true },
{ BUILTIN_SHADOW_DEBUG, "shadowDebug.vfp", 0, false },
{ BUILTIN_SHADOW_DEBUG_SKINNED, "shadowDebug_skinned.vfp", 0, true },
{ BUILTIN_SHADOW_DEBUG, "shadowDebug.vfp", "", 0, false },
{ BUILTIN_SHADOW_DEBUG_SKINNED, "shadowDebug_skinned.vfp", "", 0, true },
{ BUILTIN_BLENDLIGHT, "blendlight.vfp", 0, false },
{ BUILTIN_FOG, "fog.vfp", 0, false },
{ BUILTIN_FOG_SKINNED, "fog_skinned.vfp", 0, true },
{ BUILTIN_SKYBOX, "skybox.vfp", 0, false },
{ BUILTIN_WOBBLESKY, "wobblesky.vfp", 0, false },
{ BUILTIN_POSTPROCESS, "postprocess.vfp", 0, false },
{ BUILTIN_BLENDLIGHT, "blendlight.vfp", "", 0, false },
{ BUILTIN_FOG, "fog.vfp", "", 0, false },
{ BUILTIN_FOG_SKINNED, "fog_skinned.vfp", "", 0, true },
{ BUILTIN_SKYBOX, "skybox.vfp", "", 0, false },
{ BUILTIN_WOBBLESKY, "wobblesky.vfp", "", 0, false },
{ BUILTIN_POSTPROCESS, "postprocess.vfp", "", 0, false },
// RB begin
{ BUILTIN_SCREEN, "screen", "", 0, false },
{ BUILTIN_TONEMAP, "tonemap", "", 0, false },
@ -158,13 +159,13 @@ void idRenderProgManager::Init()
{ BUILTIN_DEEP_GBUFFER_RADIOSITY_BLUR, "DeepGBufferRadiosity_blur", "", 0, false },
{ BUILTIN_DEEP_GBUFFER_RADIOSITY_BLUR_AND_OUTPUT, "DeepGBufferRadiosity_blur", "_write", BIT( BRIGHTPASS ), false },
// RB end
{ BUILTIN_STEREO_DEGHOST, "stereoDeGhost.vfp", 0, false },
{ BUILTIN_STEREO_WARP, "stereoWarp.vfp", 0, false },
{ BUILTIN_STEREO_DEGHOST, "stereoDeGhost.vfp", "", 0, false },
{ BUILTIN_STEREO_WARP, "stereoWarp.vfp", "", 0, false },
// { BUILTIN_ZCULL_RECONSTRUCT, "zcullReconstruct.vfp", 0, false },
{ BUILTIN_BINK, "bink.vfp", 0, false },
{ BUILTIN_BINK_GUI, "bink_gui.vfp", 0, false },
{ BUILTIN_STEREO_INTERLACE, "stereoInterlace.vfp", 0, false },
{ BUILTIN_MOTION_BLUR, "motionBlur.vfp", 0, false },
{ BUILTIN_BINK, "bink.vfp", "", 0, false },
{ BUILTIN_BINK_GUI, "bink_gui.vfp", "", 0, false },
{ BUILTIN_STEREO_INTERLACE, "stereoInterlace.vfp", "", 0, false },
{ BUILTIN_MOTION_BLUR, "motionBlur.vfp", "", 0, false },
// RB begin
{ BUILTIN_DEBUG_SHADOWMAP, "debug_shadowmap.vfp", "", 0, false },

View file

@ -243,6 +243,11 @@ public:
BindShader_Builtin( BUILTIN_TEXTURE_VERTEXCOLOR );
};
void BindShader_TextureVertexColor_sRGB()
{
BindShader_Builtin( BUILTIN_TEXTURE_VERTEXCOLOR_SRGB );
};
void BindShader_TextureVertexColorSkinned()
{
BindShader_Builtin( BUILTIN_TEXTURE_VERTEXCOLOR_SKINNED );
@ -578,6 +583,7 @@ protected:
BUILTIN_SIMPLESHADE,
BUILTIN_TEXTURED,
BUILTIN_TEXTURE_VERTEXCOLOR,
BUILTIN_TEXTURE_VERTEXCOLOR_SRGB,
BUILTIN_TEXTURE_VERTEXCOLOR_SKINNED,
BUILTIN_TEXTURE_TEXGEN_VERTEXCOLOR,
BUILTIN_INTERACTION,
@ -657,6 +663,7 @@ protected:
LIGHT_PARALLEL,
BRIGHTPASS,
HDR_DEBUG,
USE_SRGB,
MAX_SHADER_MACRO_NAMES,
};

View file

@ -365,7 +365,8 @@ const char* idRenderProgManager::GLSLMacroNames[MAX_SHADER_MACRO_NAMES] =
"LIGHT_POINT",
"LIGHT_PARALLEL",
"BRIGHTPASS",
"HDR_DEBUG"
"HDR_DEBUG",
"USE_SRGB"
};
// RB end
@ -525,6 +526,10 @@ idStr StripDeadCode( const idStr& in, const char* name, const idStrList& compile
//idLexer src( LEXFL_NOFATALERRORS );
idParser_EmbeddedGLSL src( LEXFL_NOFATALERRORS );
src.LoadMemory( in.c_str(), in.Length(), name );
idStrStatic<256> sourceName = "filename ";
sourceName += name;
src.AddDefine( sourceName );
src.AddDefine( "PC" );
for( int i = 0; i < compileMacros.Num(); i++ )
@ -1583,6 +1588,9 @@ idStr ConvertCG2GLSL( const idStr& in, const char* name, bool isVertexProgram, i
idStr out;
// RB: tell shader debuggers what shader we look at
idStr filenameHint = "// filename " + idStr( name ) + "\n";
// RB: changed to allow multiple versions of GLSL
if( isVertexProgram )
{
@ -1592,6 +1600,7 @@ idStr ConvertCG2GLSL( const idStr& in, const char* name, bool isVertexProgram, i
case GLDRV_OPENGL_ES3:
{
out.ReAllocate( idStr::Length( vertexInsert_GLSL_ES_1_0 ) + in.Length() * 2, false );
out += filenameHint;
out += vertexInsert_GLSL_ES_1_0;
break;
}
@ -1599,6 +1608,7 @@ idStr ConvertCG2GLSL( const idStr& in, const char* name, bool isVertexProgram, i
case GLDRV_OPENGL_MESA:
{
out.ReAllocate( idStr::Length( vertexInsert_GLSL_ES_3_00 ) + in.Length() * 2, false );
out += filenameHint;
out += vertexInsert_GLSL_ES_3_00;
break;
}
@ -1606,6 +1616,7 @@ idStr ConvertCG2GLSL( const idStr& in, const char* name, bool isVertexProgram, i
default:
{
out.ReAllocate( idStr::Length( vertexInsert_GLSL_1_50 ) + in.Length() * 2, false );
out += filenameHint;
out += vertexInsert_GLSL_1_50;
break;
}
@ -1621,6 +1632,7 @@ idStr ConvertCG2GLSL( const idStr& in, const char* name, bool isVertexProgram, i
case GLDRV_OPENGL_ES3:
{
out.ReAllocate( idStr::Length( fragmentInsert_GLSL_ES_1_0 ) + in.Length() * 2, false );
out += filenameHint;
out += fragmentInsert_GLSL_ES_1_0;
break;
}
@ -1628,6 +1640,7 @@ idStr ConvertCG2GLSL( const idStr& in, const char* name, bool isVertexProgram, i
case GLDRV_OPENGL_MESA:
{
out.ReAllocate( idStr::Length( fragmentInsert_GLSL_ES_3_00 ) + in.Length() * 2, false );
out += filenameHint;
out += fragmentInsert_GLSL_ES_3_00;
break;
}
@ -1635,6 +1648,7 @@ idStr ConvertCG2GLSL( const idStr& in, const char* name, bool isVertexProgram, i
default:
{
out.ReAllocate( idStr::Length( fragmentInsert_GLSL_1_50 ) + in.Length() * 2, false );
out += filenameHint;
out += fragmentInsert_GLSL_1_50;
break;
}

View file

@ -437,10 +437,20 @@ static void RB_BindVariableStageImage( const textureStage_t* texture, const floa
}
else if( cin.image != NULL )
{
//Carl: A single RGB image works better with the FFMPEG BINK codec.
// Carl: A single RGB image works better with the FFMPEG BINK codec.
GL_SelectTexture( 0 );
cin.image->Bind();
renderProgManager.BindShader_TextureVertexColor();
/*
if( backEnd.viewDef->is2Dgui )
{
renderProgManager.BindShader_TextureVertexColor_sRGB();
}
else
{
renderProgManager.BindShader_TextureVertexColor();
}
*/
}
else
{
@ -3777,11 +3787,11 @@ static int RB_DrawShaderPasses( const drawSurf_t* const* const drawSurfs, const
{
// This is a hack... Only SWF Guis set GLS_OVERRIDE
// Old style guis do not, and we don't want them to use the new GUI renederProg
renderProgManager.BindShader_BinkGUI();
renderProgManager.BindShader_TextureVertexColor_sRGB();
}
else
{
renderProgManager.BindShader_Bink();
renderProgManager.BindShader_TextureVertexColor();
}
}
else