Skip to content

Commit

Permalink
Fix overflow on bad implementations of tanh()
Browse files Browse the repository at this point in the history
Fixes #3351
  • Loading branch information
10110111 committed Aug 4, 2023
1 parent 2d0e8c7 commit 3555e61
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
4 changes: 3 additions & 1 deletion atmosphere/default/shaders/light-pollution/render.frag
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
4 changes: 3 additions & 1 deletion atmosphere/default/shaders/multiple-scattering/render.frag
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ void main()
// The first factor here, with dot(view,sun), results in removal of the
// forward scattering peak. The second factor, with tanh, makes the
// transition near sunset from a bit above horizon to a bit below smoother.
// We limit the argument of tanh, because some GLSL implementations (e.g.
// AMD Radeon RX 5700 XT) overflow when computing it and yield NaN.
pseudoMirrorDepth = sqr(max(0, dot(viewDir, sunDirection))) *
tanh(150 * (newViewElev - horizElev) / (PI/2 - horizElev));
tanh(min(10, 150 * (newViewElev - horizElev) / (PI/2 - horizElev)));
}

CONST float cosSunZenithAngle =dot(zenith,sunDirection);
Expand Down

0 comments on commit 3555e61

Please sign in to comment.