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 :-)
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 :-)
hlsl fmod handles negative numbers different from glsl one
try something like a - b * floor(a/b)
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:
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?
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?
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.
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.
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?
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?
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?
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
las: i use bicubic
smash: papers? code? :)
Is "GPUGEMS Chapter 20 Fast Third-Order Texture Filtering" the thing to read?
Is "GPUGEMS Chapter 20 Fast Third-Order Texture Filtering" the thing to read?
tried that one... the results are not... mega cool. Or I might have some tiny ugly bug in it...
my fault - works.
Nice talk about Advanced Procedural Rendering in DirectX 11
by Matt Swoboda / Fairlight
Many cool stuff about raymarching.
http://directtovideo.wordpress.com/2012/03/15/get-my-slides-from-gdc2012/
by Matt Swoboda / Fairlight
Many cool stuff about raymarching.
http://directtovideo.wordpress.com/2012/03/15/get-my-slides-from-gdc2012/
in fact not really raymarching at all, but avoiding raymarching whereever possible.. :)
That fairlight logo at the start - I'm secretly hoping that was a cracktro that ran before the presentation loaded :)
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?
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.
@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 :)
Quote:
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!
Quote:
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.
Spite: you're right :)
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.
"he was raymarching me" sounds a bit dirty :)