Render To Texture Example

Jun 24, 2006 at 5:44am

Render To Texture Example

> and lastly, is it possible to render an entire scene to a texture now? Just curious, as it seems like > some things have been changed possibly wrt jitter. Not a big deal

Indeed it is possible now using the FBO backend. The pbuffer backend
has some issues in the public beta that will hopefully be addressed in
the future, but for now, FBOs work quite nicely. There are a few
things to note in the patch. First, pay attention to how
jit.gl.render’s @capture attribute is being used to both render to
texture and to the normal jit.window context. Second, notice the
glreadback message to jitter. There are two options given in patch:
fbo and rtt. fbo is FBO and rtt is pbuffer. You will probably get
stack overflow errors with the pbuffer setting.

The example is not so hot. I threw it together to show the mechanics
of it. To get more interesting effects, I would reccomend using
shaders to process the capture texture to get some alpha in the thing
for better feedback. Also something to note is that I’m rendering all
of the geometry to the FBO and to the jit.window. This requires
rendering everything twice. This doesn’t have to be the case. You
can render to just the FBO or just the jit.window.

best,
wes

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 450 360 210 196617 jit.gl.texture glfb @name cap @dim 720 480;
#P newex 529 218 98 196617 jit.gl.handle feedme;
#P newex 448 293 41 196617 r draw;
#P window linecount 2;
#P newex 448 314 220 196617 jit.gl.gridshape feedme @shape sphere
@color 0.2 0.2 0.8 0.5 @automatic 0 @blend_enable 1;
#P window linecount 1;
#P newex 448 234 41 196617 r draw;
#P window linecount 2;
#P newex 448 255 220 196617 jit.gl.gridshape feedme @shape torus
@color 0.8 0.2 0.2 0.5 @automatic 0 @blend_enable 1;
#P message 329 101 103 196617 ; jitter glreadback fbo;
#P message 329 66 102 196617 ; jitter glreadback rtt;
#P toggle 84 33 15 0;
#P window linecount 1;
#N vpatcher 20 74 209 234;
#P window setfont “Sans Serif” 9.;
#P window linecount 0;
#P newex 44 109 41 196617 s draw;
#P window linecount 1;
#P message 67 68 99 196617 capture none , erase;
#P newex 21 45 56 196617 t b draw b;
#P inlet 21 25 15 0;
#P outlet 67 88 15 0;
#P outlet 21 67 15 0;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P connect 3 1 5 0;
#P connect 3 2 4 0;
#P connect 4 0 1 0;
#P pop;
#P newobj 84 114 49 196617 p Screen;
#N vpatcher 80 358 267 524;
#P window setfont “Sans Serif” 9.;
#P message 66 69 94 196617 capture cap , erase;
#P newex 20 47 56 196617 t b draw b;
#P newex 43 109 41 196617 s draw;
#P inlet 20 27 15 0;
#P outlet 20 89 15 0;
#P outlet 66 89 15 0;
#P connect 2 0 4 0;
#P connect 4 0 1 0;
#P connect 4 1 3 0;
#P connect 4 2 5 0;
#P connect 5 0 0 0;
#P pop;
#P newobj 138 114 36 196617 p RTT;
#P newex 84 89 30 196617 t b b;
#P user jit.fpsgui 11 87 60 196617 0;
#P newex 82 288 41 196617 r draw;
#P message 239 231 70 196617 fullscreen $1;
#P toggle 222 231 15 0;
#P newex 264 206 35 196617 sel 27;
#P newex 222 206 40 196617 key;
#P window linecount 2;
#P newex 82 312 360 196617 jit.gl.gridshape feedme @shape sphere
@color 1. 1. 1. 0.8 @automatic 0 @blend_enable 1 @scale 4. 4. 0.5
@texture cap @position 0 0 -4 @tex_map 2;
#P window linecount 1;
#P newex 82 254 286 196617 jit.window feedme @depthbuffer 1 @fsmenubar
0 @floating 1;
#P newex 84 175 363 196617 jit.gl.render feedme @erase_color 0. 0. 0.
0.8 @name render1 @camera 0 0 3;
#P newex 84 51 57 196617 qmetro 20;
#P fasten 12 1 1 0 128 153 89 153;
#P connect 12 0 1 0;
#P fasten 11 0 1 0 143 153 89 153;
#P fasten 11 1 1 0 169 153 89 153;
#P connect 8 0 3 0;
#P connect 19 0 18 0;
#P connect 17 0 16 0;
#P connect 20 0 16 0;
#P connect 20 0 18 0;
#P fasten 0 0 9 0 89 81 16 81;
#P connect 0 0 10 0;
#P fasten 4 0 5 0 263 223 263 208;
#P fasten 6 0 7 0 238 246 238 231;
#P fasten 5 0 6 0 269 228 227 228;
#P fasten 10 1 11 0 109 110 143 110;
#P connect 10 0 12 0;
#P connect 13 0 0 0;
#P fasten 7 0 2 0 244 250 87 250;
#P window clipboard copycount 22;

#26540
Jun 26, 2006 at 2:09pm

On Jun 24, 2006, at 8:41 AM, vade wrote:

> This is big. Last night I finally figured out how to get to_texture
> working. For some reason I was simply blanking on it and couldnt
> get it working before. I did end up rendering twice, and erasing
> once I had captured to the texture but before I drew to the screen.
> Ugly hack. The first thing I did once I got it working was throw
> some jit.gl.slabs and imageunits at it. Goddamn, this is a new era ;)

Yes, to_texture now works properly (which is another way to
accomplish this besides the @capture/FBO solution). The texture will
also adapt to the viewport size if the @adapt attribute of
jit.gl.texture is enabled(is by default).

-Joshua

#79522
Jun 26, 2006 at 2:51pm

Thats exactly how I was using it – ill have to read up on FBO (is
there a performance difference at all or ? FBO isnt in my acronym
database ;)

Also I noticed that imageunits get cranky if you change the size of
the texture (as reported in the helpfile – id crash occasionally but
more likely id notice a huge drop in framerate and Max’s memory usage
would climb and climb – it seemed this would happen more in
@colormode uyvy.. ), but I really cant be any happier with this
functionality. Once things work smoothly, it will really make a huge
difference.

Ive already incorporated 1.6 features into my new patch and am
finding whole slews of new things to play with via slab chains and
imageunits that manipulate the whole render context – adding some
distortions/bump maps to the texuture really ‘unflattens’ openGL.

great work – seriously.

v a d e //

http://www.vade.info
abstrakt.vade.info

On Jun 26, 2006, at 10:09 AM, Joshua Kit Clayton wrote:

> Yes, to_texture now works properly (which is another way to
> accomplish this besides the @capture/FBO solution). The texture
> will also adapt to the viewport size if the @adapt attribute of
> jit.gl.texture is enabled(is by default).

#79523
Nov 20, 2006 at 9:48am

when running on an x800 ati xp swetup i get
jit.gl.readback.pbuffer: error creating pbuffer: GL Error: Invalid
enumeration

when running thru
;jitter glreadback rtt

On 6/26/06, vade wrote:
>
> Thats exactly how I was using it – ill have to read up on FBO (is there a
> performance difference at all or ? FBO isnt in my acronym database ;)
> Also I noticed that imageunits get cranky if you change the size of the
> texture (as reported in the helpfile – id crash occasionally but more likely
> id notice a huge drop in framerate and Max’s memory usage would climb and
> climb – it seemed this would happen more in @colormode uyvy.. ), but I
> really cant be any happier with this functionality. Once things work
> smoothly, it will really make a huge difference.
> Ive already incorporated 1.6 features into my new patch and am finding
> whole slews of new things to play with via slab chains and imageunits that
> manipulate the whole render context – adding some distortions/bump maps to
> the texuture really ‘unflattens’ openGL.
>
> great work – seriously.
> *
> *
> *
> *
> *v a d e //*
> *
> *
> *www.vade.info*
> *abstrakt.vade.info*
>
>
> On Jun 26, 2006, at 10:09 AM, Joshua Kit Clayton wrote:
>
> Yes, to_texture now works properly (which is another way to accomplish
> this besides the @capture/FBO solution). The texture will also adapt to
> the viewport size if the @adapt attribute of jit.gl.texture is enabled(is
> by default).
>
>
>
>
>
>

#79524
Nov 20, 2006 at 2:23pm

If you’re trying to do RTT, try this patch:

#P window setfont “Sans Serif” 9.;
#P user jit.fpsgui -3 128 60 196617 0;
#P toggle 127 42 15 0;
#P window linecount 1;
#P message 127 62 68 196617 fullscreen $1;
#N vpatcher 30 89 166 253;
#P window setfont “Sans Serif” 9.;
#P newex 50 71 35 196617 sel 27;
#P newex 50 50 40 196617 key;
#P outlet 50 93 15 0;
#P connect 1 0 2 0;
#P connect 2 0 0 0;
#P pop;
#P newobj 127 22 33 196617 p Esc;
#P button 22 50 15 0;
#P hidden newex 294 160 45 196617 loadbang;
#P newex 409 103 56 196617 loadmess 2;
#P newex 511 188 171 196617 jit.gl.slab cap @file co.additive.jxs;
#P newex 643 96 119 196617 sprintf read co.%s.jxs;
#P user ubumenu 598 75 100 196617 0 1 1 0;
#X add additive;
#X add average;
#X add brightlight;
#X add burn;
#X add darken;
#X add difference;
#X add dodge;
#X add exclude;
#X add freeze;
#X add glow;
#X add hardlight;
#X add heat;
#X add inverse;
#X add lighten;
#X add multiply;
#X add negate;
#X add overlay;
#X add reflect;
#X add screen;
#X add softlight;
#X add stamp;
#X add subtractive;
#X prefix_set 0 0 0;
#X pattrmode 1;
#P newex 409 189 27 196617 + 1;
#P user radiogroup 409 137 18 48;
#X size 3;
#X offset 16;
#X inactive 0;
#X itemtype 0;
#X flagmode 0;
#X set 2;
#X done;
#P newex 469 218 53 196617 switch 3 1;
#P newex 350 86 40 196617 t b b b;
#P newex 350 63 47 196617 r draw;
#P message 66 230 243 196617 reset , drawobject cube2 0 , drawobject
sphere2 0;
#P newex 55 254 307 196617 jit.gl.sketch cap @blend_enable 1 @capture
group2 @automatic 0;
#P comment 193 441 100 196617 group2;
#P window linecount 2;
#P newex 102 509 398 196617 jit.gl.gridshape cap @shape sphere @color
0.2 1 0. 0.6 @lighting_enable 1 @blend_enable 1 @smooth_shading 1
@automatic 0 @name sphere2 @depth_enable 0;
#P window linecount 3;
#P newex 102 460 322 196617 jit.gl.gridshape cap @shape cube @color 1
0.5 0.5 0.2 @lighting_enable 1 @blend_enable 1 @smooth_shading 1
@automatic 0 @name cube2 @depth_enable 1 @scale 0.5 1 0.5 @blend_mode
1 6;
#P window linecount 2;
#P newex 102 386 387 196617 jit.gl.gridshape cap @shape plane @color 1
1 0. 0.6 @lighting_enable 1 @blend_enable 1 @smooth_shading 1
@automatic 0 @name plane1 @depth_enable 0;
#P window linecount 1;
#P message 66 172 238 196617 reset , drawobject plane1 0 ,
drawobject torus1 0;
#P newex 56 196 307 196617 jit.gl.sketch cap @blend_enable 1 @capture
group1 @automatic 0;
#N vpatcher 25 70 242 240;
#P window setfont “Sans Serif” 9.;
#P window linecount 0;
#P newex 71 97 35 196617 s draw;
#P window linecount 1;
#P newex 50 50 53 196617 t b b erase;
#P inlet 50 30 15 0;
#P outlet 92 74 15 0;
#P outlet 50 74 15 0;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P connect 3 1 4 0;
#P connect 3 2 1 0;
#P pop;
#P newobj 58 82 37 196617 p Draw;
#P window linecount 2;
#P newex 102 348 391 196617 jit.gl.gridshape cap @shape torus @color 1
0 0.5 0.6 @lighting_enable 1 @blend_enable 1 @smooth_shading 1
@automatic 0 @name torus1 @depth_enable 1;
#P window linecount 1;
#P newex 469 260 173 196617 jit.gl.videoplane cap @scale 2.66 2;
#P newex 653 151 224 196617 jit.gl.texture cap @name group2 @dim 720 480;
#P newex 483 151 224 196617 jit.gl.texture cap @name group1 @dim 720 480;
#P newex 127 82 84 196617 jit.window cap;
#P toggle 58 34 15 0;
#P newex 58 112 158 196617 jit.gl.render cap @camera 0 0 4;
#P newex 58 58 64 196617 qmetro 30;
#P comment 190 327 100 196617 group1;
#P connect 9 0 32 0;
#P connect 9 0 2 0;
#P fasten 6 0 20 2 658 175 502 175;
#P connect 6 0 25 1;
#P fasten 19 0 5 0 355 128 488 128;
#P fasten 19 0 6 0 355 128 658 128;
#P connect 23 1 24 0;
#P connect 25 0 20 3;
#P fasten 24 0 25 0 648 180 516 180;
#P connect 5 0 20 1;
#P fasten 5 0 25 0 488 180 516 180;
#P connect 20 0 7 0;
#P fasten 22 0 20 0 414 212 474 212;
#P connect 21 0 22 0;
#P connect 26 0 21 0;
#P connect 18 0 19 0;
#P connect 30 0 4 0;
#P connect 31 0 30 0;
#P connect 29 0 31 0;
#P hidden connect 27 0 17 0;
#P hidden connect 27 0 11 0;
#P fasten 9 1 2 0 90 106 63 106;
#P connect 1 0 9 0;
#P connect 28 0 9 0;
#P connect 3 0 1 0;
#P connect 11 0 10 0;
#P fasten 19 1 10 0 370 150 61 150;
#P connect 17 0 16 0;
#P fasten 19 2 16 0 385 223 60 223;
#P window clipboard copycount 33;

#79525

You must be logged in to reply to this topic.