Raymarching Beginners' Thread
category: code [glöplog]
psonice, do you use the substracted value for your bailout condition too? Or just the step?
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.
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.
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)
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 ?
Msqrt: just there. Bailout value has no effect. I still don't get why it doesn't work :(
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
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
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.
OK, thanks kusma.
iq also has moving versions of some of his procedural images.
psonice: unc is completly right and you are too. I now get a rounded cube by subtracting from the distance.
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;
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.
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.
unc, what do you mean with "is not actually distance from a cube, it's a trick:"
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
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.
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.
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:)
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:)
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));
}
mix/step
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?
and why not add it here as demotool?
unc: frac(x) = (x-floor(x))
yeah and smoothstep is clamp(x*x*3-x*x*x*2,0,1), but having it as a single function is better=)
Oh god, I somehow managed to make a proper noise thing!
Looks great. Go make an intro about planets about it!
unc, great idea, will add frac() tonight!
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.
Btw. it would be cool if one could use f1(x) in f2(x) and so on.
added frac(x)
las, indeed. will sleep over it.
las, indeed. will sleep over it.
and added as demotool :) (how cool it is to one production to my list without having done anything)