mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 22:50:45 +00:00
Added missing shaders from last commit
This commit is contained in:
parent
5854242d7b
commit
36105c277c
5 changed files with 49 additions and 84 deletions
|
@ -66,9 +66,9 @@ half3 Fresnel_SchlickRoughness( half3 specularColor, half vDotN, half roughness
|
|||
return specularColor + ( max( half3( 1.0 - roughness ), specularColor ) - specularColor ) * pow( 1.0 - vDotN, 5.0 );
|
||||
}
|
||||
|
||||
// Sébastien Lagarde proposes an empirical approach to derive the specular occlusion term from the diffuse occlusion term in [Lagarde14].
|
||||
// Sebastien Lagarde proposes an empirical approach to derive the specular occlusion term from the diffuse occlusion term in [Lagarde14].
|
||||
// The result does not have any physical basis but produces visually pleasant results.
|
||||
// See Sébastien Lagarde and Charles de Rousiers. 2014. Moving Frostbite to PBR.
|
||||
// See Sebastien Lagarde and Charles de Rousiers. 2014. Moving Frostbite to PBR.
|
||||
float ComputeSpecularAO( float vDotN, float ao, float roughness )
|
||||
{
|
||||
return clamp( pow( vDotN + ao, exp2( -16.0 * roughness - 1.0 ) ) - 1.0 + ao, 0.0, 1.0 );
|
||||
|
@ -101,9 +101,22 @@ float Visibility_SmithGGX( half vdotN, half ldotN, float alpha )
|
|||
return ( 1.0 / max( V1 * V2, 0.15 ) );
|
||||
}
|
||||
|
||||
// HACK calculate roughness from D3 gloss maps
|
||||
float EstimateLegacyRoughness( float3 specMapSRGB )
|
||||
{
|
||||
float Y = dot( LUMINANCE_SRGB.rgb, specMapSRGB );
|
||||
|
||||
//float glossiness = clamp( 1.0 - specMapSRGB.r, 0.0, 0.98 );
|
||||
float glossiness = clamp( pow( Y, 1.0 / 2.0 ), 0.0, 0.98 );
|
||||
|
||||
float roughness = 1.0 - glossiness;
|
||||
|
||||
return roughness;
|
||||
}
|
||||
|
||||
// Environment BRDF approximations
|
||||
// see s2013_pbs_black_ops_2_notes.pdf
|
||||
/*
|
||||
half a1vf( half g )
|
||||
{
|
||||
return ( 0.25 * g + 0.75 );
|
||||
|
@ -142,8 +155,8 @@ half3 EnvironmentBRDFApprox( half roughness, half vdotN, half3 specularColor )
|
|||
half2 AB = half2( -1.04, 1.04 ) * a004 + r.zw;
|
||||
|
||||
return specularColor * AB.x + AB.y;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -119,13 +119,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
float3 kD = ( float3( 1.0, 1.0, 1.0 ) - kS ) * ( 1.0 - metallic );
|
||||
|
||||
#else
|
||||
// HACK calculate roughness from D3 gloss maps
|
||||
float Y = dot( LUMINANCE_SRGB.rgb, specMapSRGB.rgb );
|
||||
|
||||
//const float glossiness = clamp( 1.0 - specMapSRGB.r, 0.0, 0.98 );
|
||||
const float glossiness = clamp( pow( Y, 1.0 / 2.0 ), 0.0, 0.98 );
|
||||
|
||||
const float roughness = 1.0 - glossiness;
|
||||
const float roughness = EstimateLegacyRoughness( specMapSRGB.rgb );
|
||||
|
||||
half3 diffuseColor = diffuseMap;
|
||||
half3 specularColor = specMap.rgb;
|
||||
|
|
|
@ -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-2020 Robert Beckebans
|
||||
Copyright (C) 2013-2021 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -117,13 +117,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
half3 diffuseColor = baseColor * ( 1.0 - metallic );
|
||||
half3 specularColor = lerp( dielectricColor, baseColor, metallic );
|
||||
#else
|
||||
// HACK calculate roughness from D3 gloss maps
|
||||
float Y = dot( LUMINANCE_SRGB.rgb, specMapSRGB.rgb );
|
||||
|
||||
//const float glossiness = clamp( 1.0 - specMapSRGB.r, 0.0, 0.98 );
|
||||
const float glossiness = clamp( pow( Y, 1.0 / 2.0 ), 0.0, 0.98 );
|
||||
|
||||
const float roughness = 1.0 - glossiness;
|
||||
const float roughness = EstimateLegacyRoughness( specMapSRGB.rgb );
|
||||
|
||||
half3 diffuseColor = diffuseMap;
|
||||
half3 specularColor = specMapSRGB.rgb; // RB: should be linear but it looks too flat
|
||||
|
@ -134,7 +128,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
//lambert *= 1.3;
|
||||
|
||||
// rpDiffuseModifier contains light color multiplier
|
||||
half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );// * rpDiffuseModifier.xyz;
|
||||
half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );
|
||||
|
||||
half vdotN = clamp( dot3( viewVector, localNormal ), 0.0, 1.0 );
|
||||
half vdotH = clamp( dot3( viewVector, halfAngleVector ), 0.0, 1.0 );
|
||||
|
@ -153,8 +147,8 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
// disney GGX
|
||||
float D = ( hdotN * hdotN ) * ( rrrr - 1.0 ) + 1.0;
|
||||
float VFapprox = ( ldotH * ldotH ) * ( roughness + 0.5 );
|
||||
half3 specularBRDF = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;
|
||||
//specularBRDF = half3( 0.0 );
|
||||
half3 specularLight = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;
|
||||
//specularLight = half3( 0.0 );
|
||||
|
||||
#if 0
|
||||
result.color = float4( _half3( VFapprox ), 1.0 );
|
||||
|
@ -165,8 +159,10 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
//lambert /= PI;
|
||||
|
||||
//half3 diffuseColor = mix( diffuseMap, F0, metal ) * rpDiffuseModifier.xyz;
|
||||
half3 diffuseBRDF = diffuseColor * lambert * ( rpDiffuseModifier.xyz );
|
||||
half3 diffuseLight = diffuseColor * lambert * ( rpDiffuseModifier.xyz );
|
||||
|
||||
result.color.xyz = ( diffuseBRDF + specularBRDF ) * lightColor * fragment.color.rgb;
|
||||
result.color.w = 1.0;
|
||||
float3 color = ( diffuseLight + specularLight ) * lightColor * fragment.color.rgb;
|
||||
|
||||
result.color.rgb = color;
|
||||
result.color.a = 1.0;
|
||||
}
|
||||
|
|
|
@ -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-2020 Robert Beckebans
|
||||
Copyright (C) 2013-2021 Robert Beckebans
|
||||
Copyright (C) 2020 Panos Karabelas
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
@ -29,7 +29,6 @@ If you have questions concerning this license or the applicable additional terms
|
|||
*/
|
||||
|
||||
#include "renderprogs/global.inc.hlsl"
|
||||
|
||||
#include "renderprogs/BRDF.inc.hlsl"
|
||||
|
||||
|
||||
|
@ -408,19 +407,12 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
half3 diffuseColor = baseColor * ( 1.0 - metallic );
|
||||
half3 specularColor = lerp( dielectricColor, baseColor, metallic );
|
||||
#else
|
||||
// HACK calculate roughness from D3 gloss maps
|
||||
float Y = dot( LUMINANCE_SRGB.rgb, specMapSRGB.rgb );
|
||||
|
||||
//const float glossiness = clamp( 1.0 - specMapSRGB.r, 0.0, 0.98 );
|
||||
const float glossiness = clamp( pow( Y, 1.0 / 2.0 ), 0.0, 0.98 );
|
||||
|
||||
const float roughness = 1.0 - glossiness;
|
||||
const float roughness = EstimateLegacyRoughness( specMapSRGB.rgb );
|
||||
|
||||
half3 diffuseColor = diffuseMap;
|
||||
half3 specularColor = specMapSRGB.rgb; // RB: should be linear but it looks too flat
|
||||
#endif
|
||||
|
||||
//diffuseColor = half3( 1.0 );
|
||||
|
||||
// RB: compensate r_lightScale 3 and the division of Pi
|
||||
//lambert *= 1.3;
|
||||
|
@ -428,19 +420,6 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
// rpDiffuseModifier contains light color multiplier
|
||||
half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );
|
||||
|
||||
//lightFalloff.xyz = ditherRGB( lightFalloff.xyz, fragment.texcoord2.xy );
|
||||
//lightProj.xyz = ditherRGB( lightProj.xyz, fragment.texcoord3.xy );
|
||||
|
||||
//half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );
|
||||
|
||||
//lightColor = ditherChromaticBlueNoise( lightColor, fragment.position.xy, samp6 );
|
||||
|
||||
//lightColor *= sRGBToLinearRGB( lightFalloff.xyz );// * rpDiffuseModifier.xyz;
|
||||
//lightColor = ditherRGB( lightColor, fragment.position.xy );
|
||||
|
||||
|
||||
//lightColor = ditherRGB( lightColor, fragment.position.xy * rpWindowCoord.xy );
|
||||
|
||||
half vdotN = clamp( dot3( viewVector, localNormal ), 0.0, 1.0 );
|
||||
half vdotH = clamp( dot3( viewVector, halfAngleVector ), 0.0, 1.0 );
|
||||
half ldotH = clamp( dot3( lightVector, halfAngleVector ), 0.0, 1.0 );
|
||||
|
@ -458,8 +437,8 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
// disney GGX
|
||||
float D = ( hdotN * hdotN ) * ( rrrr - 1.0 ) + 1.0;
|
||||
float VFapprox = ( ldotH * ldotH ) * ( roughness + 0.5 );
|
||||
half3 specularBRDF = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;
|
||||
//specularBRDF = half3( 0.0 );
|
||||
half3 specularLight = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;
|
||||
//specularLight = half3( 0.0 );
|
||||
|
||||
#if 0
|
||||
result.color = float4( _half3( VFapprox ), 1.0 );
|
||||
|
@ -470,11 +449,9 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
//lambert /= PI;
|
||||
|
||||
//half3 diffuseColor = mix( diffuseMap, F0, metal ) * rpDiffuseModifier.xyz;
|
||||
half3 diffuseBRDF = diffuseColor * lambert * ( rpDiffuseModifier.xyz );
|
||||
half3 diffuseLight = diffuseColor * lambert * ( rpDiffuseModifier.xyz );
|
||||
|
||||
float3 color = ( diffuseBRDF + specularBRDF ) * lightColor * fragment.color.rgb * shadow;
|
||||
|
||||
//color = ditherChromaticBlueNoise( color, fragment.position.xy, samp6 );
|
||||
float3 color = ( diffuseLight + specularLight ) * lightColor * fragment.color.rgb * shadow;
|
||||
|
||||
result.color.rgb = color;
|
||||
result.color.a = 1.0;
|
||||
|
|
|
@ -2020,7 +2020,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"===========================================================================\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition GPL Source Code\n"
|
||||
"Copyright (C) 2014-2021 Robert Beckebans\n"
|
||||
"Copyright (C) 2014-2020 Robert Beckebans\n"
|
||||
"\n"
|
||||
"This file is part of the Doom 3 BFG Edition GPL Source Code (\"Doom 3 BFG Edition Source Code\").\n"
|
||||
"\n"
|
||||
|
@ -2072,7 +2072,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"}\n"
|
||||
"\n"
|
||||
"// Fresnel term F( v, h )\n"
|
||||
"// Fnone( v, h ) = F(0<EFBFBD>) = specularColor\n"
|
||||
"// Fnone( v, h ) = F(0°) = specularColor\n"
|
||||
"half3 Fresnel_Schlick( half3 specularColor, half vDotN )\n"
|
||||
"{\n"
|
||||
" return specularColor + ( 1.0 - specularColor ) * pow( 1.0 - vDotN, 5.0 );\n"
|
||||
|
@ -4891,7 +4891,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
"Doom 3 BFG Edition GPL Source Code\n"
|
||||
"Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.\n"
|
||||
"Copyright (C) 2013-2020 Robert Beckebans\n"
|
||||
"Copyright (C) 2013-2021 Robert Beckebans\n"
|
||||
"\n"
|
||||
"This file is part of the Doom 3 BFG Edition GPL Source Code (\"Doom 3 BFG Edition Source Code\").\n"
|
||||
"\n"
|
||||
|
@ -5016,7 +5016,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" //lambert *= 1.3;\n"
|
||||
"\n"
|
||||
" // rpDiffuseModifier contains light color multiplier\n"
|
||||
" half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );// * rpDiffuseModifier.xyz;\n"
|
||||
" half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );\n"
|
||||
"\n"
|
||||
" half vdotN = clamp( dot3( viewVector, localNormal ), 0.0, 1.0 );\n"
|
||||
" half vdotH = clamp( dot3( viewVector, halfAngleVector ), 0.0, 1.0 );\n"
|
||||
|
@ -5035,8 +5035,8 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" // disney GGX\n"
|
||||
" float D = ( hdotN * hdotN ) * ( rrrr - 1.0 ) + 1.0;\n"
|
||||
" float VFapprox = ( ldotH * ldotH ) * ( roughness + 0.5 );\n"
|
||||
" half3 specularBRDF = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;\n"
|
||||
" //specularBRDF = half3( 0.0 );\n"
|
||||
" half3 specularLight = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;\n"
|
||||
" //specularLight = half3( 0.0 );\n"
|
||||
"\n"
|
||||
"#if 0\n"
|
||||
" result.color = float4( _half3( VFapprox ), 1.0 );\n"
|
||||
|
@ -5047,10 +5047,12 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" //lambert /= PI;\n"
|
||||
"\n"
|
||||
" //half3 diffuseColor = mix( diffuseMap, F0, metal ) * rpDiffuseModifier.xyz;\n"
|
||||
" half3 diffuseBRDF = diffuseColor * lambert * ( rpDiffuseModifier.xyz );\n"
|
||||
" half3 diffuseLight = diffuseColor * lambert * ( rpDiffuseModifier.xyz );\n"
|
||||
"\n"
|
||||
" result.color.xyz = ( diffuseBRDF + specularBRDF ) * lightColor * fragment.color.rgb;\n"
|
||||
" result.color.w = 1.0;\n"
|
||||
" float3 color = ( diffuseLight + specularLight ) * lightColor * fragment.color.rgb;\n"
|
||||
"\n"
|
||||
" result.color.rgb = color;\n"
|
||||
" result.color.a = 1.0;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
||||
|
@ -5790,7 +5792,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
"Doom 3 BFG Edition GPL Source Code\n"
|
||||
"Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.\n"
|
||||
"Copyright (C) 2013-2020 Robert Beckebans\n"
|
||||
"Copyright (C) 2013-2021 Robert Beckebans\n"
|
||||
"Copyright (C) 2020 Panos Karabelas\n"
|
||||
"\n"
|
||||
"This file is part of the Doom 3 BFG Edition GPL Source Code (\"Doom 3 BFG Edition Source Code\").\n"
|
||||
|
@ -5816,7 +5818,6 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"*/\n"
|
||||
"\n"
|
||||
"#include \"renderprogs/global.inc.hlsl\"\n"
|
||||
"\n"
|
||||
"#include \"renderprogs/BRDF.inc.hlsl\"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
|
@ -6201,7 +6202,6 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" half3 specularColor = specMapSRGB.rgb; // RB: should be linear but it looks too flat\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" //diffuseColor = half3( 1.0 );\n"
|
||||
"\n"
|
||||
" // RB: compensate r_lightScale 3 and the division of Pi\n"
|
||||
" //lambert *= 1.3;\n"
|
||||
|
@ -6209,19 +6209,6 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" // rpDiffuseModifier contains light color multiplier\n"
|
||||
" half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );\n"
|
||||
"\n"
|
||||
" //lightFalloff.xyz = ditherRGB( lightFalloff.xyz, fragment.texcoord2.xy );\n"
|
||||
" //lightProj.xyz = ditherRGB( lightProj.xyz, fragment.texcoord3.xy );\n"
|
||||
"\n"
|
||||
" //half3 lightColor = sRGBToLinearRGB( lightProj.xyz * lightFalloff.xyz );\n"
|
||||
"\n"
|
||||
" //lightColor = ditherChromaticBlueNoise( lightColor, fragment.position.xy, samp6 );\n"
|
||||
"\n"
|
||||
" //lightColor *= sRGBToLinearRGB( lightFalloff.xyz );// * rpDiffuseModifier.xyz;\n"
|
||||
" //lightColor = ditherRGB( lightColor, fragment.position.xy );\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" //lightColor = ditherRGB( lightColor, fragment.position.xy * rpWindowCoord.xy );\n"
|
||||
"\n"
|
||||
" half vdotN = clamp( dot3( viewVector, localNormal ), 0.0, 1.0 );\n"
|
||||
" half vdotH = clamp( dot3( viewVector, halfAngleVector ), 0.0, 1.0 );\n"
|
||||
" half ldotH = clamp( dot3( lightVector, halfAngleVector ), 0.0, 1.0 );\n"
|
||||
|
@ -6239,8 +6226,8 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" // disney GGX\n"
|
||||
" float D = ( hdotN * hdotN ) * ( rrrr - 1.0 ) + 1.0;\n"
|
||||
" float VFapprox = ( ldotH * ldotH ) * ( roughness + 0.5 );\n"
|
||||
" half3 specularBRDF = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;\n"
|
||||
" //specularBRDF = half3( 0.0 );\n"
|
||||
" half3 specularLight = ( rrrr / ( 4.0 * PI * D * D * VFapprox ) ) * ldotN * reflectColor;\n"
|
||||
" //specularLight = half3( 0.0 );\n"
|
||||
"\n"
|
||||
"#if 0\n"
|
||||
" result.color = float4( _half3( VFapprox ), 1.0 );\n"
|
||||
|
@ -6251,11 +6238,9 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" //lambert /= PI;\n"
|
||||
"\n"
|
||||
" //half3 diffuseColor = mix( diffuseMap, F0, metal ) * rpDiffuseModifier.xyz;\n"
|
||||
" half3 diffuseBRDF = diffuseColor * lambert * ( rpDiffuseModifier.xyz );\n"
|
||||
" half3 diffuseLight = diffuseColor * lambert * ( rpDiffuseModifier.xyz );\n"
|
||||
"\n"
|
||||
" float3 color = ( diffuseBRDF + specularBRDF ) * lightColor * fragment.color.rgb * shadow;\n"
|
||||
"\n"
|
||||
" //color = ditherChromaticBlueNoise( color, fragment.position.xy, samp6 );\n"
|
||||
" float3 color = ( diffuseLight + specularLight ) * lightColor * fragment.color.rgb * shadow;\n"
|
||||
"\n"
|
||||
" result.color.rgb = color;\n"
|
||||
" result.color.a = 1.0;\n"
|
||||
|
|
Loading…
Reference in a new issue