3 – Raymarching: Floor + Sphere

The obj_union() function will be used with all other primitives to combine the floor and a primitive. This function can be seen as the depth test.

Now the function to generate a sphere. This function returns the distance between a position p and a sphere with a radius of 1.9. The vec2 used to return the result holds the distance in x and the material index in y. If material == 0, we have the floor. If material == 1 we have a primitive.