Raymarching Tutorial
category: code [glöplog]
he just did...
SH-SH-SHAAAAAAAAA!!1
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.
* <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.
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.
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| ..
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.
Actual tutorial, raymarching for fractals, part1:
http://blog.hvidtfeldts.net/index.php/2011/06/distance-estimated-3d-fractals-part-i/
http://blog.hvidtfeldts.net/index.php/2011/06/distance-estimated-3d-fractals-part-i/
hornet: That's a good tutorial indeed.
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
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
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.
Quote:
I like how academic publications are full of buzz words.
..just like Smash's seminars!! :D
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:
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.
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.
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.
kb: Hard surfaces are actually quite common in volume rendering...
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.
^ my post probably isn't very relevant anyway - seeing as there are very few demos written in north america anyway.
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...
kusma, of course, but if there's _only_ hard surfaces there's nothing to accumulate while marching. We're still talking beginner level here.
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 ).
distances are for beginners. equal segments is advanced stuff.
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:)
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:)
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.
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.
las was kind to post an "hello world" of raymarching in the beginners thread, including normal calculation.