Sphere Tracing Step Size Explained
Fixed steps can skip thin geometry or waste iterations in empty space. Sphere tracing advances by a safe distance to the surface. The sphere field length(p)-r is exact, whereas arbitrarily scaled or distorted fields may stop being conservative distance bounds.
Fix the problem and environment
Fixed steps can skip thin geometry or waste iterations in empty space. Sphere tracing advances by a safe distance to the surface. The sphere field length(p)-r is exact, whereas arbitrarily scaled or distorted fields may stop being conservative distance bounds.
The controlling code
float travel=0.0;
bool hit=false;
for(int i=0;i<80;i++){
float distance=scene(origin+direction*travel);
if(distance<0.002){hit=true;break;}
travel+=max(distance,0.001);
if(travel>12.0)break;
}
vec3 color=hit?shade(origin+direction*travel):background;
Verify in order
Start with the sphere, then the carved solid. Reduce steps and inspect missed hits; increase epsilon and inspect inflated silhouettes. Change one termination condition at a time.
Scope and common mistakes
Exhausting the loop is not a hit. Terminate rays that miss into the distance, and evaluate normals/shadows only after a hit. Complex fractals need their own distance-estimator reasoning.