Fog should be calculated in the user's world coordinates

Fixes #6798
This commit is contained in:
Mathias Agopian
2023-05-12 16:06:54 -07:00
committed by Mathias Agopian
parent cfe1abec08
commit d40712937d
2 changed files with 8 additions and 1 deletions

View File

@@ -62,7 +62,7 @@ vec4 fog(vec4 color, highp vec3 view) {
// Add sun colored fog when looking towards the sun
vec3 sunColor = frameUniforms.lightColorIntensity.rgb * frameUniforms.lightColorIntensity.w;
float sunAmount = max(dot(-shading_view, frameUniforms.lightDirection), 0.0); // between 0 and 1
float sunAmount = max(dot(normalize(view), frameUniforms.lightDirection), 0.0); // between 0 and 1
float sunInscattering = pow(sunAmount, frameUniforms.fogInscatteringSize);
fogColor += sunColor * (sunInscattering * (1.0 - sunTransmittance));

View File

@@ -44,6 +44,13 @@ void main() {
#if defined(VARIANT_HAS_FOG)
highp vec3 view = getWorldPosition() - getWorldCameraPosition();
// fog should be calculated in the "user's world coordinates" so that it's not
// affected by the IBL rotation. We're transofrming a vector, so we should use the
// cofactor (or inverse-transpose), but since we know this matrix is a rigid transform,
// we can use it as is.
view = mulMat3x3Float3(frameUniforms.userWorldFromWorldMatrix, view);
fragColor = fog(fragColor, view);
#endif