Building Worlds With Distance Functions in GLSL (Raymarching)





Article index:


4 – Raymarching: Floor + Torus

Build Worlds With Distance Functions in GLSL, GLSL Hacker
Raymarching: floor + torus



This time the only new function is the one that generates the torus:

vec2 obj_torus(in vec3 p)
{
  vec2 r = vec2(2.1,0.5);
  vec2 q = vec2(length(p.xz)-r.x,p.y);
  float d = length(q)-r.y;
  return vec2(d,1);
}

The torus has two params: the radius (2.1) and the section radius (0.5).

Like for the sphere, we update the distance_to_obj() function:

vec2 distance_to_obj(in vec3 p)
{
  return obj_union(obj_floor(p), obj_torus(p));
}






Article index:


Pages: 1 2 3 4 5 6 7 8 9





[ Subscribe to Geeks3D latest news by email ]

Geeks3D.com

↑ Grab this Headline Animator