Gl render buffer question

Apr 6, 2006 at 1:03am

Gl render buffer question

I’m looking for a way to enable drawing to several opengl buffers at
once for writing into by a shader. The opengl command I want to
execute is essentially glDrawBuffers(2, [GL_BACK_LEFT, GL_AUX0])
jit.gl.sketch doesn’t have a command for this. jit.gl.render has the
@aux_buffers attribute for specifying an aux buffer. I’m not quite
sure what this does, but it did completely screw up the way my sketch
object is rendering vertices. And advice on how to do this will be
greatly appreciated.

thanks,
wes

#25253
Apr 6, 2006 at 1:12am

Aux buffers aren’t well supported at the moment, Wes. Is there any
way for you to accomplish what you are attempting by rending multiple
times into the frame buffer?

-Joshua

#74161
Apr 6, 2006 at 1:24am

The fragment shader does the following in pass1

gl_FragData[0] = texture2D(TextureMap, TexCoord);
gl_FragData[1] = vec4(vec3(0.0), CameraDepth);

In pass 2 it accesses both of these values to render shadows. So,
somehow I need 2 buffers to write into simultaneously that I can then
access in shader pass 2. If I did something like enable stereo
rendering would I have access to 2 buffers then? Could I do something
tricky like:

jit.gl.render -> enable stereo
run shader pass 1 and draw into left and right buffers
run shader pass 2
jit.gl.render -> disable stereo
swap left buffer to screen

This is wild speculation and probably won’t work at all but gets the
idea across. The first shader looks at objects’ distance from the
camera and renders the scene with no lighting information. The second
pass add lighting and shadow information. This is from the Orange
Book ch 13 p. 347

It seems everytime I attempt to do some shadows in jitter I can’t get
anywhere because the method is not achievable the way things are
currently set up. :(

So, has anyone out there successfully rendered shadows in jitter? I’m
very curious as no matter how I come at it, I can’t seem to get there.

thanks,
wes

#74162
Apr 6, 2006 at 1:37am

Randy made a patch back in March 05 and posted it to the list:

here it is

max v2;
#N vpatcher 267 45 977 816;
#P origin -10 0;
#P comment 223 584 154 196617 drawing order is important so turn
automatic off;
#P newex 168 585 50 196617 t b b;
#P newex 555 614 50 196617 route init;
#P comment 600 561 90 196617 second renderer projects scene onto
shadow texture;
#P newex 7 507 145 196617 jit.fastblur @mode 2 @range 3;
#P comment 347 692 154 196617 floor;
#P comment 180 721 154 196617 shadow – blend_mode subtracts it from
floor;
#P newex 226 553 150 196617 prepend texture shadowtexture;
#P newex 179 615 138 196617 jit.gl.gridshape hedgehog @shape plane
@position 0 0 0.005 @depth_enable 1 @scale 0.5 0.5 1 @color 1 1 1 1
@blend_enable 1 @rotate 180 0 0 1 @automatic 0 @blend_mode 6 5
@texture shadowtexture;
#P message 562 485 128 196617 lookat 0 0 0 , camera 0 0 1 , up 0 1
0 , color 0.5 0.5 0.5 1 , erase_color 0 0 0 1 , depth_enable 0 ,
texture shadowtexture 256 256 , tri_grid;
#P newex 492 565 105 196617 jit.gl.render s2;
#P newex 7 479 141 196617 jit.matrix s2 4 char 128 128;
#P user jit.pwindow 19 551 130 130 0 1 0 0 1 0;
#X name ;
#P newex 502 491 50 196617 t b l erase;
#P newex 476 453 195 196617 jit.op @op pass pass + pass pass @val 0.5;
#P newex 349 632 138 196617 jit.gl.gridshape hedgehog @shape plane
@depth_enable 1 @texture grid @color 1 1 1 1 @automatic 0;
#P user ubumenu 307 375 84 196617 0 1 1 0;
#X add points;
#X add lines;
#X add line_strip;
#X add line_loop;
#X add triangles;
#X add tri_strip;
#X add tri_fan;
#X add quads;
#X add quad_strip;
#X add polygon;
#X add tri_grid;
#X add quad_grid;
#X prefix_set 0 0
0;
#P toggle 371 465 15 0;
#P message 371 483 85 196617 poly_mode $1 $1;
#N vpatcher 511 116 961 437;
#P newex 16 139 37 196617 == 0;
#P newex 105 95 27 196617 t i i;
#P message 16 164 93 196617 ; jit menubar $1;
#P newex 105 50 50 196617 select 27;
#P newex 105 28 40 196617 key;
#P toggle 105 75 15 0;
#P message 315 233 32 196617 reset;
#P flonum 261 213 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 261 233 51 196617 radius $1;
#P flonum 194 213 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 194 233 60 196617 tracking $1;
#P newex 10 254 341 196617 jit.gl.handle hedgehog @inherit_transform
1 @depth_enable 1 @tracking 2;
#P outlet 10 284 15 0;
#P newex 122 139 91 196617 prepend fullscreen;
#P newex 122 164 140 196617 jit.window hedgehog @rect 10 50 200 200
@depthbuffer 1;
#P comment 10 218 178 196617 inherit_transform is important here ,
since we are controlling jit.gl.render;
#P fasten 7 0 4 0 266 251 15 251;
#P fasten 5 0 4 0 199 248 15 248;
#P fasten 9 0 4 0 320 251 15 251;
#P connect 4 0 3 0;
#P fasten 14 0 15 0 110 127 21 127;
#P connect 15 0 13 0;
#P connect 11 0 12 0;
#P connect 12 0 10 0;
#P connect 10 0 14 0;
#P connect 14 1 2 0;
#P connect 2 0 1 0;
#P connect 6 0 5 0;
#P connect 8 0 7 0;
#P pop;
#P newobj 20 373 115 196617 p window-mouse-rotate;
#N vpatcher 40 55 443 428;
#P number 206 114 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P inlet 137 24 15 0;
#P outlet 170 329 15 0;
#P newex 136 126 50 196617 t b i b;
#P message 242 162 133 196617 deletetexture movietexture;
#P message 14 251 121 196617 usetexture movietexture;
#P newex 133 210 174 196617 sprintf texture movietexture %d %d;
#P connect 3 0 1 0;
#P connect 3 1 0 0;
#P connect 5 0 3 0;
#P connect 1 0 4 0;
#P connect 2 0 4 0;
#P connect 0 0 4 0;
#P connect 5 0 6 0;
#P connect 3 2 2 0;
#P connect 3 1 0 1;
#P pop;
#P newobj 475 304 89 196617 p remake_texture;
#P flonum 540 387 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N vpatcher 56 45 783 544;
#P inlet 669 37 15 0;
#P newex 41 216 62 196617 jit.op @op +;
#P hidden inlet 635 37 15 0;
#P newex 247 321 63 196617 jit.op @op *;
#P newex 247 280 63 196617 jit.op @op *;
#P newex 271 249 63 196617 jit.op @op *;
#P comment 355 178 49 196617 cos alpha;
#P comment 329 149 45 196617 sin alpha;
#P comment 532 148 45 196617 sin delta;
#P comment 573 180 48 196617 cos delta;
#P newex 493 212 63 196617 jit.op @op *;
#P newex 493 177 71 196617 jit.op @op cos;
#P newex 452 145 69 196617 jit.op @op sin;
#P newex 271 174 71 196617 jit.op @op cos;
#P newex 247 145 69 196617 jit.op @op sin;
#P newex 452 120 130 196617 jit.op @op * @val 3.14159;
#P newex 80 401 131 196617 jit.pack 5 float32 @adapt 1;
#P newex 80 72 79 196617 jit.unpack 5;
#P newex 247 119 124 196617 jit.op @op * @val 6.2832;
#P inlet 80 38 15 0;
#P outlet 80 427 15 0;
#P comment 273 39 100 196617 3d polar coords map:;
#P comment 376 39 168 196617 // rcst = r*cos(delta) ; // vec->x =
rcst*cos(alpha) ; // vec->y = rcst*sin(alpha) ; // vec->z = r*sin
(delta) ;;
#P comment 567 215 27 196617 rcst;
#P hidden comment 615 82 92 196617 for dims messages;
#P comment 21 186 100 196617 r offset;
#P fasten 8 2 24 0 111 129 46 129;
#P connect 6 0 8 0;
#P fasten 20 0 9 0 276 270 85 270;
#P connect 9 0 5 0;
#P connect 25 0 24 1;
#P fasten 21 0 9 1 252 300 115 300;
#P fasten 22 0 9 2 252 376 145 376;
#P connect 8 3 9 3;
#P connect 8 4 9 4;
#P fasten 8 0 7 0 85 109 252 109;
#P connect 7 0 11 0;
#P connect 11 0 21 0;
#P connect 24 0 22 0;
#P connect 7 0 12 0;
#P connect 12 0 20 0;
#P fasten 15 0 21 1 498 268 305 268;
#P fasten 13 0 22 1 457 302 305 302;
#P fasten 15 0 20 1 498 233 329 233;
#P fasten 8 1 10 0 98 101 457 101;
#P connect 10 0 13 0;
#P connect 10 0 14 0;
#P fasten 24 0 15 0 46 242 498 242;
#P connect 14 0 15 1;
#P pop;
#P newobj 484 421 85 196617 p plane-to-sphere;
#P comment 306 358 100 196617 other draw prims;
#P comment 241 144 125 196617 send texture to jit_render;
#P hidden message 314 465 32 196617 45.;
#P newex 183 276 50 196617 t b;
#P comment 15 116 164 196617 scale movie and map ARGB to RRGB;
#P comment 17 302 154 196617 send to plane 5 (z) of geometry matrix;
#P comment 17 254 154 196617 multiply by a scalar;
#P comment 18 211 154 196617 convert to float32;
#P comment 17 184 154 196617 calculate sum of rgb components;
#P hidden message 434 230 29 196617 0.25;
#P comment 354 231 100 196617 z displace scale;
#P hidden message 410 29 14 196617 1;
#P hidden message 587 30 20 196617 64;
#P comment 440 29 100 196617 set geometry dims;
#P hidden newex 632 52 50 196617 loadbang;
#P toggle 220 465 15 0;
#P message 220 483 50 196617 interp $1;
#P message 275 483 70 196617 lens_angle $1;
#P flonum 275 465 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 549 48 36 196617 t b i;
#P number 549 26 35 9 0 0 64 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 575 82 60 196617 dim $1 $1;
#P newex 183 182 164 196617 jit.scalebias @mode 1 @scale 0.33;
#P flonum 316 230 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 183 252 63 196617 jit.op @op *;
#P message 372 49 42 196617 rate $1;
#P flonum 372 29 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 373 142 144 196617 prepend texture movietexture;
#P newex 183 305 131 196617 jit.pack 5 @out_name geom;
#P newex 183 209 175 196617 jit.matrix 1 float32 64 64 @interp 1;
#P newex 183 114 275 196617 jit.matrix 4 char 64 64 @planemap 1 1 2 3
@interp 1;
#P message 246 49 28 196617 read;
#P message 316 49 27 196617 stop;
#P message 282 49 31 196617 start;
#P toggle 183 28 15 0;
#P newex 183 48 55 196617 metro 20;
#P newex 183 81 103 196617 jit.qt.movie 160 120;
#P user jit.pwindow 198 144 34 34 0 1 0 1 1 0;
#P message 191 375 44 196617 tri_grid;
#P newex 402 335 55 196617 t b b erase;
#P message 191 399 241 196617 lookat 0 0 0 , camera 1 0 2 , up 0 0
1 , color 1. 1. 1. 0.5 , erase_color 0. 0. 0. 1. , depth_enable 1
, blend_enable 0 , texture movietexture 64 64 , usetexture
movietexture , texture grid 64 64;
#P message 586 124 98 196617 plane 0 , 0.5 0.5 -0.5 -0.5 , plane 1
, -0.5 0.5 -0.5 0.5 , plane 2 , 0. 0. 0. 0. , plane 3 , 0. 1. 0.
1. , plane 4 , 0. 0. 1. 1.;
#P newex 586 232 98 196617 jit.matrix small 5 float32 2 2;
#P newex 586 208 98 196617 jit.fill small;
#P newex 586 367 101 196617 jit.matrix geom 5 float32 64 64 @interp 1
@thru 0;
#P newex 460 591 105 196617 jit.gl.render hedgehog;
#P comment 200 29 158 196617 � read a movie and turn metro on;
#P comment 191 358 100 196617 default draw prim;
#P comment 483 375 93 196617 rest size of sphere;
#P connect 45 0 60 0;
#P connect 60 0 67 0;
#P connect 67 0 59 0;
#P connect 58 1 70 0;
#P connect 70 0 63 0;
#P connect 14 0 13 0;
#P fasten 17 0 12 0 251 75 188 75;
#P fasten 16 0 12 0 321 75 188 75;
#P fasten 15 0 12 0 287 75 188 75;
#P fasten 23 0 12 0 377 75 188 75;
#P fasten 13 0 12 0 188 75 188 75;
#P connect 27 0 18 0;
#P lcolor 12;
#P connect 12 0 18 0;
#P connect 18 0 26 0;
#P fasten 27 0 19 0 580 204 188 204;
#P lcolor 12;
#P connect 26 0 19 0;
#P connect 19 0 24 0;
#P connect 24 0 45 0;
#P connect 45 0 20 0;
#P hidden connect 34 0 10 0;
#P hidden connect 34 0 8 0;
#P connect 18 0 11 0;
#P connect 33 0 32 0;
#P connect 67 0 64 0;
#P fasten 25 0 24 1 321 248 241 248;
#P fasten 24 0 20 2 188 272 248 272;
#P hidden connect 46 0 30 0;
#P connect 30 0 31 0;
#P hidden connect 34 0 46 0;
#P fasten 29 0 25 0 554 227 321 227;
#P hidden connect 39 0 25 0;
#P connect 70 1 56 0;
#P connect 54 0 53 0;
#P hidden connect 37 0 22 0;
#P connect 22 0 23 0;
#P fasten 18 0 21 0 188 139 378 139;
#P fasten 20 0 9 0 188 327 407 327;
#P hidden connect 34 0 37 0;
#P hidden fasten 34 0 39 0 637 225 439 225;
#P fasten 53 0 3 0 376 505 465 505;
#P connect 52 0 3 0;
#P connect 57 0 3 0;
#P fasten 55 1 3 0 349 394 465 394;
#P connect 51 0 3 0;
#P fasten 32 0 3 0 225 505 465 505;
#P fasten 10 0 3 0 196 395 465 395;
#P fasten 8 0 3 0 196 536 465 536;
#P fasten 31 0 3 0 280 505 465 505;
#P fasten 9 2 3 0 451 377 465 377;
#P fasten 9 0 3 0 407 382 465 382;
#P fasten 21 0 3 0 378 177 465 177;
#P connect 64 0 3 0;
#P connect 29 1 51 0;
#P lcolor 10;
#P connect 49 0 57 0;
#P fasten 4 0 49 0 591 416 489 416;
#P connect 58 1 61 0;
#P connect 62 0 61 0;
#P connect 58 0 61 0;
#P connect 58 2 61 0;
#P connect 53 0 61 0;
#P connect 49 0 58 0;
#P hidden connect 36 0 28 0;
#P connect 28 0 29 0;
#P connect 3 1 69 0;
#P connect 50 0 49 2;
#P connect 34 0 62 0;
#P connect 29 1 27 0;
#P hidden connect 34 0 7 0;
#P connect 29 0 7 0;
#P connect 7 0 5 0;
#P connect 5 0 6 0;
#P fasten 27 0 4 0 580 272 591 272;
#P lcolor 12;
#P fasten 9 1 4 0 429 357 591 357;
#P connect 6 0 4 0;
#P hidden connect 34 0 36 0;
#P pop;

#74163
Apr 6, 2006 at 1:43am

Unfortunately, this approach also assumes that you can create a
texture from the depth buffer of the aux buffer, which is also not
exposed in Jitter. Randy a while back made a simple shadow map
example, which I believe should be in the archives somewhere.

The first pass of the technique outlined in the Orange Book can in
theory be segmented into multiple stages each rendering to a single
output texture which would then be used by a final stage, though
currently it would be restricted to using the 8bit color channels of
the output texture since there are issues with rendering to floating
point textures at the moment. For greater precision with what’s
available, you could store the high order bits in one color channel
and the low order bits in another color channel (this is similar to
the approach I used for the hi-res MSP objects, making near double
precision floats out of two single precision floats). So in theory
what you want to accomplish is possible without aux buffers, depth
textures, or rendering to floating point textures, though it would of
course be cumbersome, and perhaps worth waiting until Jitter supports
the functionality you need. Stereo buffers are also not exposed.

We can work on aux buffer, stereo buffer, depth texture, and render
to floating point texture support in a future version of Jitter, but
for now, such tasks would require coding in a C object.

-Joshua

#74164
Apr 6, 2006 at 2:02am

Hey that’s great! I don’t remembr seeing this. The hedgehog thing is
also nice. It’s a nice start, but it is also really limited. The
shadow isn’t general enough to interact with the environment properly
if I move the shadow plane up and down or change it’s shape. So, for
my next question…has anyone been able to do shadows using shaders in
jitter? or depth testing methods?

thanks,
wes

#74165
Aug 25, 2010 at 11:29pm

4 years ago, JKC wrote:

> and perhaps worth waiting until Jitter supports
> the functionality you need. Stereo buffers are also not exposed.
>
> We can work on aux buffer, stereo buffer, depth texture, and render
> to floating point texture support in a future version of Jitter, but
> for now, such tasks would require coding in a C object.

So Joshua: did support for stereo buffers ever get added?

Now that there are all these cheap 120Hz 3D projectors available, it would be really killer to be able to use them with Jitter.

If not now, when?

- pH

#74166
Aug 26, 2010 at 6:08pm

We made some objects for doing active and passive stereo. It’s a bit tricky to sequence the messaging, so we encapsulated it into a single object:

Cosm:

http://www.allosphere.ucsb.edu/cosm/

#74167

You must be logged in to reply to this topic.