Article index:
- 1 – Raymarching, Distance functions
- 2 – GLSL framework for Raymarching
- 3 – Raymarching: Floor + Sphere
- 4 – Raymarching: Floor + Torus
- 5 – Raymarching: Floor + Rounded Box
- 6 – Raymarching: Floor + Union of Rounded Box and Sphere
- 7 – Raymarching: Floor + Rounded Box minus Sphere
- 8 – Raymarching: Primitive Blending
- 9 – Raymarching: Primitive Repetition
1 – Raymarching, Distance functions
Some time ago, I found this page: Modeling with distance functions by GLSL wizard iq. This page contains many ready-to-use functions to create primitives in GLSL. Ready-to-use functions… only if you have a pixel shader ready to use them. Actually, all these functions are intended for raymarching with distance fields. Raymarching is ray casting with large steps along the ray and a distance field function returns the minimum distance to any surface in a scene from any point. More details can be found on this iq’s presentation: Rendering Worlds with Two Triangles.
The aim of this article is to provide the basic GLSL framework to use these cool distance functions as well as the use of these functions.
Raymarching is one of the secrets behind those amazing demos.
|
Raymarching DemosI used GLSL Hacker to code and play with raymarching (I coded with version 0.5.0). You will find all ready-to-hack demos in GLSL Hacker Code Sample Pack in the GLSL_Raymarching/ folder. How to run the demos: start GLSL Hacker and load each demo file (*.xml files). That’s all. To tweak raymarching shaders, live coding is an useful tool (see HERE and HERE). |
All the shaders in this article are not linked to GLSL Hacker. You can use them in any application that can load GLSL shaders and of course in WebGL tools like Shadertoy or GLSL Sandbox.
In all GLSL Hacker demos, I set the VSYNC to ON to limit the framerate because NVIDIA drivers do not like some raymarching shaders:
To disable the vertical synchronisation, just replace the following line in INIT scripts:
gh_renderer.set_vsync(1)
by
gh_renderer.set_vsync(0)
Article index:
- 1 – Raymarching, Distance functions
- 2 – GLSL framework for Raymarching
- 3 – Raymarching: Floor + Sphere
- 4 – Raymarching: Floor + Torus
- 5 – Raymarching: Floor + Rounded Box
- 6 – Raymarching: Floor + Union of Rounded Box and Sphere
- 7 – Raymarching: Floor + Rounded Box minus Sphere
- 8 – Raymarching: Primitive Blending
- 9 – Raymarching: Primitive Repetition
Hey. Just found this. Came across iq’s stuff a while ago, but being a noob I couldn’t do anything with it.
Then while rediscovering GLSL & iq’s website, I found this awesome resource!
But here’s the thing, I can’t get it to work. ;o)
I eventually found 2 errors in the code. Here are the fixes:
line 97: d.x-distance_to_obj(p-e.yyx).x); // had an extra “)”
line 98: N = normalize(n); // was missing “;”
I’m trying to use GLSL Hacker 0.6.0.0 & Blender 2.69 using this tutorial:
http://en.wikibooks.org/wiki/GLSL_Programming/Blender/Minimal_Shader
Any help?
peace & 42
I too found the errors but cant get any of this to work. There are too few good examples online, it would be nice to get one working
I’m fixing the errors and I upload the code samples asap!
Code samples have been updated for the latest DEV version (0.6.3.11) and a new demo about menger sponge has been added:
http://www.geeks3d.com/20140201/glsl-menger-sponge-raymarching-code-samples-updated/