pouët.net

Go to bottom

Raymarching Beginners' Thread

category: code [glöplog]
rudi: Raymaching is a method to compute the intersection of a ray and some object defined by an inside-outside function, and is often used in raytracers to compute intersections with iso-surfaces.

Lately, the demoscene has become obsessed with using procedural distance-guided raymarching to raytrace scenes in 4k-intros, both to save space on the object definitions and to easily get shadows, reflections and other typical raytracing-features.

And this is cool as long as there's something novel about it. But I thow up a little bit in my mouth each time I see a trivial low-resolution, low-framerate rubbervector, which is waaay too often these days. I guess it's a bit of the same thing as happened with grid-expanders in the mid/late 90s; everyone did by-the-book FD-tunnels over and over again.
added on the 2011-02-07 11:55:12 by kusma kusma
Traditional voxel landscapes/tunnels/twisters are mostly forward rendering, not raytracing/marching.
added on the 2011-02-07 12:32:49 by Psycho Psycho
Psycho: A classic voxel landscape march 2D rays in a height-map, and splat visible line-segments as they encounter them. So I agree it's not a raytracer, but IMO it IS raymarching :)
added on the 2011-02-07 12:58:52 by kusma kusma
Has anyone tried producing a 3d modeller for distance fields? It would seem to be whats needed for a breakthrough.
added on the 2011-02-07 13:01:03 by auld auld
Quote:
Psycho: A classic voxel landscape march 2D rays in a height-map, and splat visible line-segments as they encounter them. So I agree it's not a raytracer, but IMO it IS raymarching :)


i look at raycasting as some ray that does not trace anything, it just evaluates the point it hits (if it is a heightmap, it evaluates the height). so in voxel landscape (or whatever) the ray discards points along the way if the next point is lower than the previous one. that's how i look at it and how i implemented my voxel landscape several years ago. (of course there's room for different implementations of this, but that's another story). so if kusma says what it is, then i probably know what raymarching is in a sense.
added on the 2011-02-07 16:31:25 by rudi rudi
My maths sucks miserably, but there's something I want to try that would work well with ray marching. So I've started, but right at the beginning:

1. 2d, plot a circle in the shader. No marching, but it helps me get my head round it one step at a time.

2. 3d, plot a sphere. Marching with fixed step size to keep it simple. No lighting, just a straight hit test.

All OK so far, and this way I understand it. Next will have to be perspective, lighting and texture, and then more complex/efficient marching, and more complex geometry (what I want to do just needs a sphere, so this can wait :)

added on the 2011-02-08 10:54:14 by psonice psonice

I'd call this raymarching too (through voxels):

http://www.youtube.com/watch?v=oc3WGeLFnYs
added on the 2011-02-08 12:02:17 by Navis Navis
psonice: go for it! and give us some shots.
added on the 2011-02-08 12:39:49 by vibrator vibrator
Navis, ACK.
added on the 2011-02-08 12:40:33 by las las
vibrator: so far, it's a white circle on a black background. I guess you can imagine that so I'll save the bandwidth ;)

I'll post screenshots when it looks as good as navis' video. Or when I have a lit, textured sphere at least.
added on the 2011-02-08 12:49:26 by psonice psonice
BB Image
added on the 2011-02-08 22:38:08 by las las
^ daaaaaaaaaaaaaaaaamn
added on the 2011-02-09 04:52:22 by gngbng gngbng
Quote:
auld: Has anyone tried producing a 3d modeller for distance fields?


I thought about it and finally decided that it is much more practical to simply write formulas for that :) Of course it would be nice to have some tool allowing to create simlpe shapes and then bend/blend/join/cut those shapes. But resulting formula will be really slow. Also do not forget about possibility to find something interesting if you make mistake in formula ;)
added on the 2011-02-09 09:24:11 by stan_1901 stan_1901
Raymarching through volumes? How does that work, is it a volume of distances based off the data-set?
The screenshot is just fake sss (sss=1-ao(d,p)) gone wild.
added on the 2011-02-09 10:11:37 by las las
I'm also curious about the Distance Fields Modeling tool. Some operators to combine different functions into code but still be able to control and animate the parameters. A lot of codes must have thought about this already.

@chaos: Do you think this would be possible with operator stacking in W4?
added on the 2011-02-09 10:29:34 by pixtur pixtur
Quote:

But resulting formula will be really slow.

That's exactly the main problem with distfield-modelling tools - Even simple scenes will result in a pretty damn slow formula as long you don't do any optimizations (i.e. domain repetition).

Maybe that's why raymarching is so cool for us coders...
Finally we are not just doing the damn tools for the lazy artists again. :D

Imho the best way is to have a simple editor where you just have your RM-shader code, a viewer window, a pause and reload button + some value sliders (maybe GNU Rocket :)).
added on the 2011-02-09 11:06:36 by las las
And if you want to have that in a "more artist usable way" - just teach your artist a minimal set of GLSL/HLSL instructions (mix, min, max, smoothstep, edge, mod, sin, cos...) + maybe integrate something in the editor that the artist can only modify stuff inside functions he's meant to edit. :D

An artist generating distance fields should - in a way - know what he's doing - especially why things go slow.
added on the 2011-02-09 11:12:59 by las las
Another question...
How to do fake soft shadows with RM? :)
From RWWTT - iq
Quote:

Recipe: take n points on the line from the surface to the light and evaluate
the distance to the closest geometry. Find a magic formula to blend the n
distances to obtain a shadow factor.

Currently only hard shadows here... Used all the magic powder up for the sss yesterday.
added on the 2011-02-09 11:17:58 by las las
Making your blending process a function of distance to the closest geometry on the way to the light source would give you a smooth shadow. You can also weight your values with the same method to get some sort of a fake high-dynamic feeling. :)

In essence, the whole trick is to use the same AO code I had posted in a clever way. Instead of sampling back on the normal, you sample back to the light source:

Code: float shadowFactor = 0.; vec3 q = normalize(lightSource - p); for (float i = 0.; i < 5.; ++i) { shadowFactor += vec3(i * k - ƒ(p + q * i * k)) / pow(2., i); }


You can also apply a variety of it just like rrrola and iq mentioned before. Also, as a simple optimisation you can merge this with the AO procedure to avoid having two loops in the fragment shader. :)

Enjoy!
added on the 2011-02-09 11:41:06 by decipher decipher
umm there's some typo in the code. well it's quite pseudo anyway :) you can't implicitly convert from vec3 to float, but since that vec3 there represents a "greyscale colour" you can just remove the 'vec3(' and ')' around it and have your shadow factor as a single float.

sorry I am quite sick and my nose is full, so I can't concentrate well…
added on the 2011-02-09 11:45:09 by decipher decipher
Okay that was to simple ;)
But faking everything with the ao routine... ;)

Come on - there must be another magic formula to blend the n distances!
added on the 2011-02-09 11:53:03 by las las
Thanks + get well soon!
added on the 2011-02-09 11:53:57 by las las
Actually it's not really faking, a shadow is actually the obstruction of a light source's effect on a certain point. :) That's exactly what the formula calculates. It might not be 100% scientifically correct, however it's very close to the mathematical implementation of the actual definition of a shadow. :)

And you're welcome. :)
added on the 2011-02-09 12:00:14 by decipher decipher
pixtur: I'm not exactly Chaos but I know the Wz4 well enough that I can say: Yes, perfectly. Somebody just has to code it :D
added on the 2011-02-09 12:07:23 by kb_ kb_

login

Go to top