Lighting in linear RGB. One step closer to PBR

This commit is contained in:
Robert Beckebans 2015-12-30 11:01:57 +01:00
parent 195f8082b8
commit a74956208e
8 changed files with 3126 additions and 1109 deletions

View file

@ -56,10 +56,10 @@ void main( PS_IN fragment, out PS_OUT result ) {
// 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;
#if defined(USE_NORMAL_FMT_RGB8)
@ -75,8 +75,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 * 1.5f;
half3 specularColor = specMap.xyz * specularContribution * rpSpecularModifier.xyz;
half3 diffuseColor = diffuseMap * sRGBToLinearRGB( rpDiffuseModifier.xyz ) * 1.5f;
half3 specularColor = specMap.xyz * specularContribution * sRGBToLinearRGB( rpSpecularModifier.xyz );
// RB: http://developer.valvesoftware.com/wiki/Half_Lambert
float halfLdotN = dot3( localNormal, lightVector ) * 0.5 + 0.5;
@ -85,11 +85,11 @@ void main( PS_IN fragment, out PS_OUT result ) {
// traditional very dark Lambert light model used in Doom 3
float ldotN = dot3( localNormal, lightVector );
half3 lightColor = rpAmbientColor.rgb;
half3 lightColor = sRGBToLinearRGB( rpAmbientColor.rgb );
half rim = 1.0f - saturate( hDotN );
half rimPower = 8.0;
half3 rimColor = half3( 0.125 ) * 1.2 * lightColor * pow( rim, rimPower );
half3 rimColor = sRGBToLinearRGB( half3( 0.125 ) * 1.2 ) * lightColor * pow( rim, rimPower );
//result.color.rgb = localNormal.xyz * 0.5 + 0.5;
result.color.xyz = ( ( diffuseColor + specularColor ) * halfLdotN * lightColor + rimColor ) * fragment.color.rgb;;

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 = sRGBAToLinearRGBA( tex2D( samp0, screenTexCoord ) );
result.color = ( 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 = sRGBAToLinearRGBA( tex2D( samp0, screenTexCoord ) );
result.color = ( 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 = sRGBAToLinearRGBA( tex2D( samp0, screenTexCoord.xy ) );
result.color = ( tex2D( samp0, screenTexCoord.xy ) );
}

View file

@ -90,9 +90,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 = lightProj.xyz * lightFalloff.xyz;
half3 diffuseColor = diffuseMap * sRGBToLinearRGB( rpDiffuseModifier.xyz );
half3 specularColor = specMap.xyz * specularContribution * sRGBToLinearRGB( rpSpecularModifier.xyz * 1.0 );
half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );
half rim = 1.0f - saturate( hDotN );
half rimPower = 16.0f;

View file

@ -66,7 +66,7 @@ void main( PS_IN fragment, out PS_OUT result )
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 = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) );

View file

@ -140,7 +140,7 @@ ID_INLINE void idImage::DeriveOpts()
break;
case TD_LIGHT:
// RB: don't destroy lighting
opts.format = FMT_RGBA8; //FMT_RGB565;
opts.format = FMT_RGB565; //FMT_RGBA8;
opts.gammaMips = true;
break;
case TD_LOOKUP_TABLE_MONO:

File diff suppressed because it is too large Load diff