Forums > Jitter

Render to Matrix via javascript with jit.gl.render quality 1

May 31, 2006 | 3:41 am

Hello, I am trying to render to a matrix via javascript with the OS X
software openGL rendering engine (works), but I cannot enable any
FSAA/antialiasing, so my output looks .. well, very aliased.

Ive searched the archives and noted JKC’s note about enabling high
quality (quality=1) to the jit.gl.render instance in the javascript.
I have attempted to do so in the code below, but still get my aliased
output.

Could someone shed some light. Im pretty sure im doing something
wrong, as my procedural coding is weak.

Thanks, example patch and JS included below. BTW, Max 4.5.7, Jitter
1.5.2, OS X 10.4.6, QT 7.1. Yay acronyms.

//// patch//

max v2;
#N vpatcher 615 406 1215 806;
#P window setfont "Sans Serif" 9.;
#P newex 25 233 190 196617 jit.window output @floating 1 @interp 1;
#P user jit.fpsgui 104 196 60 196617 0;
#P newex 25 163 198 196617 jit.matrix simple_matrix 4 char 320 240;
#P toggle 277 91 15 0;
#P message 335 147 65 196617 autowatch 1;
#P newex 277 175 78 196617 js 2_Circles.js;
#P newex 277 114 51 196617 qmetro 2;
#P connect 0 0 4 0;
#P connect 4 0 6 0;
#P connect 4 0 5 0;
#P connect 3 0 0 0;
#P connect 0 0 1 0;
#P fasten 2 0 1 0 340 169 282 169;
#P pop;

///////// js save as 2_Circle.js ////

// setup a jitter openGL renderer to render to our simple_matrix
var myRender = new JitterObject("jit.gl.render", "simple_matrix");

// setup a jit.gl.sketch object that we will do our drawing with…
var mySketch = new JitterObject("jit.gl.sketch", "simple_matrix");

// our replacement for frameCount from Processing, our timer.
var timer=0;

myRender.quality=1;
mySketch.depth_enable=0;
mySketch.antialias=1;

function bang()
{
// our jit.gl.render’s rendering commands.
myRender.erase();

// our drawing routine we ‘ported’ from Processing..
draw();

myRender.drawclients();
myRender.swap();

// increment our timer… since we dont have a ‘frameCount’ like in
processing
timer++;

// clear the command list for jit.gl.sketch, so we dont bog down
over time.
mySketch.reset();
}

function draw()
{
mySketch.moveto(0.0, 0.0, 0.0);
mySketch.glcolor(1,1,1,1);

mySketch.glpushmatrix();
mySketch.glrotate(timer*0.1, 0,0, 1);
mySketch.circle(0.5);
mySketch.moveto(0.0, 0.05, 0.0);
mySketch.glcolor(1,0,0,1);
mySketch.circle(0.45);
mySketch.glpopmatrix();

}

//////// end js /////////

v a d e //

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


May 31, 2006 | 9:37 pm

Ah, I missed this message in the archives:

Subject: Re: [max-msp] fsaa and offscreen rendering

Which pretty much covers what I wanted to do. Seems the solution is
simply to render to a higher res matrix and interpolate down. Oh well.

v a d e //

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


May 31, 2006 | 10:42 pm

On May 30, 2006, at 8:41 PM, vade wrote:

> Hello, I am trying to render to a matrix via javascript with the OS
> X software openGL rendering engine (works), but I cannot enable any
> FSAA/antialiasing, so my output looks .. well, very aliased.

jit.gl.render @antialias, just refers to line antialiasing. What you
want is multi-sampling for FSAA, which isn’t currently exposed when
rendering into RAM (since traditionally it hasn’t been supported).
However, multisampling is supported as of 10.4 and higher with
Apple’s slower, but higher quality software renderer, and we can look
at adding this in a future version.

In the meantime, and for all other platforms, I would recommend
rendering at 4x resolution and perform an averaging downsample (which
is what JSUI does). It might even be faster than the slow, but high
quality Apple software renderer with multisampling enabled. I haven’t
tested.

You can averaging downsample with the following chain jit.demultiplex-
> jit.op @op avg-> jit.demultiplex @demultiplexdim 1->jit.op @op avg.

Hope this helps.

-Joshua


June 2, 2006 | 4:42 am

Hi. I humbly submit a potential solution for people wanting to render
to a matrix via openGL but who have run into the same sorts of issues
discussed in this thread. The following patch is a workaround using a
hidden render context and GPU->Matrix readback via jit.gl.slab, and
@capture to render geometry to a texture. The patch allows the use of
antialiasing, and it seems like FSAA is working as well.

Id love feedback (esp from the hardcore openGL folks). This may seem
like an obvious way of doing it, but it was a eureka moment for me..
anyway Im particularly pleased with this solution, as it offers a lot
of options. My reasoning for doing this is to be able to port some
procedural drawing code written in Processing, render it using
jit.gl.sketch and then play with it in ‘matrix land’. Fun stuff.

max v2;
#N vpatcher 213 101 1246 761;
#P window setfont "Sans Serif" 9.;
#P message 235 50 102 196617 drawobject griddy 2;
#P window linecount 2;
#P newex 504 108 392 196617 jit.gl.gridshape invisiblecontext @shape
@shape torus @depth_enable 1 @lighting_enable 1 @blend_enable 1
@smooth_shading 1 @name griddy @automatic 0;
#P window linecount 1;
#P newex 187 545 27 196617 + 1;
#P newex 157 544 27 196617 !- 1;
#P toggle 157 527 15 0;
#P message 217 546 76 196617 outputmode $1;
#P newex 187 503 27 196617 + 1;
#P newex 157 502 27 196617 !- 1;
#P toggle 157 485 15 0;
#P message 217 504 76 196617 outputmode $1;
#P toggle 318 326 15 0;
#P flonum 323 239 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 322 258 84 196617 color 1. 1. 1. $1;
#P window linecount 2;
#P comment 370 501 100 196617 now we can use jitter processing…;
#P window linecount 1;
#P newex 520 373 43 196617 r bangs;
#P newex 296 545 160 196617 jit.repos @mode 1 @boundmode 4;
#B color 5;
#P newex 520 473 220 196617 jit.tiffany @grid 0 @xrange 0.9 @yrange 0.9;
#B color 5;
#P newex 520 450 68 196617 jit.op @op >>;
#P newex 634 424 97 196617 jit.noise 2 char 3 3;
#P newex 520 424 109 196617 jit.noise 2 char 10 10;
#P newex 356 457 43 196617 r bangs;
#P window linecount 6;
#P comment 774 425 176 196617 You might be wondering why the hell
anyone would want to render to a matrix.. well , flexibility mainly
, the ability to use all of the jitter objects , feedback , etc on
procedural animations useing openGL.;
#P window linecount 1;
#P comment 115 380 115 196617 to our invisible context;
#P newex 296 162 43 196617 r bangs;
#P newex 58 123 43 196617 s bangs;
#P window linecount 9;
#P comment 773 180 197 196617 This patch is a solution to rendering
openGl directly to a matrix. Typically , one has to use a software
renderer if one wants to render to a matrix. The Apple software
renderer has two modes , quality 1 and quality 0. Quality 0 is
faster , but supports little functionality. Quality one is *slow* ,
but allows one to render with alpha channels , but no aliasing
support.;
#P window linecount 1;
#P message 401 457 30 196617 read;
#P newex 356 479 63 196617 jit.qt.movie;
#P newex 296 503 70 196617 jit.alphablend;
#P newex 318 343 29 196617 gate;
#P message 145 62 87 196617 color 1. 0. 0. 0.8;
#P user jit.pwindow 317 384 82 62 0 1 0 0 1 0;
#P newex 318 364 66 196617 jit.unpack 4;
#P message 92 79 34 196617 reset;
#P message 159 79 81 196617 framecircle 1.1;
#P message 241 79 73 196617 ellipse 0.1 0.4;
#P message 316 79 55 196617 sphere 0.5;
#P message 309 187 68 196617 dim 320 240;
#P newex 296 276 186 196617 jit.gl.slab invisiblecontext @antialias 1;
#P message 41 258 118 196617 erase_color 0. 0. 0. 0.2;
#P toggle 10 363 15 0;
#P message 10 381 44 196617 fsaa $1;
#P newex 296 300 55 196617 jit.matrix;
#P message 387 187 68 196617 dim 640 480;
#P newex 296 573 91 196617 jit.window visible;
#P newex 296 212 374 196617 jit.gl.texture invisiblecontext @name
rendertex @dim 320 240 240 @antialias 1;
#P newex 374 78 92 196617 pak rotate 1 1 0 1;
#P message 394 39 68 196617 0 , 360 4000;
#P newex 394 57 40 196617 line;
#P message 133 44 85 196617 reset , circle 0.5;
#P window linecount 2;
#P newex 133 108 365 196617 jit.gl.sketch invisiblecontext @name
sketch @depth_enable 0 @smooth_shading 1 @lighting_enable 1
@blend_enable 1 @antialias 1 @capture rendertex;
#P user jit.fpsgui 10 312 60 196617 0;
#P toggle 10 64 15 0;
#P toggle 55 363 15 0;
#P window linecount 1;
#P message 55 381 55 196617 visible $1;
#P newex 10 102 58 196617 t erase b b;
#P newex 10 288 140 196617 jit.gl.render invisiblecontext;
#P newex 10 401 222 196617 jit.window invisiblecontext @visible 0
@fsaa 1;
#P newex 10 82 51 196617 qmetro 2;
#P window linecount 2;
#P comment 400 386 100 196617 look ma , alpha channels;
#P window linecount 7;
#P comment 773 316 176 196617 This approach uses a hidden hardware
accelerated render context , and uses the render to texture ( @
capture) methodology to render a jit.gl.sketch object to a texture ,
which is then read back to a matrix on the CPU with alpha channels
and all.;
#P window linecount 1;
#P comment 156 290 100 196617 render in hardware;
#P connect 9 0 3 0;
#P connect 3 0 6 0;
#P connect 22 0 5 0;
#P connect 6 0 5 0;
#P connect 6 1 5 0;
#P connect 5 0 10 0;
#P connect 21 0 20 0;
#P connect 7 0 4 0;
#P connect 20 0 4 0;
#P connect 8 0 7 0;
#P connect 6 2 37 0;
#P fasten 61 0 11 0 240 101 138 101;
#P fasten 27 0 11 0 164 101 138 101;
#P fasten 26 0 11 0 246 101 138 101;
#P connect 25 0 11 0;
#P fasten 12 0 11 0 138 81 138 81;
#P fasten 15 0 11 0 379 101 138 101;
#P fasten 28 0 11 0 97 101 138 101;
#P fasten 31 0 11 0 150 90 138 90;
#P connect 53 0 54 0;
#P connect 57 0 58 0;
#P fasten 54 0 55 0 162 520 185 520 185 500 192 500;
#P fasten 58 0 59 0 162 562 185 562 185 542 192 542;
#P fasten 55 0 52 0 192 521 215 521 215 501 222 501;
#P fasten 59 0 56 0 192 563 215 563 215 543 222 543;
#P connect 18 0 16 0;
#P connect 24 0 16 0;
#P connect 38 0 16 0;
#P connect 49 0 23 0;
#P connect 16 0 23 0;
#P connect 23 0 19 0;
#P connect 19 0 33 0;
#P fasten 52 0 33 0 224 521 294 521 294 500 301 500;
#P connect 33 0 46 0;
#P fasten 56 0 46 0 222 565 294 565 294 543 301 543;
#P connect 46 0 17 0;
#P connect 51 0 32 0;
#P connect 32 0 29 0;
#P connect 29 0 30 0;
#P connect 50 0 49 0;
#P fasten 19 0 32 1 301 321 342 321;
#P fasten 35 0 34 0 406 476 361 476;
#P connect 41 0 34 0;
#P connect 34 0 33 1;
#P connect 13 1 14 0;
#P connect 14 0 13 0;
#P connect 13 0 15 1;
#P fasten 45 0 46 1 525 513 451 513;
#P connect 47 0 42 0;
#P fasten 42 0 44 0 525 445 525 445;
#P fasten 44 0 45 0 525 475 525 475;
#P fasten 43 0 44 1 639 448 583 448;
#P connect 47 0 43 0;
#P pop;

v a d e //

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


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