pouët.net

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.
added on the 2011-03-03 01:01:41 by yumeji yumeji
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. ;)
added on the 2011-03-03 01:17:21 by kusma kusma
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

?
added on the 2011-03-03 10:09:47 by raer raer
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.
added on the 2011-03-03 10:20:51 by kusma kusma
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?
added on the 2011-03-03 10:37:16 by raer raer
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.
added on the 2011-03-03 11:38:38 by kusma kusma
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.
added on the 2011-03-03 12:21:03 by psonice psonice
BB Image

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?
added on the 2011-03-03 14:01:54 by psonice psonice
RareWtFailWhale : did you check GL_EXT_framebuffer_blit ? perhaps it could be of use to you.
added on the 2011-03-03 14:09:08 by kbi kbi
psonice, this is a sphere :)
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?
added on the 2011-03-03 14:50:08 by psonice psonice
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.
added on the 2011-03-03 14:50:52 by raer raer
And thanks kusma. I'll try it out when I come home from work...
added on the 2011-03-03 14:58:26 by raer raer
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.
added on the 2011-03-03 15:01:42 by las las
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
z is not transformed
More raymarching symmetry experiments :)
BB Image
Nice, sphere coords? :)
added on the 2011-03-03 19:14:16 by las las
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... :)
added on the 2011-03-03 23:10:48 by vibrator vibrator
BB Image
added on the 2011-03-04 09:32:55 by Tigrou Tigrou
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".
added on the 2011-03-04 09:54:28 by las las
More symmetry
BB Image
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.
added on the 2011-03-04 12:17:24 by las las
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 :(
added on the 2011-03-04 12:29:18 by psonice psonice
BB Image

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);

login