Anaglyph vision
Hello,
I'm searching to convert a 3D space in anaglyph vision (red/blue glasses) with jitter. I found this post in the Mailing List Archives :https://cycling74.com/forums/index.php?t=msg&goto=31071&rid=0&srch=anaglyph#msg_31071
The patch made by pseudostereo works fine. But my problem is that i don't want to use the jit.matrix object because I need a good résolution. I've got a lot of 3D objects moving in real time and, when I' put the jit.matrix in 1024*768, it works slowly.
Is it possible to found a solution with directly working with the jit.gl.render object ?
(yeah, that's a very old patch that you dug up...)
Here's a better way to do it. Use jit.gl.sketch object which gives you access to all the handy OpenGL stuff (glcolormask, glfrustum, glulookat) that you'll want for stereo, and use a javascript to control jit.gl.sketch.
Demo patcher + javascript:
//begin anaglyph.js
autowatch = 1;
var camSep = 0.1; // distance between cameras
var frustShift = 0.01; // frustum adjustment for off-axis projection)
var frust = [-1,1,-0.75,0.75,1,100]; // glfrustum
var look = [0,0,2.5,0,0,0,0,1,0]; // glulookat
var rot = 0; // rotate torus
function bang() {
rot++ // increment rotation
outlet(0,"reset");
// LEFT - draw in red channel only
outlet(0,"glcolormask",1,0,0,1);
outlet(0,"glclear");
outlet(0,"glmatrixmode", "projection");
outlet(0,"glloadidentity");
var frustL = [frust[0]+frustShift, frust[1]+frustShift, frust[2], frust[3] ,frust[4], frust[5]]
outlet(0,"glfrustum",frustL);
outlet(0,"glmatrixmode", "modelview");
outlet(0,"glloadidentity");
var lookL = [look[0]-camSep/2,look[1],look[2],look[3]-camSep/2,look[4],look[5],look[6],look[7],look[8]];
outlet(0,"glulookat",lookL);
drawSomething();
// RIGHT - draw in green & blue channels
outlet(0,"glcolormask",0,1,1,1);
outlet(0,"glclear");
outlet(0,"glmatrixmode", "projection");
outlet(0,"glloadidentity");
var frustR = [frust[0]-frustShift,frust[1]-frustShift,frust[2],frust[3],frust[4],frust[5]]
outlet(0,"glfrustum",frustR);
outlet(0,"glmatrixmode", "modelview");
outlet(0,"glloadidentity");
var lookR = [look[0]+camSep/2,look[1],look[2],look[3]+camSep/2,look[4],look[5],look[6],look[7],look[8]];
outlet(0,"glulookat",lookR);
drawSomething();
}
function drawSomething() {
outlet(0,"glpushmatrix");
outlet(0,"glrotate",rot,0,1,0);
outlet(0,"torus");
outlet(0,"glpopmatrix");
}
//end anaglyph.js
Thank you pseudostereo,
In my project, I' m working with jit.gl.model objects, And I' don't know how to connect my jit.gl.model objects to jit.gl.sketch and/or anaglyph.js objects.
Is it possible to do that ?
thanks for sharing this pseudostereo!
maybe you or somebody else can point me which direction take to render a whole context with anaglyph properties? a shader maybe?
thanks,
o
tristan - here you go - it's basically the same example, modified to draw a .obj model using the 'drawobject' command:
//begin anaglyph.js
autowatch = 1;
var camSep = 0.1; // distance between cameras
var frustShift = 0.01; // frustum adjustment for off-axis projection)
var frust = [-1,1,-0.75,0.75,1,100]; // glfrustum
var look = [0,0,2,0,0,0,0,1,0]; // glulookat
var rot = 0; // rotate torus
function bang() {
rot++ // increment rotation
outlet(0,"reset");
// LEFT - draw in red channel only
outlet(0,"glcolormask",1,0,0,1);
outlet(0,"glclear");
outlet(0,"glmatrixmode", "projection");
outlet(0,"glloadidentity");
var frustL = [frust[0]+frustShift, frust[1]+frustShift, frust[2], frust[3] ,frust[4], frust[5]]
outlet(0,"glfrustum",frustL);
outlet(0,"glmatrixmode", "modelview");
outlet(0,"glloadidentity");
var lookL = [look[0]-camSep/2,look[1],look[2],look[3]-camSep/2,look[4],look[5],look[6],look[7],look[8]];
outlet(0,"glulookat",lookL);
drawSomething();
// RIGHT - draw in green & blue channels
outlet(0,"glcolormask",0,1,1,1);
outlet(0,"glclear");
outlet(0,"glmatrixmode", "projection");
outlet(0,"glloadidentity");
var frustR = [frust[0]-frustShift,frust[1]-frustShift,frust[2],frust[3],frust[4],frust[5]]
outlet(0,"glfrustum",frustR);
outlet(0,"glmatrixmode", "modelview");
outlet(0,"glloadidentity");
var lookR = [look[0]+camSep/2,look[1],look[2],look[3]+camSep/2,look[4],look[5],look[6],look[7],look[8]];
outlet(0,"glulookat",lookR);
drawSomething();
}
function drawSomething() {
outlet(0,"glpushmatrix");
outlet(0,"glrotate",rot,0,1,0);
outlet(0,"drawobject","myModel",1);
outlet(0,"glpopmatrix");
}
//end anaglyph.js
I' m testing it and I've got some problems.
jit.gl.model anaglyph @automatic 0 @name myModel @material_mode 0
With this attributes on the jit.gl.model, I can't change the position and the size with the objects "pak position" or "pak scale".
When I put @automatic = 1 ; It produces two 3d model. I can move only one of them with "pak position" and "pak scale" and this model don't have the anaglyph effect.
Nothing happen with the attribute @tex_map for add a texture. I tried to change the @material_mode to 2 but nothing happen too.
Perhaps i must to change something in "anaglyph.js" ? (I already removed the code for rotation.)
Add some variable for scale and position in the script to change the object in real time ?
I'm working with max/msp/jitter since one year. So I 'm not an expert on jitter and java.
tristan - here's the trick - in the javascript, change the line
outlet(0,"drawobject","myModel",1);
to
outlet(0,"drawobject","myModel",0);
the 0 will cause jit.gl.sketch to pay attention to the attributes of the jit.gl.model (1 means "ignore ob3d attributes")
(note that "lighting_enable" and "smooth_shading" need to be applied to jit.gl.model)
Once you've done this, you should be able to do whatever you want with the texture.
Example patch + javascript:
//begin anaglyph.js
autowatch = 1;
var camSep = 0.1; // distance between cameras
var frustShift = 0.01; // frustum adjustment for off-axis projection)
var frust = [-1,1,-0.75,0.75,1,100]; // glfrustum
var look = [0,0,2,0,0,0,0,1,0]; // glulookat
var rot = 0; // rotate torus
function bang() {
rot++ // increment rotation
outlet(0,"reset");
// LEFT - draw in red channel only
outlet(0,"glcolormask",1,0,0,1);
outlet(0,"glclear");
outlet(0,"glmatrixmode", "projection");
outlet(0,"glloadidentity");
var frustL = [frust[0]+frustShift, frust[1]+frustShift, frust[2], frust[3] ,frust[4], frust[5]]
outlet(0,"glfrustum",frustL);
outlet(0,"glmatrixmode", "modelview");
outlet(0,"glloadidentity");
var lookL = [look[0]-camSep/2,look[1],look[2],look[3]-camSep/2,look[4],look[5],look[6],look[7],look[8]];
outlet(0,"glulookat",lookL);
drawSomething();
// RIGHT - draw in green & blue channels
outlet(0,"glcolormask",0,1,1,1);
outlet(0,"glclear");
outlet(0,"glmatrixmode", "projection");
outlet(0,"glloadidentity");
var frustR = [frust[0]-frustShift,frust[1]-frustShift,frust[2],frust[3],frust[4],frust[5]]
outlet(0,"glfrustum",frustR);
outlet(0,"glmatrixmode", "modelview");
outlet(0,"glloadidentity");
var lookR = [look[0]+camSep/2,look[1],look[2],look[3]+camSep/2,look[4],look[5],look[6],look[7],look[8]];
outlet(0,"glulookat",lookR);
drawSomething();
}
function drawSomething() {
outlet(0,"glpushmatrix");
outlet(0,"drawobject","myModel",0);
outlet(0,"glpopmatrix");
}
//end angaglyph.js
It runs nice but when I duplicate
"jit.gl.model anaglyph @automatic 0 @name myModel @material_mode 0 @lighting_enable 1 @smooth_shading 1"
with "loadbang" and "read apple.obj"
in your patch, it doesn't create two 3d objects.
I tried with this :
function drawSomething() {
outlet(0,"glpushmatrix");
outlet(0,"drawobject","myModel",0);
outlet(0,"drawobject","myModel2",0);
outlet(0,"glpopmatrix");
}
With replacing the @name by myModel2 on the second jit.gl.model and it runs.
I've got a lot of 3D objects (+-100) and I think it will be complicated to name all.
May be you have a solution for the organization of such a patch? Or a script in the anaglyph.js ?
I don't try your patch with mine but I think It will run.
Thank you very much for your help.
Hello,
Very interesting
Is posssible to post this maxpat, i wouldlike to convert this for MAX4.63