mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
brdf handling corrections
1-handle the brdfTexture in linear space, not srgb. 2-clamp surface.NoV across the board for consistency. (solves several new and ongoing artifacts)
This commit is contained in:
parent
e0e3ebc69d
commit
b60d51969e
5 changed files with 8 additions and 11 deletions
|
|
@ -290,7 +290,7 @@ bool RenderProbeMgr::onAdd()
|
||||||
}
|
}
|
||||||
|
|
||||||
String brdfTexturePath = GFXTextureManager::getBRDFTexturePath();
|
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");
|
Con::errorf("RenderProbeMgr::onAdd: Failed to load BRDF Texture");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ struct Surface
|
||||||
|
|
||||||
void updateSurface(inout Surface 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.linearRoughness = surface.roughness * surface.roughness;
|
||||||
surface.linearRoughnessSq = surface.linearRoughness * surface.linearRoughness;
|
surface.linearRoughnessSq = surface.linearRoughness * surface.linearRoughness;
|
||||||
|
|
|
||||||
|
|
@ -105,10 +105,9 @@ struct Surface
|
||||||
|
|
||||||
inline void Update()
|
inline void Update()
|
||||||
{
|
{
|
||||||
NdotV = abs(dot(N, V)) + 1e-5f; // avoid artifact
|
NdotV = clamp( dot(N, V), 0.0009765625f,0.9990234375f); // avoid artifact
|
||||||
|
linearRoughness = roughness * roughness;
|
||||||
linearRoughness = roughness * roughness;
|
linearRoughnessSq = linearRoughness * linearRoughness;
|
||||||
linearRoughnessSq = linearRoughness * linearRoughness;
|
|
||||||
|
|
||||||
albedo = baseColor.rgb * (1.0f - metalness);
|
albedo = baseColor.rgb * (1.0f - metalness);
|
||||||
f0 = lerp(0.04f, baseColor.rgb, metalness);
|
f0 = lerp(0.04f, baseColor.rgb, metalness);
|
||||||
|
|
|
||||||
|
|
@ -202,14 +202,13 @@ void main()
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//energy conservation
|
//energy conservation
|
||||||
vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
vec3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
||||||
vec3 kD = 1.0f - F;
|
vec3 kD = 1.0f - F;
|
||||||
kD *= 1.0f - surface.metalness;
|
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(surface.NdotV, surface.roughness),0).rg;
|
||||||
vec2 envBRDF = textureLod(BRDFTexture, vec2(dfgNdotV, surface.roughness),0).rg;
|
|
||||||
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
|
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
|
||||||
irradiance *= kD * surface.baseColor.rgb;
|
irradiance *= kD * surface.baseColor.rgb;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,8 +197,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
||||||
float3 kD = 1.0f - F;
|
float3 kD = 1.0f - F;
|
||||||
kD *= 1.0f - surface.metalness;
|
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(surface.NdotV, surface.roughness,0,0)).rg;
|
||||||
float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(dfgNdotV, surface.roughness,0,0)).rg;
|
|
||||||
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
|
specular *= F * envBRDF.x + surface.f90 * envBRDF.y;
|
||||||
irradiance *= kD * surface.baseColor.rgb;
|
irradiance *= kD * surface.baseColor.rgb;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue