Forums > MaxMSP

SceneProcess

January 13, 2006 | 10:56 pm

Hi List,
If you are like me, then you probably get tired of the clean edges and
sterility of the OpenGL view, but can’t afford to render to a matrix
because of frame rate loss. Well, this week’s example offers a remedy
to this bothersome conflict.

Since Jitter 1.5, we have a nice collection of texture-processing tools
(jit.gl.slab,jit.gl.texture,jit.gl.shader, and the jitter-shader
library). This allows the clever jitter user to do most of her
processing on the GPU, thus freeing up her CPU to do things like
generating clicks and beeps. This example uses the capture attribute of
jit.gl.objects to render the OpenGL scene to a texture (everything stays
on the GPU), which is then processed using some jit.gl.slab objects with
different shaders. For more excitement, I heartily recommend learning
to write your own shaders (most consist of only about 5 lines of code).

Enjoy the long weekend!
Happy Patching.
Andrew B.
Cycling ’74

max v2;
#N vpatcher 251 420 1651 865;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 1185 227 43 196617 $1 200;
#P newex 1185 246 40 196617 line 0.;
#P newex 1185 208 41 196617 * 0.01;
#P newex 1185 188 64 196617 random 100;
#P message 1120 227 43 196617 $1 200;
#P newex 1120 246 40 196617 line 0.;
#P newex 1120 208 41 196617 * 0.01;
#P newex 1120 188 64 196617 random 100;
#P message 1055 227 43 196617 $1 200;
#P newex 1055 246 40 196617 line 0.;
#P newex 1055 208 41 196617 * 0.01;
#P newex 1055 188 64 196617 random 100;
#P message 894 173 43 196617 $1 200;
#P newex 894 191 40 196617 line 0.;
#P newex 913 88 50 196617 qlim 300;
#P message 1033 73 287 196617 param srcdim 2. 10. 637. 480. , param
dstdim 0. 0. 640. 480.;
#P newex 526 38 48 196617 loadbang;
#P message 526 58 14 196617 0;
#P toggle 639 52 15 0;
#P newex 639 126 27 196617 + 1;
#P newex 639 154 38 196617 gate 2;
#P flonum 1137 282 38 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 1098 282 38 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 1055 282 42 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 1054 303 135 196617 pak param scale 1. 1. 1.;
#P newex 968 334 32 196617 print;
#P message 680 314 30 196617 read;
#P newex 667 334 300 196617 jit.gl.slab cracks @file cc.scalebias.jxs
@dim 320 240 @adapt 0;
#P message 725 253 67 196617 getparamlist;
#P message 693 253 30 196617 read;
#P newex 667 179 177 196617 jit.gl.slab cracks @file co.reflect.jxs;
#P newex 894 113 29 196617 gate;
#P number 194 256 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 194 276 56 196617 dim $1 $1;
#P newex 251 217 130 196617 jit.matrix 3 float32 20 20;
#P newex 251 236 184 196617 jit.slide @slide_up 50 @slide_down 50;
#P newex 251 142 56 196617 qlim 1500;
#P newex 894 154 41 196617 * 0.02;
#P newex 894 134 64 196617 random 200;
#P message 893 214 81 196617 param width $1;
#P newex 865 233 32 196617 print;
#P message 726 197 67 196617 getparamlist;
#P message 694 197 30 196617 read;
#P newex 667 383 203 196617 jit.gl.videoplane cracks @scale 1.333 1. 1.;
#P newex 667 233 197 196617 jit.gl.slab cracks @file cf.gaussian.2p.jxs;
#P newex 667 126 223 196617 jit.gl.texture cracks @name bob @dim 640 480;
#P newex 367 275 271 196617 jit.gl.handle cracks @inherit_transform 1
@auto_rotate 1;
#P message 367 256 34 196617 reset;
#P newex 251 256 115 196617 jit.dimmap @invert 1 1;
#P newex 251 276 91 196617 prepend ctlmatrix;
#P window linecount 2;
#P newex 251 303 308 196617 jit.gl.nurbs cracks @color 0.8 0.7 0.3 0.6
@capture bob @rotate 20. 60. 0. 0. @blend_enable 1 @poly_mode 1 0
@lighting_enable 1;
#P window linecount 1;
#P newex 7 64 74 196617 t erase b b b b;
#P newex 7 349 229 196617 jit.gl.render cracks @erase_color 0.2 0.1 0.1 1.;
#P newex 251 164 122 196617 jit.noise 3 float32 20 20;
#P newex 251 187 324 196617 jit.expr @expr "snorm[0]+0.1*jit.noise()"
"2*in[0]-0.9" "snorm[1]";
#P newex 59 44 162 196617 jit.window cracks @size 640 480;
#P toggle 6 24 15 0;
#P newex 6 44 51 196617 qmetro 5;
#P connect 1 0 0 0;
#P connect 0 0 6 0;
#P connect 6 0 5 0;
#P fasten 6 1 5 0 28 215 12 215;
#P connect 25 0 24 0;
#P fasten 6 2 21 0 44 111 256 111;
#P connect 21 0 4 0;
#P fasten 6 2 23 0 44 213 256 213;
#P connect 23 0 22 0;
#P connect 22 0 9 0;
#P connect 9 0 8 0;
#P fasten 11 0 7 0 372 296 256 296;
#P connect 8 0 7 0;
#P connect 24 0 7 0;
#P connect 10 0 11 0;
#P connect 41 0 40 0;
#P connect 39 0 38 0;
#P fasten 40 0 38 0 531 123 644 123;
#P connect 38 0 37 0;
#P fasten 6 3 12 0 60 100 672 100;
#P connect 12 0 37 1;
#P connect 37 1 27 0;
#P fasten 29 0 27 0 730 271 672 271;
#P fasten 28 0 27 0 698 271 672 271;
#P connect 27 0 13 0;
#P fasten 16 0 13 0 731 225 672 225;
#P fasten 18 0 13 0 898 229 672 229;
#P fasten 15 0 13 0 699 222 672 222;
#P connect 13 0 30 0;
#P fasten 33 0 30 0 1059 331 672 331;
#P fasten 31 0 30 0 685 331 672 331;
#P connect 30 0 14 0;
#P fasten 37 0 14 0 644 367 672 367;
#P fasten 30 0 27 1 672 352 839 352;
#P connect 13 1 17 0;
#P connect 44 0 18 0;
#P fasten 39 0 26 0 644 84 899 84;
#P connect 26 0 19 0;
#P connect 19 0 20 0;
#P connect 20 0 45 0;
#P connect 45 0 44 0;
#P fasten 6 4 43 0 76 84 918 84;
#P connect 43 0 26 1;
#P connect 30 1 32 0;
#P fasten 26 0 46 0 899 131 1060 131;
#P connect 46 0 47 0;
#P connect 47 0 49 0;
#P connect 49 0 48 0;
#P connect 48 0 34 0;
#P connect 52 0 35 0;
#P fasten 34 0 33 2 1060 299 1121 299;
#P fasten 26 0 50 0 902 131 1125 131;
#P connect 50 0 51 0;
#P connect 51 0 53 0;
#P connect 53 0 52 0;
#P connect 56 0 36 0;
#P fasten 35 0 33 3 1103 299 1152 299;
#P fasten 36 0 33 4 1142 299 1183 299;
#P fasten 26 0 54 0 900 131 1190 131;
#P connect 54 0 55 0;
#P connect 55 0 57 0;
#P connect 57 0 56 0;
#P pop;


January 13, 2006 | 11:07 pm

Sorry About That!

I posted a non-working version

This one will work(hopefully) ;)

Andrew B.

max v2;
#N vpatcher 79 555 1219 961;
#P origin -76 0;
#P setbglock 1;
#P window setfont "Sans Serif" 9.;
#P window linecount 4;
#P comment 541 335 371 196617 This patch demonstrates a technique for
doing matrix-style processing on an openGL scene without reading back to
the CPU. This allows you to add a variety of processing effects to your
live OpenGL patch without encountering much loss of frame rate. Another
incentive to look at those shaders…;
#P window linecount 1;
#P comment 951 348 169 196617 andrewb@cycling74.com;
#P comment 789 279 80 196617 scale_bias filter;
#P comment 609 179 132 196617 dodge composite (feedback);
#P comment 702 233 64 196617 gaussian blur;
#P comment 601 79 201 196617 this is our render destination for the nurbs;
#P user jit.fpsgui 34 351 60 196617 0;
#P flonum 624 113 42 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 624 133 88 196617 param amount $1;
#P newex 120 116 56 196617 qlim 1000;
#P newex 120 137 124 196617 jit.matrix 3 float32 10 5;
#P message 1053 155 43 196617 $1 400;
#P newex 1053 174 40 196617 line 0.;
#P newex 1053 136 41 196617 * 0.03;
#P newex 1053 116 64 196617 random 100;
#P message 988 155 43 196617 $1 400;
#P newex 988 174 40 196617 line 0.;
#P newex 988 136 41 196617 * 0.03;
#P newex 988 116 64 196617 random 100;
#P message 923 155 43 196617 $1 400;
#P newex 923 174 40 196617 line 0.;
#P newex 923 136 41 196617 * 0.03;
#P newex 923 116 64 196617 random 100;
#P message 814 154 43 196617 $1 400;
#P newex 814 172 40 196617 line 0.;
#P newex 833 69 50 196617 qlim 500;
#P hidden newex 491 15 48 196617 loadbang;
#P hidden message 491 35 14 196617 0;
#P toggle 541 14 47 0;
#P newex 541 107 27 196617 + 1;
#P newex 541 135 38 196617 gate 2;
#P flonum 1005 210 38 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 966 210 38 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 923 210 42 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 922 231 135 196617 pak param scale 1. 1. 1.;
#P newex 569 260 300 196617 jit.gl.slab cracks @file cc.scalebias.jxs
@dim 320 240 @adapt 0;
#P newex 569 160 171 196617 jit.gl.slab cracks @file co.dodge.jxs;
#P newex 814 94 29 196617 gate;
#P number 63 237 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 63 257 56 196617 dim $1 $1;
#P newex 120 198 177 196617 jit.matrix 3 float32 20 20 @interp 1;
#P newex 120 217 184 196617 jit.slide @slide_up 50 @slide_down 50;
#P newex 814 135 103 196617 expr $i1*0.02-0.01;
#P newex 814 115 64 196617 random 200;
#P message 813 195 81 196617 param width $1;
#P newex 569 288 203 196617 jit.gl.videoplane cracks @scale 1.333 1. 1.;
#P newex 569 214 197 196617 jit.gl.slab cracks @file cf.gaussian.2p.jxs;
#P newex 569 92 233 196617 jit.gl.texture cracks @name super @dim 640 480;
#P newex 236 256 271 196617 jit.gl.handle cracks @inherit_transform 1
@auto_rotate 1;
#P message 236 237 34 196617 reset;
#P newex 120 237 115 196617 jit.dimmap @invert 1 1;
#P newex 120 257 91 196617 prepend ctlmatrix;
#P window linecount 2;
#P newex 120 284 311 196617 jit.gl.nurbs cracks @color 0.8 0.7 0.3 0.6
@capture super @rotate 20. 60. 0. 0. @blend_enable 1 @poly_mode 1 0
@lighting_enable 1;
#P window linecount 1;
#P newex 34 45 74 196617 t erase b b b b;
#P newex 34 330 229 196617 jit.gl.render cracks @erase_color 0.2 0.1 0.1 1.;
#P window linecount 2;
#P newex 120 159 226 196617 jit.expr @expr
"jit.noise()*0.5-0.5+snorm[0]" "jit.noise()*4.-2." "snorm[1]" @cache 0;
#P window linecount 1;
#P newex 86 25 162 196617 jit.window cracks @size 640 480;
#P toggle 4 25 29 0;
#P newex 34 25 51 196617 qmetro 5;
#P window linecount 3;
#P comment 589 19 57 196617 turn on/off slab processing;
#P window setfont "Sans Serif" 24.;
#P window linecount 1;
#P comment 950 320 169 196632 SceneProcess;
#P user panel 0 0 538 389;
#X brgb 150 218 112;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P background;
#P user panel 537 0 587 389;
#X brgb 255 250 224;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P background;
#P hidden connect 5 0 4 0;
#P connect 4 0 9 0;
#P fasten 9 1 8 0 55 196 39 196;
#P connect 9 0 8 0;
#P connect 8 0 56 0;
#P connect 24 0 23 0;
#P fasten 9 2 53 0 71 111 125 111;
#P connect 53 0 52 0;
#P connect 52 0 7 0;
#P fasten 9 2 22 0 71 191 125 191;
#P connect 7 0 22 0;
#P connect 22 0 21 0;
#P connect 21 0 12 0;
#P connect 12 0 11 0;
#P fasten 14 0 10 0 241 277 125 277;
#P connect 11 0 10 0;
#P fasten 23 0 10 0 68 277 125 277;
#P connect 13 0 14 0;
#P hidden connect 36 0 35 0;
#P connect 34 0 33 0;
#P hidden fasten 35 0 33 0 496 104 546 104;
#P connect 33 0 32 0;
#P fasten 9 3 15 0 87 81 574 81;
#P connect 15 0 32 1;
#P fasten 54 0 26 0 629 155 574 155;
#P connect 32 1 26 0;
#P connect 26 0 16 0;
#P fasten 18 0 16 0 818 210 574 210;
#P fasten 28 0 27 0 927 255 574 255;
#P connect 16 0 27 0;
#P connect 27 0 17 0;
#P fasten 32 0 17 0 546 281 574 281;
#P connect 55 0 54 0;
#P fasten 27 0 26 1 574 281 561 281 561 155 735 155;
#P connect 38 0 18 0;
#P fasten 34 0 25 0 546 65 819 65;
#P connect 25 0 19 0;
#P connect 19 0 20 0;
#P connect 20 0 39 0;
#P connect 39 0 38 0;
#P hidden fasten 9 4 37 0 103 65 838 65;
#P connect 37 0 25 1;
#P fasten 25 0 40 0 819 112 928 112;
#P connect 40 0 41 0;
#P connect 41 0 43 0;
#P connect 43 0 42 0;
#P connect 42 0 29 0;
#P connect 46 0 30 0;
#P fasten 29 0 28 2 928 227 989 227;
#P fasten 25 0 44 0 822 112 993 112;
#P connect 44 0 45 0;
#P connect 45 0 47 0;
#P connect 47 0 46 0;
#P connect 50 0 31 0;
#P fasten 30 0 28 3 971 227 1020 227;
#P fasten 31 0 28 4 1010 227 1051 227;
#P fasten 25 0 48 0 820 112 1058 112;
#P connect 48 0 49 0;
#P connect 49 0 51 0;
#P connect 51 0 50 0;
#P pop;


January 16, 2006 | 3:43 am

Hi.

Question:

@capture only seems to work for one gl object. IE: if I have 2 gl
objects with @capture ‘destination’, then the texture named
destination seems to take the first gl object and render only that to
the texture. ie: capture is 1 to 1, one GL object one texture. This
makes sense to me, however:

Id like to ‘capture’ the whole scene. I know jit.gl.render has
to_texture, but I get this error when sending that message:

warning: method screen_grab called on invalid object

ive looked in the jitter examples, and in the html, and I see no
example of using it to capture a full scene to a texture. Whats the
best way to go about doing this? @caputure seems quite fast… Is
there any chance someone could throw a simple multi jit.gl.* patch
(say 3 jit.gl.models ) that are all captures to a texture which can
be slabbed all day long?

thanks for all the prior jitter example patches – they’ve been most
enlightening.

v a d e //

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


Viewing 3 posts - 1 through 3 (of 3 total)