Merge remote-tracking branch 'RBDOOM-3-BFG/gamma-correction' into HDR-linearRGB

Conflicts:
	base/renderprogs/global.inc
	neo/renderer/tr_local.h
This commit is contained in:
Robert Beckebans 2015-12-21 13:27:12 +01:00
commit a378e73823
17 changed files with 121 additions and 57 deletions

View file

@ -218,29 +218,22 @@ unfortunately requires Steam for Windows - Steam for Linux or OSX won't do, beca
Even the DVD version of Doom 3 BFG only contains encrytped data that is decoded
by Steam on install.
Fortunately, you can run Steam in Wine to install Doom3 BFG and afterwards copy the
game data somewhere else to use it with native executables.
Winetricks ( http://winetricks.org/ ) makes installing Windows Steam on Linux really easy.
On Linux and OSX the easiest way to install is with SteamCMD: https://developer.valvesoftware.com/wiki/SteamCMD
See the description on https://developer.valvesoftware.com/wiki/SteamCMD#Linux (OS X is directly below that) on how to install SteamCMD on your system. You won't have to create a new user.
If using the Linux version of Steam, you can open the console (launch steam with -console or try steam://open/console in a web browser) and enter the following:
download_depot 208200 208202
This will download the base game files to a path similar to (the path cannot be configured):
~/.steam/root/ubuntu12_32/steamapps/content/app_208200/depot_208202/
Steam will not provide feedback on the download progress so you will have to watch the folder.
You will also have to run download_depot for your language:
download_depot 208200 <language depot>
Where <language depot> is:
English: 208203
German: 208204
French: 208205
Italian: 208206
Spanish: 208207
Japanese: 208208
Combining the contents of both depots will provide the necessary game files for the engine.
Then you can download Doom 3 BFG with
> ./steamcmd.sh +@sSteamCmdForcePlatformType windows +login <YOUR_STEAM_LOGIN_NAME> +force_install_dir ./doom3bfg/ +app_update 208200 validate +quit
(replace <YOUR_STEAM_LOGIN_NAME> with your steam login name)
When it's done you should have the normal windows installation of Doom 3 BFG in ./doom3bfg/ and the needed files in ./doom3bfg/base/
That number is the "AppID" of Doom 3 BFG; if you wanna use this to get the data of other games you own, you can look up the AppID at https://steamdb.info/
NOTE that we've previously recommended using download_depot in the Steam console to install the game data. That turned out to be unreliable and result in broken, unusable game data. So use SteamCMD instead, as described above.
Anyway:
1. Install Doom 3 BFG in Steam (Windows version), make sure it's getting
1. Install Doom 3 BFG in Steam (Windows version) or SteamCMD, make sure it's getting
updated/patched.
2. Create your own Doom 3 BFG directory, e.g. /path/to/Doom3BFG/
@ -248,6 +241,7 @@ Anyway:
3. Copy the game-data's base dir from Steam to that directory
(e.g. /path/to/Doom3BFG/), it's in
/your/path/to/Steam/steamapps/common/DOOM 3 BFG Edition/base/
or, if you used SteamCMD, in the path you used above.
4. Copy your RBDoom3BFG executable that you created in 5) or 6) and the FFmpeg DLLs to your own
Doom 3 BFG directory (/path/to/Doom3BFG).

View file

@ -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 );
}

View file

@ -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 );
}

View file

@ -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 );
}

View file

@ -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 );
}

View file

@ -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,17 +225,8 @@ 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 )
static const half4 LUMINANCE_VECTOR = half4( 0.2125, 0.7154, 0.0721, 0.0 );
// RB end
#define _half2( x ) half2( x )
#define _half3( x ) half3( x )
#define _half4( x ) half4( x )
@ -193,7 +236,10 @@ static const half4 LUMINANCE_VECTOR = half4( 0.2125, 0.7154, 0.0721, 0.0 );
#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

View file

@ -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 );
}

View file

@ -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 ) );
}

View file

@ -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 ) );
}

View file

@ -54,5 +54,5 @@ void main( PS_IN fragment, out PS_OUT result ) {
screenTexCoord = saturate( screenTexCoord );
// load the screen render
result.color = tex2D( samp0, screenTexCoord.xy );
result.color = sRGBAToLinearRGBA( tex2D( samp0, screenTexCoord.xy ) );
}

View file

@ -53,13 +53,13 @@ struct PS_OUT {
void main( PS_IN fragment, out PS_OUT result ) {
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
half4 lightFalloff = idtex2Dproj( samp1, fragment.texcoord2 );
half4 lightProj = 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 = tex2D( samp4, fragment.texcoord5.xy );
half4 specMap = sRGBAToLinearRGBA( tex2D( samp4, fragment.texcoord5.xy ) );
half3 lightVector = normalize( fragment.texcoord0.xyz );
half3 diffuseMap = ConvertYCoCgToRGB( YCoCG );
half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) );
half3 localNormal;
// RB begin

View file

@ -63,13 +63,13 @@ struct PS_OUT
void main( PS_IN fragment, out PS_OUT result )
{
half4 bumpMap = tex2D( samp0, fragment.texcoord1.xy );
half4 lightFalloff = idtex2Dproj( samp1, fragment.texcoord2 );
half4 lightProj = 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 = tex2D( samp4, fragment.texcoord5.xy );
half4 specMap = ( tex2D( samp4, fragment.texcoord5.xy ) );
half3 lightVector = normalize( fragment.texcoord0.xyz );
half3 diffuseMap = ConvertYCoCgToRGB( YCoCG );
half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) );
half3 localNormal;
// RB begin
@ -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 );

View file

@ -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 );
}

View file

@ -136,7 +136,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:

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-2015 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -365,27 +365,42 @@ void idImage::AllocImage()
GL_CheckErrors();
PurgeImage();
int sRGB = r_useSRGB.GetInteger();
switch( opts.format )
{
case FMT_RGBA8:
internalFormat = GL_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;
break;
case FMT_XRGB8:
internalFormat = GL_RGB;
internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB : GL_RGB;
dataFormat = GL_RGBA;
dataType = GL_UNSIGNED_BYTE;
break;
case FMT_RGB565:
//internalFormat = ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) ? GL_SRGB : GL_RGB;
internalFormat = GL_RGB;
dataFormat = GL_RGB;
dataType = GL_UNSIGNED_SHORT_5_6_5;
break;
case FMT_ALPHA:
#if defined( USE_CORE_PROFILE )
internalFormat = GL_R8;
dataFormat = GL_RED;
#if 1
if( ( glConfig.sRGBFramebufferAvailable && ( sRGB == 1 || sRGB == 3 ) ) )
{
internalFormat = GL_SRGB;
dataFormat = GL_RED;
}
else
#endif
{
internalFormat = GL_R8;
dataFormat = GL_RED;
}
#else
internalFormat = GL_ALPHA8;
dataFormat = GL_ALPHA;
@ -423,12 +438,14 @@ void idImage::AllocImage()
dataType = GL_UNSIGNED_BYTE;
break;
case FMT_DXT1:
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 = 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;

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-2015 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -555,6 +555,11 @@ idStr StripDeadCode( const idStr& in, const char* name, const idStrList& compile
src.AddDefine( "USE_HALF_LAMBERT" );
}
if( r_useSRGB.GetBool() )
{
src.AddDefine( "USE_SRGB" );
}
idList< idCGBlock > blocks;
blocks.SetNum( 100 );

View file

@ -965,6 +965,7 @@ extern idCVar r_useShadowDepthBounds; // use depth bounds test on individual sh
extern idCVar r_useShadowMapping; // use shadow mapping instead of stencil shadows
extern idCVar r_useHalfLambertLighting; // use Half-Lambert lighting instead of classic Lambert
extern idCVar r_useHDR;
extern idCVar r_useSRGB;
// RB end
extern idCVar r_skipStaticInteractions; // skip interactions created at level load