Go to bottom

Raymarching Beginners' Thread

category: code [glöplog]
Wow, awesome explanation. Thanks a lot.
Regarding the domain repetition: the fmod works differently in hlsl and I get some pretty weird results when looking into the wrong direction.

las: "fmod in hlsl iirc" what does that mean? It sure doesn't sound like English anymore :-)

added on the 2012-02-25 20:31:51 by pixtur pixtur
hlsl fmod handles negative numbers different from glsl one
added on the 2012-02-25 20:40:54 by rale rale
try something like a - b * floor(a/b)
added on the 2012-02-25 20:41:42 by rale rale
I'm still fighting with the distance field and spacial distortion. I would like to intersected a bunch of rotated planes and cubes. I managed to pull off this little function that gives me planes rotated around z:

Code: float dRotatedPlanes(float3 p, float angle, float frequency, float ratio) { float3 pRotated= float3(p.x * cos(angle) - p.y * sin(angle), p.x * sin(angle) + p.y * cos(angle), p.z); return sin(pRotated.x *frequency)-ratio; }

For frequency=1 the result looks quite pleasing. For higher frequencies however, the intersecting surfaces get fucked up...

I guess, that's related to my scaled boxes before. But how do I rotate something? IQs suggestion with the inverted matrix seems to be too slow for realtime.

I wand to intersect 3 grids of rotated boxes to build some kind of city. Any suggestions?

BB Image

added on the 2012-02-26 20:18:26 by pixtur pixtur
Pixtur: you can't just use any random function as a distance function. If you are 10 units away from your object in reality, then it is fine that your function says you are closer than that (say 8 or 5 or 9 units from it), as long as the error becomes smaller when you get closer to your object. You'll just have to march a few extra steps.

But if your function says you're 11 or 12 units from it, you'll take a step that is too large and may end up inside your object. So it's OK if your function underestimates the true distance, but it should never overestimate it. A consequence of this is that the "speed" or steepest slope f(x)/x of your function should always be less then 1. So the value of distance( p ) should never be more then 1 different then the value of distance( p + vec3(1,0,0) ), same with the Y and Z directions or a combination. If you move 1 unit in whatever direction, you should never suddenly be 1.5 units closer or further from the object.

The Sine function has a maximum slope of 1 (near 0 f.e. : sin(0.001) = 0.0009999998).But if you multiply with a frequency higher then 1, then the slope gets steeper: sin( 0.001 * 5) = 0.0049999, so the slope f(x)/x = 0.0049999/ 0.001 = 4.9999 . You can fix this by dividing your distance estimate by it's speed, but of course that will cause a slowdown. See this thread: http://www.pouet.net/topic.php?which=5604

But in your case, I would suggest using a modified cube formula to get a huge flat rectangle, then use domain repetition to get a stack of those, and then rotate the result. That should give your the same result, but probably faster.
added on the 2012-02-27 20:32:07 by Seven Seven
Just modulo repeat some rotated boxes and cut them from you "big box".

A question for all those who tried storing SDFs as 2D/3D texture - how do you sample that crap in order to get a proper C2 surface?
added on the 2012-03-01 14:44:57 by las las
well, sampling SDFs from textures is indeed a bit crappy :/ i've given up that thing personally. Maybe others had some bright idea. Did you try the smoothstep trick from iq to sample normal/bump maps?
added on the 2012-03-01 16:20:48 by nystep nystep
i think your dScaledBox is wrong: you shouldn't scale P, but the cube itslef. in other words, change b in sdBox in http://iquilezles.org/www/articles/distfunctions/distfunctions.htm, not p. then you should be able to use smaller and smaller cubes as much as you want: http://iquilezles.org/www/articles/menger/menger.htm
added on the 2012-03-01 17:59:09 by iq iq
las: i use bicubic
added on the 2012-03-01 18:35:38 by smash smash
smash: papers? code? :)
Is "GPUGEMS Chapter 20 Fast Third-Order Texture Filtering" the thing to read?
added on the 2012-03-01 19:00:28 by las las
tried that one... the results are not... mega cool. Or I might have some tiny ugly bug in it...
added on the 2012-03-01 23:08:52 by las las
my fault - works.
added on the 2012-03-03 01:07:27 by las las
Nice talk about Advanced Procedural Rendering in DirectX 11
by Matt Swoboda / Fairlight

Many cool stuff about raymarching.

in fact not really raymarching at all, but avoiding raymarching whereever possible.. :)
added on the 2012-03-15 14:39:59 by smash smash
That fairlight logo at the start - I'm secretly hoping that was a cracktro that ran before the presentation loaded :)
added on the 2012-03-15 15:20:37 by psonice psonice
It really amazes me that temporal reprojection isn't more common, I have a feeling (but no data...) that it could be used very well for a lot of static scenes. Maybe the static is why.
graga - what makes you think repojection not common?
added on the 2012-03-15 16:09:51 by hornet hornet
Speaking of IQ and smoothstep -- favourite story from GDC: when someone stopped a fairly long way from him and said "Hey Inigo - what am I?" and then proceeded to move closer and closer in 50% increments.
added on the 2012-03-15 16:58:03 by gloom gloom
@hornet: touché, I don't know anything about that either. Dumb of me. Is it common?
graga - it's reasonably common for a couple of things, though primarily used for SSAO and AA. Known uses in gears of war2+3 (ue3), bf3, crysis2 - high-end games with expensive effects that benefit from it :)
added on the 2012-03-15 19:24:49 by hornet hornet
Speaking of IQ and smoothstep -- favourite story from GDC: when someone stopped a fairly long way from him and said "Hey Inigo - what am I?" and then proceeded to move closer and closer in 50% increments.

lmfao. would have loved to see that!
Speaking of IQ and smoothstep -- favourite story from GDC: when someone stopped a fairly long way from him and said "Hey Inigo - what am I?" and then proceeded to move closer and closer in 50% increments.

I think that was @UnitZeroOne.
added on the 2012-03-16 11:55:56 by spite spite
Spite: you're right :)
added on the 2012-03-16 12:30:35 by gloom gloom
yes, it was Ralph. and yep, i didn't get the joke until they explained it to me he was raymatching me. lol, it was a good bad-joke, i love it now.
added on the 2012-03-17 07:01:43 by iq iq
"he was raymarching me" sounds a bit dirty :)
added on the 2012-03-17 07:11:20 by gloom gloom


Go to top