Raymarching Beginners' Thread
category: code [glöplog]
a cheaper method? how? without copying the rendertargets or the pipelined and compressed depth buffer output into a usable texture?
way is, to use a floating point rendertarget texture for all the channels and just render the depth into the f32 alpha channel bypassing the original depth queue and having the option to use f32 and additive calculations on colors too.
this not working with alpha calculations tho, but this raymarching techniques here, so... alpha is not that important.
this' AFAI learned and tryed todo. but I know... this' mosdef suboptimal.
way is, to use a floating point rendertarget texture for all the channels and just render the depth into the f32 alpha channel bypassing the original depth queue and having the option to use f32 and additive calculations on colors too.
this not working with alpha calculations tho, but this raymarching techniques here, so... alpha is not that important.
this' AFAI learned and tryed todo. but I know... this' mosdef suboptimal.
rare: You don't need to do glTexImage2D first with glCopyTexImage2D. And as you point out, you might be able to copy from the depth buffer with some GL_DEPTH_COMPONENT-trickery. But yeah, there were a reason for the "if you can get away with it"-part. ;)
How can I do a copy without having a texture before? Is a glBindTexture enough?!
?
Code:
glEnable(GL_TEXTURE_2D);
glGenTexture(1, &color);
glGenTexture(1, &depth);
...
//per loop
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, color);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, w, h, 0); //(rectanglular and non-power-2 textures need to be supported)
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, depth);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, w, h, 0);
//use shader
?
glBindTexture is enough, yes. glCopyTexImage2D allocates a new texture-image. If you were to use glCopySubTexImage2D (which is a bit faster), then you'd have to do glTexImage2D first to allocate the texture-image.
glGenTextures isn't needed, just use some hard-coded texture names. With fragment shaders, glEnable(GL_TEXTURE_2D) is superfluous, it only affects fixed-function fragment processing.
glGenTextures isn't needed, just use some hard-coded texture names. With fragment shaders, glEnable(GL_TEXTURE_2D) is superfluous, it only affects fixed-function fragment processing.
But I do need the bind every loop right? Or is binging once enough and then just activate the texture? Plus is some glTexParameters setup needed?
You probably don't have to bind it every loop, but you do have to call glActiveTexture both before binding and before doing glCopyTexImage2D, so you might as well just do both at the same time to save some calls.
Does it make any difference? The time to bind will be trivial, and for size I doubt it will make any difference inside or outside the loop. May as well put it inside.

That's a cube, I'm figuring out how to do more complex repeat patterns than mod(p, 1.0) without causing a glitch feast. I'm changing the modulation period based on the sin of the current position, then resizing the cube to fit inside that period so it doesn't cut into the cube.
What other ways are there to do complex repeats?
RareWtFailWhale : did you check GL_EXT_framebuffer_blit ? perhaps it could be of use to you.
psonice, this is a sphere :)
http://js1k.com/2010-first/demo/704
http://js1k.com/2010-first/demo/704
Paulo: ah yes, I remember that. How are you rendering the sphere, something like the variable mod() I described above?
psonice: Nice, man!
kbi: If I use a prost-processing shader anyway I could as well just sample from texture/FBO and ouput to color buffer.
kbi: If I use a prost-processing shader anyway I could as well just sample from texture/FBO and ouput to color buffer.
And thanks kusma. I'll try it out when I come home from work...
psonice:
polar coords (See tb thread for working codeusing atan2/mod/sin/cos), cylinder coords (didn't care...), sphere coords...
Other things I tested... use a "saw" function instead of frac (== mod(x,1.0)) - does not "cut" completely symmetric things (but is crap for deformed stuff) at the border iirc.
polar coords (See tb thread for working codeusing atan2/mod/sin/cos), cylinder coords (didn't care...), sphere coords...
Other things I tested... use a "saw" function instead of frac (== mod(x,1.0)) - does not "cut" completely symmetric things (but is crap for deformed stuff) at the border iirc.
psonice, i transform x,y,z to the distance to 0,0,0 with some sin perturbation.
This is also a nice way to do a torus LOL
This is also a nice way to do a torus LOL
z is not transformed
More raymarching symmetry experiments :)

Nice, sphere coords? :)
As OP I'd like to say that I'm really pleased with how this thread is turning out.
Nice atmosphere and it seems really creative and productive. A pleasure to behold you guys figure out the math of pretty images.
I also have a question for those in the know: How's the current state of CPU vs GPU? - Both have advanced tremendously in parallelity. Is GPU still on top?
On the CPU front, folks are also productive, but rendering still seems a tad slow: Witness Intel's 80 thread raytracing orgy.
On the other hand, that was Sep 2010. Things are surely progressing fast these days, everywhere... :)
Nice atmosphere and it seems really creative and productive. A pleasure to behold you guys figure out the math of pretty images.
I also have a question for those in the know: How's the current state of CPU vs GPU? - Both have advanced tremendously in parallelity. Is GPU still on top?
On the CPU front, folks are also productive, but rendering still seems a tad slow: Witness Intel's 80 thread raytracing orgy.
On the other hand, that was Sep 2010. Things are surely progressing fast these days, everywhere... :)

vibrator: at least for 4k GPU is inho on top (small size for huge effects :)). And yeah... that "realtime" RT from your youtube link is not "realtime" in any way - not even "interactive".
More symmetry


Paulo, how did you get the sphere coord repeat working? Had some problems applying it...
Should be something like:
get radius (r = length(p). get theta (acos(z/r), get phi (atan(y,x), apply modulos to theta and phi and recalculate x, y, z.
Should be something like:
get radius (r = length(p). get theta (acos(z/r), get phi (atan(y,x), apply modulos to theta and phi and recalculate x, y, z.
yeah, code requested :)
I'll have a try with spherical coords during lunch today. I've got some ideas that need complex repeat patterns, and spherical coords would be helpful. Getting patterns that look good is hard though :(
I'll have a try with spherical coords during lunch today. I've got some ideas that need complex repeat patterns, and spherical coords would be helpful. Getting patterns that look good is hard though :(

HLSL experiment code dump, not optimized :)
float2 rot(float2 p,float r){
float2 ret;
ret.x=p.x*cos(r)-p.y*sin(r);
ret.y=p.x*sin(r)+p.y*cos(r);
return ret;
}
float2 rotsim(float2 p,float s){
float2 ret=p;
ret=rot(p,-PI/(s*2));
ret=rot(p,floor((-atan2(ret.y,ret.x)/PI)*s)*(PI/s));
return ret;
}
//p is xyz
p.xy=rotsim(p.xy,4);
p.xz=rotsim(p.xz,4);