Building Worlds With Distance Functions in GLSL (Raymarching)



Article index:


8 – Raymarching: Primitive Blending

Build Worlds With Distance Functions in GLSL, GLSL Hacker
Raymarching: rounded box and torus blended

The blending is performed by the op_blend() function:

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

vec2 obj_round_box(vec3 p)
{
  float d= length(max(abs(p)-vec3(1.0,0.5,2.0),0.0))-0.08;
  return vec2(d,1);
}

vec2 op_blend(vec3 p, vec2 a, vec2 b)
{
 float s = smoothstep(length(p), 0.0, 1.0);
 float d = mix(a.x, b.x, s);
 return vec2(d,1);
}

And the distance_to_obj() function:

vec2 distance_to_obj(in vec3 p)
{
  return obj_union(obj_floor(p), op_blend(p, obj_round_box(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