Helper module for debugging raytraced SDFs inspired by Johann Korndorfer's "How to Create Content with Signed Distance Functions" talk at NVScene 2015.
trace = require(glsl-ruler/trace, <map>, <steps>)
glsl-ruler needs to handle raytracing on your behalf – it does so using an API very similar to glsl-raytrace. For further details, check out that project's documentation.
vec3 trace(vec3 ro, vec3 rd)
The key difference here between
glsl-raytrace is that instead of returning a
trace will return a
vec3 with the elements corresponding to:
- The signed distance value retrieved from a raytrace of your
mapfunction merged with the ruler plane.
- A second attribute for assigning an ID to surfaces. This will be
-1.0if the ray hit the plane.
- The signed distance value retrieved from a raytrace of only
mapfunction. You can then use this to color the plane.
color = require(glsl-color)
vec3 color(float distance)
Returns an RGB color for the plane based on the
distance value of your signed distance field.
By combining the above two modules together, you can quickly tweak existing glslify-driven raytracers to debug and explore 3D SDFs:
vec2# camera = require('glsl-turntable-camera')# trace = require('glsl-ruler/trace', map = doModel, steps = 90)# color = require('glsl-ruler/color')// creates a unit sphere at the originvec2void
For a full example, see demo.frag.
See stackgl/contributing for details.
MIT. See LICENSE.md for details.