File tree Expand file tree Collapse file tree
chunky/src/java/se/llbit/chunky/renderer/scene/sky Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments