Distance fields and other curiosities

Does anyone have any recommendations for learning materials and examples to learn more about and start using, distance fields, raymarching etc in vvvv?

I need to start at a fairly basic level…

Things I’m looking at -

(I’m particularly interested in working with volumetric data, and generating procedural geometry)

hey mrboni i tried to implement the gpugems3
the funny thing is that is kind of old (but nevertheless amazing)
but therefore he uses a lot of fragmentshader that I was not able to puzzle together correctly.
Even if it is HSLS there is a lot of semantics that I didnt encounter before in my vvvv HLSL learnings.
Also I had some problems reading the c++ program code that uses all the fragment shaders.

But the theory is clear and refreshing :)

start with 2d
girlpower( distance field )

Here is a basic rig that works with camera, should at least get started.

There’s enough sphere tracers example in shadertoy, so I didn’t included any distance functions except from sphere.

What other thing you want to do with volumes? , there’s heap loads of possibilities, it really opens up a brand new world ;)

Doing marching cubes (basic version) in dx11 is super simple (with append buffers + one compute shader).

spheretrace.zip (3.9 kB)

@tekcor - ah balls, didn’t realise it was GLSL. Just noticed it was made in 2007! Fair play. The thing that really interests me in it is generating complex mesh data with fairly simple density functions

@Joreg - great!

@Vux - Amazing. A really useful start. A few things -

  • What is being accumulated in the ‘iter’ for loop? I can imagine many rays are being cast, but why are there so many rays for each pixel, and what is the difference between them?

  • What is actually being returned as the colour §? It seems to relate to the distance and also the angle from view

  • How is the following line creating an array of spheres?
    float3 np = abs§ % spacing - (spacing * 0.5f)

Thanks guys

(edit) - I get how in the for loop we are moving the ray forward in steps along the raydir vector, but I’m not sure how the result of the distance function is relating to this)

@Vux, I’m primarily interested in being able to procedurally generate animated volume fields that relate to sound input, and visualise those and many ways including as geometry, or particle emitters/forces

in iter you calculate the position of the closest object.
By having this minimal distance you assume you can safely advance your ray from this distance (this is not always true). When distance is under a certain value you assume that you “hit” the object.

As color I just return iteration count, it useful for some other aspects but if you want to color and shade you need to compute normals at intersection point (there’s heap load of doc about it), it’s more or less a gradient function.

Once you have normals you can shade with any light equation you want.

Using abs and % is a domain repetition function. Not too simple to explain, but basically you convolute your ray to fit in a smaller domain. For a lot of useful functions (bend/twist/transform), you generally modify your ray a instead of your object itself.

Thanks!

I must say I’m having more fun with this than I have in vvvv for ages. That patch was the perfect starting point.

Do you have an example of marching cubes that I might be able to use with this technique?

W