Forums > Jitter

Jit.boids3D

April 4, 2008 | 12:52 pm

Hi,

Am trying to get open gl models into Wesley Smiths jit boids 3d patch, so as the models are the boids elements in effect….. cant figure out how to get jit.gl.model to fit within the patch…anyone any ideas?

I know you can use jit.gl.mesh, and jit.gridshape, but really need to get my own models in…presume it must be possible,

Any help would be much appreciated….


April 4, 2008 | 8:46 pm

a couple of ways i’ve done something similar.
one way involves sending the output of boids to a jit.scanwrap and sending that to the position input of a jit.gl.multiple, which is bound to whatever object you want as your boid.
something like this:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 308 129 123 196617 jit.boids3d @number 225;
#B color 5;
#P newex 308 161 188 196617 jit.scanwrap 3 float32 15 15 @mode 1;
#B color 5;
#P newex 308 195 266 196617 jit.gl.multiple foo 3 @targetname m1 @glparams position;
#B color 5;
#P connect 1 0 0 0;
#P connect 2 0 1 0;
#P window clipboard copycount 3;

another method involves iterating the boids matrix each time step, and wrapping your gl object in a poly~.
something like this:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 61 325 52 196617 s to_poly;
#P newex 46 51 69 196617 r from_boids;
#P newex 46 77 29 196617 t l 1;
#P newex 194 128 21 196617 t 2;
#P newex 186 151 38 196617 gate 2;
#P newex 61 177 76 196617 prepend target;
#P newex 61 152 27 196617 + 1;
#P newex 61 129 52 196617 unpack i i;
#P newex 82 229 40 196617 t b b l;
#P newex 82 204 82 196617 prepend position;
#P newex 46 103 40 196617 jit.iter;
#P connect 5 0 10 0;
#P fasten 2 0 10 0 87 261 66 261;
#P fasten 2 2 10 0 117 276 66 276;
#P connect 9 0 8 0;
#P fasten 6 0 1 0 191 198 87 198;
#P connect 8 0 0 0;
#P connect 0 1 3 0;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P fasten 6 1 1 0 219 200 87 200;
#P connect 1 0 2 0;
#P fasten 8 1 6 0 70 97 191 97;
#P fasten 7 0 6 0 199 148 191 148;
#P fasten 2 1 7 0 102 256 228 256 228 109 199 109;
#P fasten 0 0 6 1 51 124 219 124;
#P window clipboard copycount 11;

keep in mind, jit.gl.model does not do well for multiple instances of complex models. your better off using wes’s lua gl model, or jit-ogre.

-rob


April 4, 2008 | 8:49 pm

err, that second code snippet might seem a bit weird, because it was taken from a more complex patch, but hopefully you get the idea.

AND, i should mention, the gl.multiple method will give you the best performance.


December 27, 2008 | 7:31 pm

I’ve been trying to do this as well, but with videos instead of gl models, similar to Andrew Benson’s recipe Dancing Sprites.

I’ve tried both of these methods, but neither compares to jit.boids3d help file, which uses xray.jit.boidsrender to jit.gl.mesh. However, if I use the video as a texture to jit.gl.mesh, I can’t get the videos to always appear flat and rectangular in the window and just change size as they move in space, rather than distorting in 3d. Is there anyway to get around this? Please let me know if I’m not being clear.

Thanks,
Zach


December 27, 2008 | 8:38 pm

Here’s an example patch doing screen-aligned billboarding using some
jit.expr and shader voodoo. The cray.jit.boidsrender object was made
when I was just learning 3D rotation transformations and uses some
semi-hack techniques. This example does the billboarding in the
shader and requires very specific matrices in the vertex and texcoord
inputs. See if you can figure it out!

– Pasted Max Patch, click to expand. –

And the shader:

screen-aligned billboarding

uniform float scale;
varying vec2 texcoord0;

void main()
{
vec3 offset = vec3(gl_MultiTexCoord0.xy, 0.)*2.-1.;

//screen-aligned axes
vec3 axis1 = vec3( gl_ModelViewMatrix[0][0],
gl_ModelViewMatrix[1][0],
gl_ModelViewMatrix[2][0]);

vec3 axis2 = vec3( gl_ModelViewMatrix[0][1],
gl_ModelViewMatrix[1][1],
gl_ModelViewMatrix[2][1]);

//offset from center point
vec3 corner = (offset.x*axis1 + offset.y*axis2)*scale + gl_Vertex.xyz;

// position in eye space
gl_Position = gl_ModelViewProjectionMatrix * vec4(corner, 1.);

texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
gl_FrontColor = gl_Color;
}
]]>

varying vec2 texcoord0;
uniform sampler2DRect tex0;

void main()
{
gl_FragColor = texture2DRect(tex0, texcoord0)*gl_Color;
}
]]>


December 27, 2008 | 9:25 pm

Thanks, Wesley, but indeed I cannot figure it out!

First of all, I’m getting an error that jit.noise doesn’t understand the int input from the counter.

I do understand that the jit.op fancywork handles what was encapsulated in xray.jit.boidsrender, while the shader handles the billboarding I asked for. However, where does the input from jit.boids3d go? When I run your patch I don’t get anything in my jit.window. Please explain?


December 27, 2008 | 9:55 pm

it would appear that the @carry flag output setting reverted to
numeric, instead of bang, when you copy-compressed the patch.

On Dec 27, 2008, at 3:38 PM, Wesley Smith wrote:

> Here’s an example patch doing screen-aligned billboarding using some
> jit.expr and shader voodoo. The cray.jit.boidsrender object was made
> when I was just learning 3D rotation transformations and uses some
> semi-hack techniques. This example does the billboarding in the
> shader and requires very specific matrices in the vertex and texcoord
> inputs. See if you can figure it out!
>
>
>

– Pasted Max Patch, click to expand. –

>
>
>
>
> And the shader:
>
>
>
>
>
>
>
> screen-aligned billboarding
>
>
>
>
>
>
>
>
>
>
> uniform float scale;
> varying vec2 texcoord0;
>
> void main()
> {
> vec3 offset = vec3(gl_MultiTexCoord0.xy, 0.)*2.-1.;
>
> //screen-aligned axes
> vec3 axis1 = vec3( gl_ModelViewMatrix[0][0],
> gl_ModelViewMatrix[1][0],
> gl_ModelViewMatrix[2][0]);
>
> vec3 axis2 = vec3( gl_ModelViewMatrix[0][1],
> gl_ModelViewMatrix[1][1],
> gl_ModelViewMatrix[2][1]);
>
>
> //offset from center point
> vec3 corner = (offset.x*axis1 + offset.y*axis2)*scale +
> gl_Vertex.xyz;
>
> // position in eye space
> gl_Position = gl_ModelViewProjectionMatrix * vec4(corner, 1.);
>
> texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
> gl_FrontColor = gl_Color;
> }
> ]]>
>
>
>
>
>
> varying vec2 texcoord0;
> uniform sampler2DRect tex0;
>
> void main()
> {
> gl_FragColor = texture2DRect(tex0, texcoord0)*gl_Color;
> }
> ]]>
>
>
>


December 27, 2008 | 10:00 pm

> First of all, I’m getting an error that jit.noise doesn’t understand the int input from the counter.
>
hmm. I thought counter was supposed to save it’s state w/r/t the
overflow flag. Just stick a [t b] there.

> I do understand that the jit.op fancywork handles what was encapsulated in xray.jit.boidsrender, while the shader handles the billboarding I asked for. However, where does the input from jit.boids3d go? When I run your patch I don’t get anything in my jit.window. Please explain?

This is probably due to the error. Try this one:

– Pasted Max Patch, click to expand. –

December 27, 2008 | 10:21 pm

Not sure what you’re talking about with counter, but it fixed the error.

However, I’m still not getting anything on the screen. Maybe it has do with the way I implemented the shader?


December 27, 2008 | 10:30 pm

hmm … it works when the patch loads up for me after fixing the
counter thing. There are 2 matrices, the [2 float32 160 1] is both
your texcoords and offsets in the shader. This is what the quads are
built with. The other one with the noise and ops are just random 3d
coordinates where you can plug your boids positions in to. The
important point is to expand this matrix x4 such that each point is
"quadruplicated". With these 2 matrices, the shader know the location
of the quad and for each of the quadruplicated points, how much to
offset it by.

wes


December 27, 2008 | 11:00 pm

Well, I at least have the mesh working when I replace the noise with boids. However, I still can’t get the shader to work as I have limited experience with glsl. Can you possibly post the shader file you used?


December 27, 2008 | 11:21 pm

On Sat, Dec 27, 2008 at 5:00 PM, Zach Gold

wrote:
>
> Well, I at least have the mesh working when I replace the noise with boids. However, I still can’t get the shader to work as I have limited experience with glsl. Can you possibly post the shader file you used?
>


December 28, 2008 | 12:17 am

I see that Zachary Seldess has a complicated patching solution to the billboarding problem:

http://www.cycling74.com/forums/index.php?t=msg&goto=158307&rid=0&S=b175b858ca8a21f2f43892f0622dcfad

Unfortunately, I can’t get that to work either. It seems the shader would be much more elegant anyway.


December 29, 2008 | 4:51 pm

wes attached his shader to via email, so it didn’t make it to the forum. you can access it through the archives here:

http://www.cycling74.com/pipermail/jitter/attachments/20081227/fa6f5250/vd.billboard.obj


December 29, 2008 | 11:35 pm

Thanks, Rob. Unfortunately the shader is not working for me. It does scale the videos in response to my parameter, but does not billboard them. I’m not getting any errors in the Max window either. Any ideas?


December 31, 2008 | 11:00 pm

So much more elegant when done this way. Thanks Wes. You just instigated a new year’s resolution.

Zachary


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