pouët.net

Raymarching Tutorial

category: code [glöplog]
he just did...
added on the 2011-07-04 15:08:44 by doomdoom doomdoom
BB Image

SH-SH-SHAAAAAAAAA!!1
added on the 2011-07-04 19:51:10 by superplek superplek
T21:

* <A,B> is the dot (inner) product of A and B. <A,B> = dot(A,B) = A·B The dot product
* |A| is the length of A, such that |A|² = <A,A>.

You can use the regular linear, distributive and commutative rules to expand dot products (and squared lengths) into simple dots, just as you would do with scalars, and hence get things like the binomial expansion working with vectors, etc: |A+B|² = <A,A> + 2<A,B> + <B,B> = |A|² + 2<A,B> + |B|² Well, you get the idea. The nice thing is that you don't have to work with coordinates nor long equations.
added on the 2011-07-04 20:08:27 by iq iq
Quote:
NEVER DO THAT! Use vectors!


Right. I suggest going with the fully generic approach that can just as well be applied to any nth degree surfaces.

If anyone, Adok is smart enough to apply and explain this stuff so that an average democoder can understand it.
added on the 2011-07-04 20:11:03 by 216 216
Quote:

line: P = A + t * AB
sphere: |P - C| = r

substitute P

|AC + t * AB| = r

I think this is probably stupid, though I may not be the only person wondering..

I don't understand how the substitution yields |AC + t * AB|. I feel that a step was skipped? I thought that the substitution would yield |A + t * AB - C| = r ? I am assuming that AC is meant to be a vector (using notation typically seen for line segments).. as is AB. If I had done the substitution, I think I would have ended up simplifying |A + t * AB - C| to |t * AB - AC| ..
added on the 2011-07-04 20:35:14 by guesser guesser
guesser: Yes, or |CA + t * AB| = r. Seems like he made a little mistake - well, who does not. |AC - t * AB| = r would also work.
added on the 2011-07-05 00:26:20 by Adok Adok
hornet: That's a good tutorial indeed.
added on the 2011-07-05 15:30:46 by Adok Adok
iq: The math you used for this problem feels so natural.

When I wrote a ray-tracer as a mental exercise I actually skipped all the intersection math and went directly for the solved equation in C form.

I was frustrated reading many slides using non intuitive math that I never felt comfortable learning this step of the process.

I'm now wondering why people are not using vector math as you use it in all those tutorials & slide about raytracing ?

BTW, while I have your attention :) thanks for sharing your research& finding. I enjoyed all your article & discussion [\kissass]

Also, have you evaluated this method for shadow computation ?
http://www.cs.utah.edu/~bes/papers/coneShadow/shadow-node3.html



added on the 2011-07-05 20:15:07 by T21 T21
classic :) i use similar ideas all the time for soft shadows (Ixaleno, the raymarched bridge, etc etc). By the way, what he calls a "Bernstein interpolant" is just a simple smoothstep() - I like how academic publications are full of buzz words.
added on the 2011-07-05 23:40:39 by iq iq
Quote:
I like how academic publications are full of buzz words.


..just like Smash's seminars!! :D
added on the 2011-07-05 23:49:18 by ferris ferris
iq, it's all jargon and no action.
Btw iq, what's up with the gras on that bridge picture? I don't remember you explaining it further, but it's very pretty!
i just wonder if the riemann sum should be part of the definition of the raymarching-technique. i read this in a doc:
Quote:

The ray marching algorithm subdivides the ray into equal segments and takes a sample of the participating materials properties for each segment. These segments correspond to the segments used in the Riemann approximation. As a result, the integral of the participating materials properties along the viewing ray can be approximated by the sum of the sample values multiplied by the length of one segment.

sorry to say i dont know where this doc was from.

if it has only to do with radiance, then i will rule this out, but it may hell be a part of it, i dont know. my former un-matematical definition still stands, though.
added on the 2011-07-06 14:58:23 by rudi rudi
Google reveals that's from a paper about volume rendering so it doesn't apply to hard surfaces. The volumetric stuff Chock and Las did recently is related tho.
added on the 2011-07-06 16:45:29 by kb_ kb_
kb: Hard surfaces are actually quite common in volume rendering...
added on the 2011-07-06 17:15:51 by kusma kusma
Around these parts (where proper mathematics is still far from having trickled down to the masses), the mention of Riemann sums could give the process an air of mystery and block proper learning. Some people would grab code to sprinkle around as fairy dust and plan to get around to understanding it later, and others would namedrop Riemann without offering actual explanation to maximize geek cred. I think it would actually cause harm to mention them in a definition of raymarching.. though I wouldn't see harm in mentioning the relationship in extra notes.
added on the 2011-07-06 17:51:56 by guesser guesser
^ my post probably isn't very relevant anyway - seeing as there are very few demos written in north america anyway.
added on the 2011-07-06 18:00:15 by guesser guesser
Quote:
The ray marching algorithm subdivides the ray into equal segments and takes a sample of the participating materials properties for each segment. These segments correspond to the segments used in the Riemann approximation. As a result, the integral of the participating materials properties along the viewing ray can be approximated by the sum of the sample values multiplied by the length of one segment.

Isn't this just fancy for getting the objects contribution to opacity, fog or light attenuation etc? March and accumulate the values...
added on the 2011-07-06 18:03:48 by raer raer
kusma, of course, but if there's _only_ hard surfaces there's nothing to accumulate while marching. We're still talking beginner level here.
added on the 2011-07-06 18:08:42 by kb_ kb_
I confirm raymarching fractals is really fun and easier than what you think. (plus comparing to other methods its fast enough to change parameters at runtime, and really easy to do some object intersections ).

BB Image

added on the 2011-07-06 19:24:06 by Tigrou Tigrou
distances are for beginners. equal segments is advanced stuff.
added on the 2011-07-06 20:01:02 by 216 216
The grass look like a tiny and tweaked version of the forest ?
I also wonder how its 'accelerated'. Is it Domain repetition with variation of some parameters (like the columns in Slisesix) ?
What I dont know is , does the function get 4 time slower if you do repetition as you take the min distance of the 4 as you closest distance?
If this is the case, the grass would take weeks to render...

I'm pretty slow at getting into something, but I cant wait to try some of those techniques in a ray-tracer environment.

I will scan the beginners thread again for ideas, but what is considered the 'hello world' of raymarching? (but something else then a sphere or cube as my bounding volumes are sphere and cubes:)
added on the 2011-07-07 01:18:32 by T21 T21
Well, I can always render a cube in a sphere bounding volume...

Seem to work, all my little spheres moving around are now little cubes :)
(Using IQ rounder edge cube formula and Las raymarching loop from the toolbox thread.)

I dont get the right lighting/texturing because the normal is calculated using the sphere, but its an encouraging start for me. I barely notice a frame rate drop. I'm guessing its because my ray segment start/end at the sphere bounding volume, very close to the actual surface of the cube.

Should be 'fun' to adapt the single point soft shadow function, it seem somewhat natural as its distance based... but the normal seem like a mind bending exercise.
added on the 2011-07-07 02:24:32 by T21 T21
las was kind to post an "hello world" of raymarching in the beginners thread, including normal calculation.

added on the 2011-07-08 00:53:34 by T21 T21

login