Merge pull request #671 from Azaezel/alpha40/brdfFixes

brdf handling corrections
This commit is contained in:
Brian Roberts 2021-11-14 13:46:47 -06:00 committed by GitHub
commit 4f04213cd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 15 deletions

View file

@ -290,7 +290,7 @@ bool RenderProbeMgr::onAdd()
}
String brdfTexturePath = GFXTextureManager::getBRDFTexturePath();
if (!mBRDFTexture.set(brdfTexturePath, &GFXTexturePersistentSRGBProfile, "BRDFTexture"))
if (!mBRDFTexture.set(brdfTexturePath, &GFXTexturePersistentProfile, "BRDFTexture"))
{
Con::errorf("RenderProbeMgr::onAdd: Failed to load BRDF Texture");
return false;

View file

@ -106,7 +106,7 @@ struct Surface
void updateSurface(inout Surface surface)
{
surface.NdotV = abs(dot(surface.N, surface.V)) + 1e-5f; // avoid artifact
surface.NdotV = clamp( dot(surface.N, surface.V), 0.0009765625f,0.9990234375f); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
surface.linearRoughness = surface.roughness * surface.roughness;
surface.linearRoughnessSq = surface.linearRoughness * surface.linearRoughness;
@ -650,8 +650,7 @@ vec4 debugVizForwardProbes(Surface surface,
vec3 kD = 1.0f - F;
kD *= 1.0f - surface.metalness;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg;
vec2 envBRDF = textureLod(BRDFTexture, vec2(surface.NdotV, surface.roughness),0).rg;
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;

View file

@ -105,10 +105,9 @@ struct Surface
inline void Update()
{
NdotV = abs(dot(N, V)) + 1e-5f; // avoid artifact
linearRoughness = roughness * roughness;
linearRoughnessSq = linearRoughness * linearRoughness;
NdotV = clamp( dot(N, V), 0.0009765625f,0.9990234375f); // avoid artifact
linearRoughness = roughness * roughness;
linearRoughnessSq = linearRoughness * linearRoughness;
albedo = baseColor.rgb * (1.0f - metalness);
f0 = lerp(0.04f, baseColor.rgb, metalness);
@ -654,8 +653,7 @@ float4 debugVizForwardProbes(Surface surface,
float3 kD = 1.0f - F;
kD *= 1.0f - surface.metalness;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg;
float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.NdotV, surface.roughness,0,0)).rg;
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;

View file

@ -202,14 +202,13 @@ void main()
return;
#endif
//energy conservation
vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
vec3 kD = 1.0f - F;
kD *= 1.0f - surface.metalness;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg;
vec2 envBRDF = textureLod(BRDFTexture, vec2(surface.NdotV, surface.roughness),0).rg;
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;

View file

@ -197,8 +197,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
float3 kD = 1.0f - F;
kD *= 1.0f - surface.metalness;
float dfgNdotV = max( surface.NdotV , 0.0009765625f ); //0.5f/512.0f (512 is size of dfg/brdf lookup tex)
float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg;
float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.NdotV, surface.roughness,0,0)).rg;
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
irradiance *= kD * surface.baseColor.rgb;