Skip to content

Commit

Permalink
fix sampling direction of fog color from IBL
Browse files Browse the repository at this point in the history
When sampling the fog color from the IBL we need to take into account
the IBL transform. This broke recently when the for calculation was
moved in user world coordinates.
  • Loading branch information
pixelflinger committed May 23, 2023
1 parent faafb14 commit fda62e0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion shaders/src/fog.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ vec4 fog(vec4 color, highp vec3 view) {
// get fog color from envmap
// TODO: use a lower resolution mip as we get further (problem we don't have mips!)
float lod = frameUniforms.iblRoughnessOneLevel;
fogColor *= textureLod(light_iblSpecular, view, lod).rgb;

// when sampling the IBL we need to take into account the IBL transform. We know it's a
// a rigid transform, so we can take the transpose instead of the inverse, and for the
// same reason we can use it directly instead of taking the cof() to transfrom a vector.
highp mat3 worldFromUserWorldMatrix = transpose(mat3(frameUniforms.userWorldFromWorldMatrix));
fogColor *= textureLod(light_iblSpecular, worldFromUserWorldMatrix * view, lod).rgb;
}
#endif

Expand Down

0 comments on commit fda62e0

Please sign in to comment.