Fixed NaN with specular on transparent objects

This commit is contained in:
Olivier Prat 2018-07-02 12:20:55 +02:00
parent bbc757a193
commit d2a612580c
4 changed files with 9 additions and 6 deletions

View file

@ -198,7 +198,7 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse;
color += (ambientSpecular + directionalSpecular) / opacity;
color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity);
return color;
}
@ -231,7 +231,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse;
color += (ambientSpecular + directionalSpecular) / opacity;
color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity);
// Haze
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
@ -269,7 +269,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation);
color += ambientDiffuse + directionalDiffuse;
color += (ambientSpecular + directionalSpecular) / opacity;
color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity);
// Haze
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {

View file

@ -197,7 +197,7 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse;
color += (ambientSpecular + directionalSpecular) / opacity;
color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity);
return color;
}
@ -223,7 +223,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse;
color += (ambientSpecular + directionalSpecular) / opacity;
color += evalSpecularWithOpacity(ambientSpecular + directionalSpecular, opacity);
// Haze
// FIXME - temporarily removed until we support it for forward...

View file

@ -143,6 +143,6 @@ vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, SurfaceD
fragSpecular *= isSpecularEnabled();
fragColor.rgb += fragDiffuse;
fragColor.rgb += fragSpecular / opacity;
fragColor.rgb += evalSpecularWithOpacity(fragSpecular, opacity);
return fragColor;
}

View file

@ -314,6 +314,9 @@ void evalFragShadingGloss(out vec3 diffuse, out vec3 specular,
specular = shading.xyz;
}
vec3 evalSpecularWithOpacity(vec3 specular, float opacity) {
return specular / max(opacity, 1e-6);
}
<@if not GETFRESNEL0@>
<@def GETFRESNEL0@>