Skip to content

Commit 1ee8c98

Browse files
authored
Fix negative distance resulting in infinite attenuation due to almost horizontal intersections with clouds. (#1862)
Fixes #1664
1 parent f03c94d commit 1ee8c98

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • chunky/src/java/se/llbit/chunky/renderer/scene/sky

chunky/src/java/se/llbit/chunky/renderer/scene/sky/Sky.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,10 @@ public boolean cloudIntersection(Scene scene, Ray ray) {
989989
int target = 1;
990990
double t_offset = 0;
991991
if (oy < offsetY || oy > cloudTop) {
992+
if (Math.abs(ray.d.y) < Ray.EPSILON) {
993+
// ignore almost horizontal intersections that result in huge t_offset and negative t (issue #1664)
994+
return false;
995+
}
992996
if (ray.d.y > 0) {
993997
t_offset = (offsetY - oy) / ray.d.y;
994998
} else {
@@ -1126,7 +1130,9 @@ public boolean cloudIntersection(Scene scene, Ray ray) {
11261130
return false;
11271131
}
11281132
ray.setNormal(nx, ny, nz);
1129-
enterCloud(ray, t + t_offset);
1133+
t += t_offset;
1134+
assert t >= 0 : "t negative, t_offset=" + t_offset;
1135+
enterCloud(ray, t);
11301136
return true;
11311137
} else {
11321138
if (t > tExit) {

0 commit comments

Comments
 (0)