pouët.net

Go to bottom

Raymarching Beginners' Thread

category: code [glöplog]
psonice, do you use the substracted value for your bailout condition too? Or just the step?
added on the 2011-03-08 18:12:11 by msqrt msqrt
las, yep nice idea, and will try it soon (and i use pow() for the light attenuation in this video :) !
PauloFalcoa, not yet, it's maked with the new FRequency tool (an advanced shader editor with curves for parameters). The images are generated not in real time actually (~1sec per frame), because i use many step for the distance field, supersampling antialiasing and others stuffs.
added on the 2011-03-08 18:20:55 by Anat Anat
XT95, Cool :)

I think there should be a new category for "not realtime executable demo" something that would generate images and sound, in a standard form, so that was very simple to mount a video, possibly the executable would be generic too... (java?!) or something completely new build with LLVM, possible new competitions limiting the executable size ;)

I mean... i have a intel video card... i can't run GPU demos for years now... i only see them on youtube :(

But i have a nice dual core cpu ;)

I can do raymarching on a low resolution using the CPU (where the resolution dynamically changes depending on the time it took the last frame to render - fixed fps) or using RenderMonkey in HLSL ou GLSL in a small render window, but sometimes the time of compiling the shader is huge... so sometimes I switch to CPU rendering LOL

With pure raymarching is possible to use only the CPU in a low resolution, with no AA, to design the demo, and then render everything in 1280x720x60fps with a nice AA.

Do you all think this is a crazy idea?

BTW i use VisualC++Express with GLM + some cool noise functions for CPU rendering (no textures)
wow this is nice : how did you make the synchs ?
added on the 2011-03-09 09:33:55 by nytrik nytrik
Msqrt: just there. Bailout value has no effect. I still don't get why it doesn't work :(
added on the 2011-03-09 11:17:45 by psonice psonice
psonice: i believe that's because those distance fields we generate are not exactly "distance from object/from each point of that object"
some of them are, like sphere, but for example max(abs(p.x),max(abs(p.y),abs(p.z)))-size
is not actually distance from a cube, it's a trick
added on the 2011-03-09 11:28:14 by unc unc
PauloFalcao: There's already a category that suits that well, called "wild". There's where you find Tom Thumb and Staying Pictures, which are both "non-realtime generative demos". There simply aren't enough productions of this kind to justify defining a new category for it.
added on the 2011-03-09 14:00:56 by kusma kusma
OK, thanks kusma.
iq also has moving versions of some of his procedural images.
added on the 2011-03-09 15:10:42 by xernobyl xernobyl
psonice: unc is completly right and you are too. I now get a rounded cube by subtracting from the distance.
added on the 2011-03-09 16:04:08 by las las
Something like this seems to work
Code: float box2(vec3 p, vec3 s) { float d = length(clamp(p, -s, s)-p); // will become 0 if inside vec3 v = abs(p)-s; return mix(max(v.x,max(v.y, v.z)), d, step(0.000001, d)); } // rounded box d = box2(p, vec3(2.5)); d -=0.5;


added on the 2011-03-09 16:20:48 by las las
Wow, so I was actually right AND I have an explanation? Amazing! I thought there was some huge hole in my logic for sure :D Thanks unc!

Now, if only I could try it. I'm away for a few days with my laptop. GMA950 :( I did try to open my current project earlier... It took a looong time to render the first frame.
added on the 2011-03-09 21:37:01 by psonice psonice
unc, what do you mean with "is not actually distance from a cube, it's a trick:"

Code: float signedDistToBox( const vec3 & p, const vec3 & b ) { const vec3 di = abs(p) - b; const float mc = maxcomp(di); return mc<0.0f ? mc : length(max(di,0.0f)); }


gives the right closest (signed) euclidean distance to a box (you can double check it by computing the distance to the faces, edges and vertices of the box and simplify the expressions until you get this - that's how i got it). Similarly

Code: float distToCBox( vec3 pos, vec3 box, float rad ) { return length( max( abs(pos) - box + vec3(rad), 0.0 ) ) - rad; }


gives the real distance to a rounded box (measured as the closest distance to it's 6 rectangles/sides, 12 cylinders/edges and 8 spheres/corners), again, simplified to dead, but still 100% mathematically correct.
added on the 2011-03-10 01:52:39 by iq iq
I meant, when you simply do max() on two objects (their distance fields), it won't be a exactly a distance to their intersection-object. And when you subtract some value from it, it'd be the same as subtracting it from each of the object's distance fields

and yeah, distance from a cube must be done like distance from a zero-radius rounded cube. I was talking there about intersection-of-planes way of doing it:)
added on the 2011-03-10 06:53:21 by unc unc
Code: float signedDistToBox( const vec3 & p, const vec3 & b ) { const vec3 di = abs(p) - b; const float mc = maxcomp(di); return mc<0.0f ? mc : length(max(di,0.0f)); }

That one works perfect.

But it's definitely not the same as (one could consider this as a "hack")
Code: float signedDistToBox( in vec3 p, in vec3 b ) { const vec3 di = abs(p) - b; return min( maxcomp(di), length(max(di,0.0)) ); }

Original thread where that code first appeared
here

In addition to that... I don't know if using min/step will be any faster but you can get rid of the branching:
Code: float box(vec3 p, vec3 s) { vec3 d = abs(p) - s; float m = max(d.x,max(d.y, d.z)); return mix(m, length(max(d, 0.0)),step(0.,m)); }
added on the 2011-03-10 08:37:49 by las las
mix/step
added on the 2011-03-10 08:40:51 by las las
iq: could you please add frac(x) to graphtoy?:) just found that it's working on my phone(operamini) <3
and why not add it here as demotool?
added on the 2011-03-10 17:30:14 by unc unc
unc: frac(x) = (x-floor(x))
added on the 2011-03-10 18:20:28 by las las
yeah and smoothstep is clamp(x*x*3-x*x*x*2,0,1), but having it as a single function is better=)
added on the 2011-03-10 18:27:03 by unc unc
Oh god, I somehow managed to make a proper noise thing!

BB Image
added on the 2011-03-10 22:08:03 by msqrt msqrt
Looks great. Go make an intro about planets about it!
added on the 2011-03-10 23:38:11 by xernobyl xernobyl
unc, great idea, will add frac() tonight!
added on the 2011-03-10 23:58:36 by iq iq
And yeah, I have to second the demand to add graphtoy as a demotool - because it is one :)
Btw. it would be cool if one could use f1(x) in f2(x) and so on.
added on the 2011-03-11 00:22:30 by las las
added frac(x)

las, indeed. will sleep over it.
added on the 2011-03-11 04:47:13 by iq iq
and added as demotool :) (how cool it is to one production to my list without having done anything)
added on the 2011-03-11 04:51:30 by iq iq

login

Go to top