Forums > Jitter

some questions about jit.gl.mesh

August 26, 2006 | 11:41 am


i’m trying to use a jit.gl.mesh to draw a plane with an image as texture, and i’m trying to use a glsl script to change the verteces of this plane based on a jitter matrix that i bring into my script as the ‘tangent array".

i have a number of questions.

without using a programmable shader,
1) i find that my plane must be the same dimentions as my texture matrix; if not, i don’t see the full image but only as many pixels as my planes dimensionality. when i use somethin like jit.gl.videoplane, on the other hand, my plane can be a much lower dimension than my image and i still see all the image. why?

2) what should be dimensions and plane-count of the textcoord array, the normal array, specular array….. ?

now, with using a glsl shader:
3) i find that when i use the two "thru" vertex/fragment programs in the "share" folder:

sh.passthru.color.fp.glsl
sh.passthru.xform.vp.glsl

i no longer see anything rendered.

4) when i use these two scripts i found after some research:

///vertext
void main()
{

gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

}

///fragment
uniform sampler2DRect tex0;

void main (void)
{
vec4 color = texture2DRect(tex0, gl_TexCoord[0].st);
gl_FragColor = color;
}

then i get my plane drawn, but it’s all black. i’m trying to give jit.gl.mesh a texture from the outside with the "texture" messages to its first inlet. my texture is an jitter matrix with the same dims as my plane. is that the way?

thanks in advance….

a


August 26, 2006 | 8:28 pm

Hey Ali,
The texcoord matrix input to jit.gl.mesh is 2 planes, and it expects
normalized values (0.-1.) for texture coordinates. jit.expr @expr
norm[0] norm[1] will give you a texcoord matrix that is basically what
you would get with jit.gl.videoplane. Note that the dimensions of all of
your jit.gl.mesh inputs should be the same. See example patch below.

See the Jitter OpenGL documentation for more info about the breakdown of
plane numbers. (Appendix C? I can’t remember off the top of my head).

What you’re trying to do with the shader is going to require more than a
cursory knowledge of GLSL. I wouldn’t recommend diving too deep into it
without grabbing a copy of the GLSL orange book.
Truth be told, I’m not sure I understand why you aren’t just
manipulating the vertex matrix using MOPs. You might also look at the
td.repos.jxs shader if you are simply trying to manipulate the texture
image. It’s hard to speculate on any of this without a better idea of
what you’re trying to accomplish.

Andrew B.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 103 86 30 196617 read;
#P button 245 86 15 0;
#P newex 245 115 30 196617 t b b;
#P newex 103 144 86 196617 jit.gl.texture foo;
#P newex 103 116 63 196617 jit.qt.movie;
#P newex 357 236 157 196617 jit.expr @expr norm[0] norm[1];
#P newex 357 152 130 196617 jit.matrix 2 float32 50 50;
#P message 83 243 34 196617 reset;
#P newex 82 264 80 196617 jit.gl.handle foo;
#P newex 15 224 75 196617 jit.window foo;
#P newex 226 152 130 196617 jit.matrix 3 float32 50 50;
#P newex 172 236 179 196617 jit.expr @expr snorm[0] snorm[1] 0.;
#P toggle 15 33 15 0;
#P newex 15 57 51 196617 qmetro 5;
#P newex 15 82 58 196617 t erase b b;
#P newex 15 194 82 196617 jit.gl.render foo;
#P newex 172 263 118 196617 jit.gl.mesh foo;
#P comment 261 86 100 196617 generate geometry;
#P connect 17 0 13 0;
#P connect 16 0 15 0;
#P connect 15 1 11 0;
#P connect 15 0 7 0;
#P connect 14 0 1 0;
#P fasten 3 2 13 0 68 107 108 107;
#P connect 13 0 14 0;
#P fasten 12 0 1 1 362 258 190 258;
#P connect 11 0 12 0;
#P connect 7 0 6 0;
#P connect 6 0 1 0;
#P connect 9 0 1 0;
#P connect 10 0 9 0;
#P connect 3 0 2 0;
#P fasten 3 1 2 0 44 176 20 176;
#P connect 4 0 3 0;
#P connect 5 0 4 0;
#P window clipboard copycount 18;


August 26, 2006 | 9:01 pm

On Aug 26, 2006, at 4:41 AM, Ali Momeni wrote:

>
> without using a programmable shader,
> 1) i find that my plane must be the same dimentions as my texture
> matrix; if not, i don’t see the full image but only as many pixels
> as my planes dimensionality. when i use somethin like
> jit.gl.videoplane, on the other hand, my plane can be a much lower
> dimension than my image and i still see all the image. why?

Difficult to speculate without example. It sounds like for some
reason you’re not giving texture coordinates from 0.-1, or you’re no
providing enough cells for one of your jit.gl.mesh input matrices.

> 2) what should be dimensions and plane-count of the textcoord
> array, the normal array, specular array….. ?

Dimensions of *all* matrix input to jit.gl.mesh should always be the
same. With the exception of the index matrix.

Planecount is as follows:

- vertex: 2 -3 planes (x,y,z)
- texcoord: 1-4 planes (s,t,r,q)
- normal: 3 plane (nx,ny,nz)
- color: 3 or 4 planes (r,g,b,a)
- specular: 4 planes (r,g,b,a)
- edgeflag: 1 plane (on/off)
- tangent: 4 planes (tx,ty,tz,tw)
- bitangent: 4 planes (bx,by,bz,bw)
- index: 1 plane (vertex index)

> then i get my plane drawn, but it’s all black. i’m trying to give
> jit.gl.mesh a texture from the outside with the "texture" messages
> to its first inlet. my texture is an jitter matrix with the same
> dims as my plane. is that the way?

Too hard to speculate without a complete example (you really need to
get better at providing clear and complete information for people to
help you, otherwise we’re just going to start ignoring your emails,
Ali). Why aren’t you using Wesley’s patch and shader as a starting
point? It should work fine.

-Joshua


August 27, 2006 | 5:45 am

thanks for the answers andrew and joshua.
actually, joshua, that’s just what i did. i started with wes’ patch and shaders, and i began to adjust it to do what i need and i ran into various questions that i didn’t find answers to in the jit.gl.mesh html reference or the forum so i posted my questions.


August 27, 2006 | 6:18 am

i’m not trying to apply what i learned from andrew’s patch about placeing a texture on a geometry with jit.gl.mesh, and wes’s patches and applying shaders, in order to get a texture rendered on a geometry that has a programmable shader applied.

i’m able to get the texture on the geometry following andrew’s patch; but when i tell jit.gl.mesh to use a shader (wes’s), i loose the texture; i assume it’s because the texture isn’t explicitly passed thru within wes’s script. but i’m still not clear on how to access the matrices that entire jit.gl.mesh’s inlets within my glsl script.

i’m also uncertain about the difference between passing a texture to jit.gl.mesh using the "texture" or "jit_gl_textures" messages, as opposed to it’s color matrix input which can serve the same ends.

patch and script are below:

———-patch
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 284 315 61 196617 texture joo;
#P newex 439 187 157 196617 jit.expr @expr norm[0] norm[1];
#P message 125 219 80 196617 read dozer.mov;
#P newex 81 281 137 196617 jit.gl.texture foo @name joo;
#P newex 81 253 63 196617 jit.qt.movie;
#P message 489 342 40 196617 shader;
#P message 475 311 52 196617 shader at;
#N vpatcher 10 59 336 296;
#P window setfont "Sans Serif" 9.;
#N vpatcher 10 59 256 244;
#P inlet 51 52 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 123 50 29 196617 t b f;
#P newex 50 97 102 196617 jit.op @op * @val 0.;
#P newex 50 75 55 196617 jit.matrix;
#P inlet 123 30 15 0;
#P outlet 50 119 15 0;
#P fasten 4 0 2 0 128 72 55 72;
#P connect 5 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P connect 1 0 4 0;
#P connect 4 1 3 1;
#P pop;
#P newobj 207 129 42 196617 p Scale;
#N vpatcher 10 59 256 244;
#P inlet 51 52 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 123 50 29 196617 t b f;
#P newex 50 97 102 196617 jit.op @op * @val 0.;
#P newex 50 75 55 196617 jit.matrix;
#P inlet 123 30 15 0;
#P outlet 50 119 15 0;
#P connect 5 0 2 0;
#P fasten 4 0 2 0 128 72 55 72;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P connect 1 0 4 0;
#P connect 4 1 3 1;
#P pop;
#P newobj 156 129 42 196617 p Scale;
#P newex 105 162 53 196617 jit.pack 3;
#N vpatcher 10 59 256 244;
#P inlet 51 52 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 123 50 29 196617 t b f;
#P newex 50 97 102 196617 jit.op @op * @val 0.;
#P newex 50 75 55 196617 jit.matrix;
#P inlet 123 30 15 0;
#P outlet 50 119 15 0;
#P fasten 4 0 2 0 128 72 55 72;
#P connect 5 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 0 0;
#P connect 1 0 4 0;
#P connect 4 1 3 1;
#P pop;
#P newobj 105 129 42 196617 p Scale;
#P newex 34 74 63 196617 jit.unpack 3;
#P inlet 239 46 15 0;
#P inlet 188 46 15 0;
#P inlet 137 46 15 0;
#P inlet 34 54 15 0;
#P outlet 105 184 15 0;
#P button 105 74 15 0;
#P connect 2 0 6 0;
#P fasten 5 0 0 0 244 67 110 67;
#P fasten 4 0 0 0 193 67 110 67;
#P connect 0 0 7 0;
#P fasten 6 0 7 0 39 116 110 116;
#P connect 7 0 8 0;
#P connect 8 0 1 0;
#P fasten 9 0 8 1 161 152 131 152;
#P connect 3 0 7 1;
#P fasten 10 0 8 2 212 157 152 157;
#P fasten 6 1 9 0 56 106 161 106;
#P connect 4 0 9 1;
#P fasten 6 2 10 0 73 98 212 98;
#P connect 5 0 10 1;
#P pop;
#P newobj 660 344 116 196617 p Displace;
#P flonum 771 317 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 733 317 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 303 493 112 196617 vertex attr test shader;
#P newex 396 90 48 196617 loadbang;
#P message 387 447 30 196617 read;
#P flonum 695 317 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 660 187 271 196617 jit.expr 3 float32 10 10 @expr "norm[0]" "norm[1]" "1";
#P button 8 89 15 0;
#P message 296 447 89 196617 read vd.attr2.jxs;
#P newex 296 471 132 196617 jit.gl.shader attr @name at;
#P button 396 110 15 0;
#P newex 396 129 130 196617 jit.matrix 3 float32 10 10;
#P newex 396 152 352 196617 jit.expr @expr "snorm[0]" "snorm[1]" "0.9*hypot(snorm[0]\, snorm[1])";
#P newex 396 388 369 196617 jit.gl.mesh attr @blend_enable 1 @depth_enable 1;
#P toggle 135 54 15 0;
#P message 135 74 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 135 34 33 196617 p Esc;
#P newex 135 92 151 196617 jit.window attr @depthbuffer 1;
#P message 96 92 34 196617 reset;
#P newex 96 113 186 196617 jit.gl.handle attr @inherit_transform 1;
#P toggle 33 69 15 0;
#P newex 33 88 57 196617 qmetro 60;
#P newex 33 113 58 196617 t b erase b;
#P newex 33 138 157 196617 jit.gl.render attr @camera 0 0 4;
#P user jit.pwindow 22 318 82 62 0 1 0 0 1 0;
#P connect 32 0 11 0;
#P connect 28 0 0 0;
#P connect 28 0 29 0;
#P connect 13 0 12 0;
#P connect 13 0 31 0;
#P connect 12 0 11 0;
#P fasten 12 0 18 0 401 175 665 175;
#P connect 25 0 11 6;
#P connect 27 0 11 0;
#P connect 26 0 11 0;
#P connect 31 0 11 1;
#P connect 14 0 13 0;
#P connect 2 2 28 0;
#P connect 3 0 2 0;
#P fasten 17 0 2 0 13 108 38 108;
#P fasten 2 0 1 0 38 134 38 134;
#P fasten 2 1 1 0 78 134 38 134;
#P connect 30 0 28 0;
#P fasten 24 0 25 3 776 338 770 338;
#P fasten 23 0 25 2 738 338 735 338;
#P fasten 19 0 25 1 700 338 700 338;
#P fasten 18 0 25 0 665 284 665 284;
#P connect 21 0 14 0;
#P connect 9 0 7 0;
#P connect 10 0 9 0;
#P connect 8 0 10 0;
#P connect 6 0 5 0;
#P fasten 5 0 1 0 101 134 38 134;
#P connect 4 0 3 0;
#P connect 16 0 15 0;
#P fasten 20 0 15 0 392 466 301 466;
#P window clipboard copycount 33;

—————.jxs file named "vd.attr2.jxs"



Textured glass-like material lit with a point light w/ two specular components calculated per pixel.

Position of Light Source

Position

Tangent

Primary Specular Color

Secondary Specular Color

Base Color

Primary Specular Multiplier

Secondary Specular Multiplier

Specularity Adjustment










< ![CDATA[
/*
*
* Derek Gerstmann – derek@cycling74.com
* Copyright 2005 – Cycling ’74
*
* GLSL vertex program for a textured glass-like material lit by a
* point light source.
*
*/

uniform vec3 lightpos; // position of light source
attribute vec3 position;
attribute vec3 tangent;

varying vec3 lightdir; // direction of light source
varying vec3 viewdir; // view direction
varying vec3 normal; // surface normal

void main(void)
{

gl_FrontColor = gl_Color;
// perform standard transform on vertex
gl_Position = gl_ModelViewProjectionMatrix*vec4((position+tangent), 1.);

// normalize view direction
viewdir = -normalize(vec3(gl_ModelViewMatrix * gl_Vertex));

// normalize light direction
lightdir = normalize(lightpos);

// get texture coordinate
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

// transform normal into view space
normal = normalize(gl_NormalMatrix * gl_Normal);
}
]]>

< ![CDATA[
/*
*
* Derek Gerstmann – derek@cycling74.com
* Copyright 2005 – Cycling ’74
*
* GLSL fragment program for a textured glass-like material lit by a
* point light source.
*
*/

varying vec3 lightdir; // light direction
varying vec3 viewdir; // view direction
varying vec3 normal; // surface normal

uniform vec4 basecolor; // base glass color
uniform vec4 specular2; // secondary specular color
uniform vec4 specular1; // main specular color

uniform float ks1; // specular multiplier
uniform float ks2; // dim specular multiplier

uniform float shininess; // specular adjustment

void main (void)
{
vec4 color;

// compute the reflection vector
vec3 reflect = normalize( 2.0 * dot( normal, lightdir) * normal – lightdir );

// compute specular intensity
float specularity = max(dot(viewdir, reflect), 0.0);
specularity = specularity * specularity;

// add in the base and secondary specular color
color = basecolor + ks2 * specularity * specular2;

// add in the primary specular color
specularity = pow(specularity, shininess) * ks1;
color += specularity * specular1;

// set the outgoing fragment color
// gl_FragColor = min(color, vec4(1.0));
gl_FragColor = gl_Color;
}
]]>


August 27, 2006 | 6:41 am

Ali,
No offense, but do you actually < > the emails we’ve been sending
you? If you look at the top of the email that I posted the inital
vertex displacement shader patch in, you would find this list:

> These are the state variables that you can bind vertex shader
> attributes to. The correspond precisely to their jit.gl.mesh’s
> namesake.:

> "POSITION"
> "NORMAL"
> "TANGENT"
> "BITANGENT"
> "TEXCOORD"

Now, if you look at my original shader it’s simple matter to access
the input matrices to jit.gl.mesh using these values instead of
TANGENT like I had done.

> i’m able to get the texture on the geometry following andrew’s patch; but when i tell jit.gl.mesh to > use a shader (wes’s), i loose the texture; i assume it’s because the texture isn’t explicitly passed > thru within wes’s script. but i’m still not clear on how to access the matrices that entire
> jit.gl.mesh’s inlets within my glsl script.

As I think Andrew suggested, you need to take a look at a book or
website or something on shaders. Textures need to be explicity
applied by the fragment shader to ane any effect. May I politely
suggest you read the orangebook or something similar to familiarize
yourself with the programmable GPU pipeline. There are also a
bajillion shader examples that do texture access. It should be
straightforward to add this to the shader.

> i’m also uncertain about the difference between passing a texture to jit.gl.mesh using the
> "texture" or "jit_gl_textures" messages, as opposed to it’s color matrix input which can serve the
> same ends.

jit_gl_texture and @texture are exactly the same thing. The color
matrix and textures are completely different. For more on this, see
this page:

http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node21.html

jit.gl.mesh uses glVertexPointer and related methods for doing its
thing. glColorPointer is very very different than textures.

wes


August 27, 2006 | 6:57 am


August 27, 2006 | 10:10 pm

On Aug 26, 2006, at 11:57 PM, Ali Momeni wrote:

> there are plenty of people asking basic and obvious questions on
> the cycling forum. if at anypoint something is so far below your
> level of expertise that a respond to the question is going to be
> tinged with antagonism instead of compassion, then perhaps you
> should simply refrain from responding.

What is under discussion here is that you ask questions (which are in
no way below our level of expertise), that we would be happy to
answer, but that you consistently ask the questions in such a way
that we need to send several emails back and forth to actually figure
out what you’re doing. This is frustrating for us (and frustrating
for you).

It really is important to provide clear and complete information so
that anyone (not just us) can answer your questions intelligently.
Not to single you out, as there are many users that do this (I would
like to stress to everyone to provide this sort of information),
however, I would expect at this point, you would know to provide this
kind of information in the first message.

I’m not trying to berate you as a person, or the fundamental nature
of any of the questions you ask. Just that you do so in a way that
requires much more work on all of our parts (yours and ours).

-Joshua


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