Raymarching SDF artefacts

hi guys,

I’m quite new to the glsl world (actually in programing general :slight_smile: ) :confused:
I try to figure out why there are those artefacts in my glsl programming, and i am pretty sure it’s because of my cells are incorrect?! the rotation in it or maybe cause of the sine on y coordinate?

heres is part of the code i use:

float sdBox(vec3 p, vec3 b){
vec3 q = abs(p) - b;
return max(q.x, max(q.y, q.z));
}
void pR(inout vec2 p, float a) {
p = cos(a) * p + sin(a) * vec2(p.y, -p.x);
}
float sceneSDF(vec3 p)
{
vec3 p1 = p;
p1.z += 0.5;
float sizeB1 = 1.0;
vec3 c = floor((p1 + sizeB1*0.5)/sizeB1);
vec3 l = vec3(5.);
p1.y += cos(c.x + uTime)*0.5+0.5;   // noise(c.xyx)  + sin(c.x * .5) + sin(c.y * .5 + uTime) *2.0 -1.0;
p1.xz = p1.xz-sizeB1*clamp(round(p1.xz/sizeB1),-l.x,l.x);
pR(p1.xy, c.x + uTime - c.z);
pR(p1.yz, c.z + uTime);
float box = sdBox(p1, vec3(0.15));

vec3 p2 = p;
float sizeB2 = 1.0;
vec3 cB2 = floor((p2 + sizeB2*0.5)/sizeB2);
vec3 lB2 = vec3(4.0);
p2.y += sin(cB2.x + uTime*0.7931)*0.7+1.0;   // noise(c.xyx)  + sin(c.x * .5) + sin(c.y * .5 + uTime) *2.0 -1.0;
p2.xz = p2.xz-sizeB2*clamp(round(p2.xz/sizeB2),-lB2.x,lB2.x);

pR(p2.xy, cB2.x + uTime - cB2.z);
pR(p2.yz, cB2.z + uTime);
    
float box1 = sdBox(p2, vec3(0.2));

float boxes = opSmoothUnion (box, box1, 0.3);

return boxes*0.8;
}
.
.
.
float shortestDistanceToSurface(vec3 eye, vec3 marchingDirection, float start, float end) {
    float depth = start;
    for (int i = 0; i < uSteps; i++) {
        float dist = sceneSDF(eye + depth * marchingDirection);
        if (dist < start) {
            return depth;
        }
        depth += dist;
        if (depth >= end) {
            return end;
        }
    }
    return end;
}
.
.
.

Can anyone guide me to the problem? in the picture you see those artefacts :slight_smile:

Thanks,
Stan

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.