Raymarching Beginners' Thread
category: code [glöplog]
And I just realised, there's a difference between occlusion and ambient occlusion. What I'm trying to do is straight occlusion rather than AO. Maybe O will be enough, maybe O + AO will look best.
Is lighting generally done with point or directional lights btw? Or a mix? (One light with shadows plus a bunch of directional lights should be trivial enough!)
Is lighting generally done with point or directional lights btw? Or a mix? (One light with shadows plus a bunch of directional lights should be trivial enough!)
you can do the light however you want - the only limitation you have is speed.
Speed isn't a problem, just lower the resolution even more ;)
This seems very awesome. Is there an article which can get a complete newcomer into this kinda stuff? :)
Am I the only one that have a feeling that we'll see a lot of cut-out-objects in future intros/demos in 2011? ;-)
nakedman: Search for the raymarching toolbox thread on the pouet bbs
Punqtured: Might happen - more people working on it - more ideas - more progress - more fun.
Punqtured: Might happen - more people working on it - more ideas - more progress - more fun.
nakedman: http://www.pouet.net/topic.php?which=7931 should cover most of it. There's a raymarching loop at the bottom of las' first post, you need to provide it with a camera position and ray direction, and a function (try a simple sphere function initially to check if it works - also on that page).
Punqtured: expect a ton of wobbly blobs too ;)
Punqtured: expect a ton of wobbly blobs too ;)
I just think this is great, using Pouet for something useful, sharing knowledge and educating people about how to do raymarching effects!
Quick, someone post a cat or porn or anything unrelated!
No powly - we don't need another residue thread here :)
Btw. I tried to fake something like colorbleeding - more or less successful. It was very hard to control and looked like crap - but I guess one can fake it better.
How do you handle color/materials in a fast way? I implemented my distance function twice, one version computes distance only the second version computes the material. (could be crunched by using macros).
The version to determine the material is only used one time for each pixel, the distance only version far more often.
Another thing I thought of was encoding the material in the last 3 bits (8 different materials possible) of the float and let the min do the "branching" - this could be done by using asfloat and asint (the GLSL names are just too long). Maybe there's a more clever way to "watermark" the floats with the corresponding material - any ideas?
Btw. I tried to fake something like colorbleeding - more or less successful. It was very hard to control and looked like crap - but I guess one can fake it better.
How do you handle color/materials in a fast way? I implemented my distance function twice, one version computes distance only the second version computes the material. (could be crunched by using macros).
Code:
vec3 color;
float nd, d;
nd = d = dot(p-vec3(0.0,-1.0,0.0),vec3(0.0,1.0,0.0));
color = hsv(0.0, 1.0, 1.0);
nd = dot(p-vec3(0.0,1.0,0.0),vec3(0.0,-1.0,0.0));
d = min(d, nd);
color = mix(color, hsv(0.1, 1.0, 1.0), step(nd, d));
nd = dot(p-vec3(-1.0,0.0,0.0),vec3(1.0,0.0,0.0));
d = min(d, nd);
color = mix(color, hsv(0.2, 0.6, 0.8), step(nd, d));
nd = dot(p-vec3(1.0,0.0,0.0),vec3(-1.0,0.0,0.0));
d = min(d, nd);
color = mix(color, hsv(0.3, 0.0, 1.0), step(nd, d));
The version to determine the material is only used one time for each pixel, the distance only version far more often.
Another thing I thought of was encoding the material in the last 3 bits (8 different materials possible) of the float and let the min do the "branching" - this could be done by using asfloat and asint (the GLSL names are just too long). Maybe there's a more clever way to "watermark" the floats with the corresponding material - any ideas?
float2
or struct.
punqtured, csg has evolved alot from the basic opengl-way using stencils - http://www.opengl.org/resources/code/samples/advanced/advanced97/notes/node11.html
The quest for decent shadows goes on.. and at last something that looks half decent. I'm using 20 iterations for the shadows, so the speed hit shouldn't be too harsh. I'll clean up the code at lunch time and post it in the toolbox thread, time to get ready for work now.
Quote:
float2
But min is component wise... what one needs is a min that moves also the y component according to x values. Where is the point of using a float2 or struct?
Code:
float2 min2(float2 a,float2 b){return a.x<b.x?a:b;}
I guess that will be way slower than using two separate versions of the field.
i dunno, never used it :P
Damn, I've been wondering all morning what the hell a float2 is! 64bit float? Some kind of new version of a float?! But it's just a vec2. Doh!
Unc: handy. Time to add some colours + materials :) Thanks.
Related question: Say we use the y component to determine if the material should have SSS, but we also want AO (or whatever other lighting.. and I wonder now wtf my shadow code does if I change it to SSS).
Switching between AO and SSS is pretty trivial, with something like
But what's the best way to switch between AO and SSS+AO?
Unc: handy. Time to add some colours + materials :) Thanks.
Related question: Say we use the y component to determine if the material should have SSS, but we also want AO (or whatever other lighting.. and I wonder now wtf my shadow code does if I change it to SSS).
Switching between AO and SSS is pretty trivial, with something like
Code:
l = ao(p, n, d * (dist > 0. ? 1. : -1.), float i)
But what's the best way to switch between AO and SSS+AO?
oh, thought hit me right after I hit submit.
How about changing the AO function itself. For positive d, the ray steps out along the normal. For negative d, it alternates between +/- distance along the normal, so it calculates both AO and SSS in one step (but with half accuracy).
How about changing the AO function itself. For positive d, the ray steps out along the normal. For negative d, it alternates between +/- distance along the normal, so it calculates both AO and SSS in one step (but with half accuracy).
You can do that. But I use very different step-widths for ao and sss also the number of samples differs.
You have to play around a lot to archive a good looking sss - maybe it's a good idea to try to combine it when you are almost done.
I would just compute both ao and sss as usual and then combine it on demand.
You have to play around a lot to archive a good looking sss - maybe it's a good idea to try to combine it when you are almost done.
I would just compute both ao and sss as usual and then combine it on demand.
Ahh and please use the sign function ;)
Code:
l = ao(p, n, d * sign(dist), float i)
Hmm.. I guess it's possible with a single AO function + some trickery, but more difficult. And good point about sign(), I have a bad habit of using conditionals all over the place where something else would be better.
I would do that kind of trickery at the end of the development process because it really limits your choices and kills playing around with single values without side effects. btw. Nice shadows you've go there ;)
We really need more stuff on domain repetition in the toolbox thread. e.g. with polar coordinates you can repeat an object around an axis.
We really need more stuff on domain repetition in the toolbox thread. e.g. with polar coordinates you can repeat an object around an axis.
@unc: if you're interested in participating in some pretty interesting vvvv developments, contact me (username m4d) or dottore on vvvv.org.. ;)