Render erase color

Mar 23, 2008 at 2:03am

Render erase color

I need to render a few opengl objects to different render objects and then view them all in the same window. I want to have erase color control of each opengl object separately. Can someone please show me how to do this.

Thanx

#36470
Mar 23, 2008 at 2:34am

Render to texture. Search the forums about this subject, all will be
revealed … (you can render each object to a texture with a
different background color by drawing a quad first on each draw pass).
wes

On Sat, Mar 22, 2008 at 7:03 PM, Mike wrote:
>
> I need to render a few opengl objects to different render objects and then view them all in the same window. I want to have erase color control of each opengl object separately. Can someone please show me how to do this.
>
> Thanx
>
>
>
>

#125209
Mar 23, 2008 at 6:38pm

Ah I see what your saying. However i was wanting to take advantage of the delayed erase time in the renderer. I like the effect. Is there a way of using this separately on each grideshape?

#125210
Mar 23, 2008 at 7:05pm

You can use a shader in a feedback network to accomplish the same
effect. I’ve made a shader called co.accum.jxs that does this.
Here’s a patch and shader.

wes

#P window setfont “Sans Serif” 9.;
#P flonum 544 295 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 544 315 137 196617 param erase_color 0 0 0 $1;
#P flonum 201 293 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 201 313 137 196617 param erase_color 0 0 0 $1;
#P newex 404 388 74 196617 jit.gl.slab test;
#P newex 374 369 162 196617 jit.gl.slab test @file co.accum.jxs;
#P newex 71 385 74 196617 jit.gl.slab test;
#P newex 41 366 162 196617 jit.gl.slab test @file co.accum.jxs;
#P newex 374 318 41 196617 r draw;
#P window linecount 2;
#P newex 374 414 268 196617 jit.gl.videoplane test @transform_reset 2
@depth_enable 0 @blend_enable 1 @blend_mode 6 1 @position 0.1 0.1 0;
#P newex 41 414 275 196617 jit.gl.videoplane test @transform_reset 2
@depth_enable 0 @blend_enable 1 @blend_mode 6 1 @position -0.1 -0.1 0;
#P window linecount 1;
#P newex 41 314 41 196617 r draw;
#P newex 273 234 48 196617 loadbang;
#P message 337 261 207 196617 reset , drawobject vp2 0 , drawobject gs2 0;
#P newex 337 282 144 196617 jit.gl.sketch test @capture c2;
#P message 38 261 207 196617 reset , drawobject vp1 0 , drawobject gs1 0;
#P newex 38 282 144 196617 jit.gl.sketch test @capture c1;
#P window linecount 2;
#P newex 32 181 293 196617 jit.gl.gridshape test @shape plane @dim 2 2
@transform_reset 2 @color 0 1 0 1 @depth_enable 0 @name vp1 @automatic
0;
#P newex 337 181 293 196617 jit.gl.gridshape test @shape plane @dim 2
2 @transform_reset 2 @color 0 0 1 1 @depth_enable 0 @name vp2
@automatic 0;
#P window linecount 1;
#P newex 41 337 213 196617 jit.gl.texture test @name c1 @dim 1024 768;
#P window linecount 2;
#P newex 337 216 238 196617 jit.gl.gridshape test @shape opencylinder
@color 1 1 0 1 @lighting_enable 1 @name gs2 @automatic 0;
#P newex 32 216 223 196617 jit.gl.gridshape test @shape torus @color 1
0 0 1 @lighting_enable 1 @name gs1 @automatic 0;
#P window linecount 1;
#P message 154 82 34 196617 reset;
#P newex 154 102 186 196617 jit.gl.handle test @inherit_transform 1;
#P newex 19 102 48 196617 r render;
#P toggle 134 73 15 0;
#N vpatcher 53 128 279 297;
#P inlet 106 30 15 0;
#P window setfont “Sans Serif” 9.;
#P window linecount 0;
#P newex 43 95 47 196617 gate 1 1;
#P newex 43 116 41 196617 s draw;
#P window linecount 1;
#P newex 17 52 58 196617 t b b erase;
#P inlet 17 32 15 0;
#P outlet 17 83 15 0;
#P connect 1 0 2 0;
#P connect 2 0 0 0;
#P fasten 2 2 0 0 70 75 22 75;
#P fasten 5 0 4 0 111 88 48 88;
#P connect 4 0 3 0;
#P fasten 2 1 4 1 46 83 85 83;
#P lcolor 15;
#P pop;
#P newobj 72 102 42 196617 p Draw;
#P toggle 210 41 15 0;
#P message 210 61 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 227 41 33 196617 p Esc;
#P newex 210 79 151 196617 jit.window test @depthbuffer 1;
#P toggle 72 54 15 0;
#P newex 72 73 57 196617 qmetro 30;
#P newex 72 129 187 196617 jit.gl.render test @erase_color 0 0 0 1;
#P newex 374 341 216 196617 jit.gl.texture test @name c2 @dim 1024 768;
#P connect 22 0 19 0;
#P connect 19 0 18 0;
#P connect 23 0 15 0;
#P connect 15 0 27 0;
#P connect 31 0 27 0;
#P connect 27 0 24 0;
#P connect 27 0 28 0;
#P connect 3 0 2 0;
#P connect 2 0 8 0;
#P fasten 10 0 1 0 24 124 77 124;
#P connect 8 0 1 0;
#P fasten 11 0 1 0 159 124 77 124;
#P fasten 9 0 8 1 139 95 109 95;
#P connect 12 0 11 0;
#P connect 28 0 27 1;
#P connect 32 0 31 0;
#P connect 5 0 7 0;
#P connect 7 0 6 0;
#P connect 6 0 4 0;
#P connect 22 0 21 0;
#P connect 21 0 20 0;
#P connect 26 0 0 0;
#P connect 0 0 29 0;
#P connect 33 0 29 0;
#P connect 29 0 25 0;
#P connect 29 0 30 0;
#P connect 30 0 29 1;
#P connect 34 0 33 0;
#P window clipboard copycount 35;



Accumulator

fade amount




< ![CDATA[

// texcoords
varying vec2 texcoord0;
varying vec2 texcoord1;

// samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

// accum amount
uniform vec4 erase_color;

// entry point
void main()
{
vec4 current = texture2DRect(tex0, texcoord0);
vec4 previous = texture2DRect(tex1, texcoord1);

//simulation of jit.gl.render’s @erase_color attribute
vec4 framebuffer = mix(previous, erase_color, erase_color.a);

gl_FragColor = framebuffer + current;
// gl_FragColor = framebuffer;
}

]]>

#125211
Mar 23, 2008 at 8:29pm

BTW, in the patch I posted, you don’t even need the background quads.
You can just use the erase_color shader parameter to set the
background color.

wes

#125212
Mar 23, 2008 at 10:45pm

thanx man. great work

mike

#125213
Mar 25, 2008 at 12:01am

Hey Wes?

Im trying to use your shader but am having some issues with the code.

can you check it for me and tell me what Im missing. Below is the code and the error message i get from max window.

thanx


Shader to emulate render erase color


< ![CDATA[

// texcoords
varying vec2 texcoord0;
varying vec2 texcoord1;

// samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

// accum amount
uniform vec4 erase_color;

// entry point
void main()

{

vec4 current = texture2DRect(tex0, texcoord0);
vec4 previous = texture2DRect(tex1, texcoord1);

//simulation of jit.gl.render’s @erase_color attribute
vec4 framebuffer = mix(previous, erase_color, erase_color.a);

gl_FragColor = framebuffer + current;
// gl_FragColor = framebuffer;}

]]>

jit.gl.render: building GL on window “test”…
• error: — START GLSL INFO LOG:
ERROR: 0:1: ‘+’ : syntax error parse error
ERROR: Parser found no code to compile in source strings.
• error: — END GLSL INFO LOG:

• error: jit.gl.shader: GLSL program failed to compile.
• error: — START GLSL INFO LOG:

ERROR: 0:1: ‘kSO’ : syntax error parse error
ERROR: Parser found no code to compile in source strings.
• error: — END GLSL INFO LOG:

• error: jit.gl.shader: GLSL program failed to compile.

#125214
Mar 25, 2008 at 12:47am

#125215
Mar 25, 2008 at 1:27am

here is the error message and the attached shader file

jit.gl.render: building GL on window “test”…
• error: — START GLSL INFO LOG:
ERROR: 0:1: ‘+’ : syntax error parse error
ERROR: Parser found no code to compile in source strings.
• error: — END GLSL INFO LOG:

• error: jit.gl.shader: GLSL program failed to compile.
• error: — START GLSL INFO LOG:

ERROR: 0:1: ‘kSO’ : syntax error parse error
ERROR: Parser found no code to compile in source strings.
• error: — END GLSL INFO LOG:

• error: jit.gl.shader: GLSL program failed to compile.

#125216
Mar 25, 2008 at 2:26am

#125217
Mar 28, 2008 at 7:01pm

Hey Wes,
sorry but your attachment is not there. Can you send it to me again please.

regards mike

#125218
Mar 28, 2008 at 9:28pm
#125219
Mar 29, 2008 at 12:45am

thanx a bunch

#125220
Apr 3, 2008 at 7:55pm

When I try to use your co.accum.jsx shader I get this message.

error: jit_xml_document: error reading file at byte offset 1079 / no element found

error: line (44):

error: jit.gl.shader: error reading shader xml file ‘C:/Program Files/Cycling ’74/MaxMSP 4.6/Cycling ’74/jitter-shaders/composite/co.accum.jxs’

Whats going on?

Ive attached a patch so you can show me how to use it.

max v2;
#N vpatcher 74 41 1244 904;
#P window setfont “Sans Serif” 9.;
#P newex 30 213 33 9109513 r draw;
#P objectname receive[2];
#P number 69 184 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname number[1];
#P message 69 206 56 9109513 dim $1 $1;
#P newex 635 135 284 9109513 jit.window cymon @depthbuffer 1 @fsaa 6 @border 1 @floating 1;
#P objectname jit.window;
#P newex 69 291 54 9109513 s lowshape;
#P newex 2 477 66 9109513 r lowshape;
#P objectname receive[1];
#P flonum 243 428 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname flonum[18];
#P flonum 201 428 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname flonum[17];
#P flonum 161 428 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname flonum[16];
#P newex 181 455 86 9109513 pak scale 0 0 0;
#P flonum 246 366 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname flonum[9];
#P flonum 206 366 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname flonum[8];
#P flonum 166 366 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname flonum[7];
#P newex 165 388 96 9109513 pak position 0 0 0;
#P number 105 428 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname number[3];
#P number 67 428 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname number[2];
#P newex 67 455 106 9109513 pak blend_mode 0 0;
#P toggle 290 366 14 0;
#P objectname toggle[5];
#P message 261 388 85 9109513 auto_normals $1;
#P toggle 171 322 15 0;
#P objectname toggle[4];
#P message 171 341 94 9109513 smooth_shading $1;
#P toggle 270 322 15 0;
#P objectname toggle[3];
#P message 270 341 90 9109513 lighting_enable $1;
#P window linecount 2;
#P newex 67 498 343 9109513 jit.gl.mesh cymon @blend_enable 1 @viewalign 1 @scale 1. 1 1 @depth_enable 1 @draw_mode tri_grid @lighting_enable 1 @color 1. 1. 1. 1. @auto_normals 1;
#P objectname jit.gl.mesh;
#P window linecount 1;
#P newex 69 265 115 9109513 jit.matrix 12 float32 20 20;
#P newex 69 240 290 9109513 jit.gl.gridshape @shape sphere @matrixoutput 1 @automatic 0;
#P newex 67 580 77 9109513 jit.gl.slab cymon;
#P objectname jit.gl.slab[2];
#P newex 501 118 418 9109513 jit.gl.videoplane cymon @automatic 0 @name scene_plane @transform_reset 2 @texture sc_tex;
#P objectname jit.gl.videoplane;
#P newex 764 101 155 9109513 jit.gl.texture cymon @name sc_tex;
#P objectname jit.gl.texture;
#N vpatcher 428 389 1028 789;
#P window setfont “Sans Serif” 9.;
#P message 184 153 142 9109513 reset , drawobject scene_plane 0;
#P newex 184 173 129 9109513 jit.gl.sketch test @layer 2;
#P newex 26 54 48 9109513 loadbang;
#P message 183 86 125 9109513 reset , drawobject low_scene;
#P newex 183 106 208 9109513 jit.gl.sketch test @layer 1 @capture sc_tex;
#P fasten 2 0 1 0 31 77 188 77;
#P connect 1 0 0 0;
#P fasten 2 0 4 0 31 127 189 127;
#P connect 4 0 3 0;
#P pop 1;
#P newobj 848 83 71 9109513 p rendermaster;
#P newex 81 94 35 9109513 s draw;
#P objectname receive[13];
#P message 263 53 29 9109513 reset;
#P newex 263 77 292 9109513 jit.gl.handle cymon @inherit_transform 1 @auto_rotate 1 @visible 0;
#P objectname handle;
#P newex 71 68 56 9109513 t b b erase;
#P newex 71 118 339 9109513 jit.gl.render cymon @erase_color 0. 0. 0. 1. @depth_enable 1 @blend_enable 1;
#P objectname jit.gl.render;
#P toggle 71 28 15 0;
#P objectname toggle;
#P newex 71 47 50 9109513 qmetro 30;
#P window linecount 3;
#P newex 67 608 194 9109513 jit.gl.videoplane cymon @automatic 0 @blend_enable 1 @transform_reset 2 @depth_enable 1 @name low_scene;
#P objectname jit.gl.videoplane[3];
#P window setfont “Sans Serif” 24.;
#P window linecount 1;
#P comment 268 622 767 9109528 ?????????????? How do I apply a shader to this ???????????????;
#P connect 33 0 15 0;
#P connect 29 0 15 0;
#P connect 25 0 15 0;
#P connect 22 0 15 0;
#P hidden connect 16 0 15 0;
#P hidden connect 18 0 15 0;
#P connect 20 0 15 0;
#P connect 12 0 1 0;
#P connect 37 0 36 0;
#P connect 36 0 13 0;
#P connect 38 0 13 0;
#P connect 36 0 14 0;
#P connect 13 0 14 0;
#P connect 14 0 34 0;
#P connect 3 0 2 0;
#P connect 2 0 5 0;
#P hidden fasten 6 0 4 0 268 116 76 116;
#P connect 5 0 4 0;
#P fasten 5 2 4 0 122 117 76 117;
#P connect 5 1 8 0;
#P connect 23 0 22 1;
#P connect 24 0 22 2;
#P connect 19 0 18 0;
#P connect 26 0 25 1;
#P connect 30 0 29 1;
#P connect 27 0 25 2;
#P connect 31 0 29 2;
#P connect 28 0 25 3;
#P connect 32 0 29 3;
#P connect 21 0 20 0;
#P connect 7 0 6 0;
#P connect 17 0 16 0;
#P pop;

Thanks wes

#125221
Apr 3, 2008 at 8:41pm

The trouble seems to lay in the mesh. How can I get what is outputted from the mesh to a videoplane so that I can put a shader on it?

#125222
Apr 3, 2008 at 10:03pm

@capture on the gl.mesh.

please see the Scene Process jitter recipe. all the answers are there.

#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 connect 49 0 48 0;
#P connect 47 0 49 0;
#P connect 46 0 47 0;
#P connect 23 0 17 0;
#P fasten 23 0 38 0 819 112 928 112;
#P fasten 23 0 42 0 822 112 993 112;
#P fasten 23 0 46 0 820 112 1058 112;
#P fasten 29 0 26 4 1010 227 1051 227;
#P fasten 28 0 26 3 971 227 1020 227;
#P connect 48 0 29 0;
#P connect 45 0 44 0;
#P connect 43 0 45 0;
#P connect 42 0 43 0;
#P fasten 27 0 26 2 928 227 989 227;
#P connect 44 0 28 0;
#P connect 40 0 27 0;
#P connect 41 0 40 0;
#P connect 39 0 41 0;
#P connect 38 0 39 0;
#P connect 35 0 23 1;
#P hidden fasten 7 4 35 0 103 65 838 65;
#P connect 37 0 36 0;
#P connect 18 0 37 0;
#P connect 17 0 18 0;
#P connect 32 0 31 0;
#P fasten 32 0 23 0 546 65 819 65;
#P connect 36 0 16 0;
#P connect 25 0 15 0;
#P fasten 25 0 24 1 574 281 561 281 561 155 735 155;
#P connect 53 0 52 0;
#P fasten 30 0 15 0 546 281 574 281;
#P connect 14 0 25 0;
#P fasten 26 0 25 0 927 255 574 255;
#P fasten 16 0 14 0 818 210 574 210;
#P connect 24 0 14 0;
#P connect 30 1 24 0;
#P fasten 52 0 24 0 629 155 574 155;
#P connect 13 0 30 1;
#P fasten 7 3 13 0 87 81 574 81;
#P connect 31 0 30 0;
#P hidden fasten 33 0 31 0 496 104 546 104;
#P hidden connect 34 0 33 0;
#P connect 11 0 12 0;
#P fasten 21 0 8 0 68 277 125 277;
#P connect 9 0 8 0;
#P fasten 12 0 8 0 241 277 125 277;
#P connect 10 0 9 0;
#P connect 19 0 10 0;
#P connect 20 0 19 0;
#P connect 5 0 20 0;
#P fasten 7 2 51 0 71 111 125 111;
#P fasten 7 2 20 0 71 191 125 191;
#P connect 50 0 5 0;
#P connect 51 0 50 0;
#P connect 22 0 21 0;
#P connect 6 0 54 0;
#P connect 7 0 6 0;
#P fasten 7 1 6 0 55 196 39 196;
#P connect 2 0 7 0;
#P hidden connect 3 0 2 0;
#P window clipboard copycount 61;

#125223
Apr 3, 2008 at 10:18pm

Cool. Just wondering if there is a sketch drawing command like the drawobject that can be used to capture jit.gl.mesh?

#125224

You must be logged in to reply to this topic.