From 12315d2791b1b483034ef43a4b0b6241daa28fbe Mon Sep 17 00:00:00 2001 From: Amy Retzerau Date: Thu, 4 Sep 2025 12:50:36 +0200 Subject: [PATCH] fix: changes inf ray behaviour for better sky rendering --- sdf.glsl | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sdf.glsl b/sdf.glsl index e73a76b..9dea62e 100644 --- a/sdf.glsl +++ b/sdf.glsl @@ -28,7 +28,7 @@ struct Ray { }; Ray createRay(vec3 dir, vec3 pos){ - return Ray(dir, pos, .0, .0, SmallHit(80.,0.,false), vec3(.0)); + return Ray(dir, pos, .0, .0, SmallHit(80.,0.,false), vec3(1.0)); } Ray applyMin(Ray ray, float min) { @@ -52,11 +52,11 @@ Ray applyMin(Ray ray, float min) { float planeMin(vec3 pos){ - return pos.y - planeHeight; + return pos.y - planeHeight+ 0.2*sin(5*pos.x+t)*sin(5*pos.y+t)*sin(5*pos.z+t); } float sphereMin(vec3 pos){ - return length(pos - center) - radius + 0.2*sin(5*pos.x+t)*sin(5*pos.y+t)*sin(5*pos.z+t); + return length(pos - center) - radius; } Ray minFn(Ray ray){ @@ -88,11 +88,13 @@ Ray march(Ray ray){ //ray.min = minFn(ray.pos); ray = minFn(ray); int c = 0; - while(( c < 200) && (ray.min < 100.0f) && (ray.min > 0.01f) ) { + while(( c < 1000) && (ray.min < 100.0f) && (ray.min > 0.01f) ) { ray = minFn(ray); c++; } - + if(ray.min > 0.01){ + ray.color = vec3(1.0); + } return ray; } @@ -142,11 +144,14 @@ void main() light *= shLeve; + Ray reflectR = createRay(reflect(ray.dir,normal),ray.pos + 0.1* normal); + reflectR = march(reflectR); + if(ray.min <= 0.2){ - //FragColor = vec4(vec3(shRay.small.min)*0.1,1.0); - FragColor = vec4(ray.color * (light+0.3), 1.0); + //FragColor = vec4(0,1,0,1.0); + FragColor = vec4(mix(ray.color,reflectR.color,0.3) * (light+0.3), 1.0); } else { - FragColor = vec4(.0,0.0,0.0,1.0); + FragColor = vec4(ray.color,1.0); } }