Forums > Jitter

texture mapping not working with jit.gl.multiple

September 24, 2006 | 11:41 pm

I’m having problems mapping textures using jit.gl.multiple. I basically want
to use a texture in environment mapping, and need to scale it using
tex_plane_s/t. Nothing seems to work like using regular jit.gl objects.
There is no change to the mapping at all. Here’s an example patch. I can’t
scale the dozer so that it will fit the screen. Really wanted to use this
for a project, with just one day to go… guess I’m screwed :-(

-thijs

using windows max 4.6.2rc2 jitter 1.6.2

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 576 353 56 9109513 r loadbang;
#P window linecount 2;
#P message 507 381 50 9109513 autoscale $1;
#P window linecount 1;
#P message 576 379 79 9109513 read dozer.mov;
#P newex 577 440 233 9109513 jit.gl.texture foo @name dozer @texgen
environment;
#P toggle 508 361 15 0;
#P newex 387 159 50 9109513 r lkj;
#P newex 310 320 50 9109513 r lkj;
#P newex 632 280 50 9109513 s lkj;
#P number 568 203 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 568 224 57 9109513 tex_map $1;
#P newex 632 198 50 9109513 !- 0.;
#P flonum 633 177 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 656 248 107 9109513 tex_plane_t 0. $1 0. 0.;
#P message 632 225 107 9109513 tex_plane_s $1 0. 0. 0.;
#P newex 78 188 41 9109513 s draw;
#P newex 246 136 56 9109513 r loadbang;
#P newex 105 386 56 9109513 s loadbang;
#P newex 472 259 32 9109513 print;
#P newex 160 155 54 9109513 r multiple;
#N vpatcher 375 354 1147 800;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P message 148 225 50 9109513 0.12;
#P message 493 301 80 9109513 setall 0 , bang;
#P newex 493 324 117 9109513 jit.matrix 1 char 15 15;
#P newex 146 248 130 9109513 jit.matrix 3 float32 15 15;
#P newex 84 188 256 9109513 jit.expr @expr "0" "0" "0";
#P newex 84 167 130 9109513 jit.matrix 3 float32 15 15;
#P window linecount 2;
#P newex 17 98 180 9109513 jit.expr @expr "snorm[0]*2" "snorm[1]*2" "0";
#P window linecount 1;
#P newex 17 74 130 9109513 jit.matrix 3 float32 15 15;
#P inlet 91 36 15 0;
#P outlet 493 346 15 0;
#P outlet 146 296 15 0;
#P outlet 84 210 15 0;
#P outlet 17 132 15 0;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 0 0;
#P connect 4 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 1 0;
#P connect 12 0 9 0;
#P connect 9 0 2 0;
#P connect 4 0 12 0;
#P connect 4 0 11 0;
#P connect 11 0 10 0;
#P connect 10 0 3 0;
#P pop;
#P newobj 246 177 79 9109513 p GenGLParams;
#P newex 85 357 48 9109513 loadbang;
#P message 172 190 65 9109513 getglparams;
#P user jit.fpsgui 58 210 60 9109513 0;
#P message 52 506 34 9109513 reset;
#P newex 52 525 255 9109513 jit.gl.handle foo @inherit_transform 1
@auto_rotate 1;
#P newex 321 567 188 9109513 jit.window foo @depthbuffer 1 @sync 0;
#P number 75 106 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 34 106 15 0;
#P newex 34 128 51 9109513 qmetro 20;
#P newex 34 150 58 9109513 t b b erase;
#P newex 34 567 271 9109513 jit.gl.render foo @erase_color 1. 1. 1. 1.
@camera 0 0 4;
#P button 85 385 15 0;
#P button 246 157 15 0;
#P window linecount 2;
#P newex 85 411 347 9109513 jit.gl.gridshape foo @shape plane
@lighting_enable 1 @blend_enable 1 @smooth_shading 1 @automatic 0
@depth_enable 1 @dim 10 10 @name me;
#P newex 246 225 227 9109513 jit.gl.multiple foo 4 @targetname me @glparams
position rotatexyz scale texture @texture dozer;
#B color 5;
#P window setfont "Sans Serif" 12.;
#P window linecount 5;
#P comment 693 132 100 9109516 scaling doesn’t do anything on both multiple
and gridshape objects;
#P connect 6 1 13 0;
#P fasten 6 1 21 0 63 182 83 182;
#P connect 24 0 25 0;
#P connect 24 0 23 0;
#P connect 22 0 28 0;
#P connect 23 0 28 0;
#P connect 26 0 28 0;
#P connect 25 0 22 0;
#P connect 34 0 32 0;
#P connect 33 0 32 0;
#P connect 35 0 33 0;
#P connect 27 0 26 0;
#P connect 31 0 34 0;
#P connect 1 1 18 0;
#P fasten 16 3 1 3 320 206 467 206;
#P fasten 16 2 1 2 297 212 395 212;
#P fasten 16 1 1 1 274 218 323 218;
#P connect 30 0 1 0;
#P connect 16 0 1 0;
#P fasten 17 0 1 0 165 221 251 221;
#P fasten 14 0 1 0 177 221 251 221;
#P connect 3 0 16 0;
#P connect 20 0 3 0;
#P connect 15 0 4 0;
#P fasten 15 0 19 0 90 380 110 380;
#P connect 4 0 2 0;
#P connect 29 0 2 0;
#P connect 9 0 7 1;
#P connect 12 0 11 0;
#P connect 6 0 5 0;
#P fasten 6 2 5 0 87 173 39 173;
#P fasten 11 0 5 0 57 554 39 554;
#P connect 7 0 6 0;
#P connect 8 0 7 0;
#P window clipboard copycount 36;


September 25, 2006 | 12:22 am

Hi Thijs,
Thanks for pointing out this tex_map/tex_plane_* bug. Please note
though that tex_plane_s/t only work in tex_map modes 1 and 3. For
environment mapping, they have no effect. You can however use a
shader to do this kind of stuff. Reflection mapping is a bit tricky
as you’re taking a vector in 3D and doing a 2D texture lookup, so
scaling the thing. Here’s a patch that uses a shader called
td.reflect.jxs that I made to replicate @texgen environment as a
shader so that you can have more control over it. If you need
lighting, this also has to be done in the shader. I can make an
example of how to do that if you need it. Below are the patch *and*
the shader.

best,
wes

******************************PATCH*********************************
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 204 176 49 196617 pak 0. 0.;
#P flonum 204 155 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 538 96 40 196617 shader;
#P flonum 243 155 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 277 204 94 196617 param scale $1 $2;
#P message 182 204 89 196617 file td.reflect.jxs;
#P message 524 78 74 196617 shader relfect;
#P newex 182 231 353 196617 jit.gl.shader foo @file td.reflect.jxs
@name reflect @param scale 1.05 0.28;
#P toggle 371 437 15 0;
#P message 371 457 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 371 417 33 196617 p Esc;
#P user ubumenu 720 284 100 196617 0 1 1 0;
#X add none;
#X add objectspace;
#X add viewspace;
#X add environment;
#X prefix_set 0 0 0;
#X pattrmode 1;
#P newex 727 305 75 196617 prepend texgen;
#P newex 627 268 56 196617 r loadbang;
#P message 556 295 67 196617 autoscale $1;
#P message 627 294 79 196617 read dozer.mov;
#P newex 627 355 148 196617 jit.gl.texture foo @name dozer;
#P toggle 556 275 15 0;
#P newex 437 74 50 196617 r lkj;
#P newex 301 290 50 196617 r lkj;
#P newex 128 103 41 196617 s draw;
#P newex 296 51 56 196617 r loadbang;
#P newex 155 301 56 196617 s loadbang;
#P newex 629 199 32 196617 print;
#P newex 210 70 54 196617 r multiple;
#N vpatcher 375 354 1147 800;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P message 148 225 50 196617 0.12;
#P message 493 301 80 196617 setall 0 , bang;
#P newex 493 324 117 196617 jit.matrix 1 char 15 15;
#P newex 146 248 130 196617 jit.matrix 3 float32 15 15;
#P newex 84 188 256 196617 jit.expr @expr "0" "0" "0";
#P newex 84 167 130 196617 jit.matrix 3 float32 15 15;
#P window linecount 2;
#P newex 17 98 180 196617 jit.expr @expr "snorm[0]*2" "snorm[1]*2" "0";
#P window linecount 1;
#P newex 17 74 130 196617 jit.matrix 3 float32 15 15;
#P inlet 91 36 15 0;
#P outlet 493 346 15 0;
#P outlet 146 296 15 0;
#P outlet 84 210 15 0;
#P outlet 17 132 15 0;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 0 0;
#P connect 4 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 1 0;
#P connect 12 0 9 0;
#P connect 9 0 2 0;
#P connect 4 0 12 0;
#P connect 4 0 11 0;
#P connect 11 0 10 0;
#P connect 10 0 3 0;
#P pop;
#P newobj 296 92 79 196617 p GenGLParams;
#P newex 135 272 48 196617 loadbang;
#P message 222 105 65 196617 getglparams;
#P user jit.fpsgui 108 125 60 196617 0;
#P message 102 421 34 196617 reset;
#P newex 102 440 255 196617 jit.gl.handle foo @inherit_transform 1
@auto_rotate 1;
#P newex 371 482 188 196617 jit.window foo @depthbuffer 1 @sync 0;
#P number 131 23 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 84 21 15 0;
#P newex 84 43 57 196617 qmetro 20;
#P newex 84 65 58 196617 t b b erase;
#P newex 84 482 271 196617 jit.gl.render foo @erase_color 1. 1. 1. 1.
@camera 0 0 4;
#P button 135 300 15 0;
#P button 296 72 15 0;
#P window linecount 2;
#P newex 135 326 403 196617 jit.gl.gridshape foo @shape plane
@lighting_enable 1 @blend_enable 1 @smooth_shading 1 @automatic 0
@depth_enable 1 @dim 2 2 @name me @tex_map 2 @color 1 1 1 1;
#P window linecount 3;
#P newex 296 140 343 196617 jit.gl.multiple foo 4 @targetname me
@glparams position rotatexyz scale texture @texture dozer @targetmode
1 @lighting_enable 1 @blend_enable 1 @depth_enable 1 @smooth_shading 1
@color 1 1 1 1 @shader reflect;
#B color 5;
#P window setfont "Sans Serif" 12.;
#P comment 650 142 220 196620 < = more efficient in targetmode 1 , but
you have to set all the opengl attrs here;
#P connect 8 0 7 0;
#P connect 7 0 6 0;
#P connect 6 0 5 0;
#P fasten 6 2 5 0 137 88 89 88;
#P fasten 11 0 5 0 107 469 89 469;
#P connect 12 0 11 0;
#P connect 6 1 13 0;
#P fasten 6 1 21 0 113 97 133 97;
#P connect 9 0 7 1;
#P connect 15 0 4 0;
#P connect 4 0 2 0;
#P connect 22 0 2 0;
#P fasten 15 0 19 0 140 295 160 295;
#P fasten 37 0 34 0 282 225 187 225;
#P connect 36 0 34 0;
#P connect 40 0 41 0;
#P connect 38 0 41 1;
#P fasten 41 0 37 0 209 198 282 198;
#P connect 20 0 3 0;
#P connect 3 0 16 0;
#P connect 23 0 1 0;
#P connect 16 0 1 0;
#P fasten 17 0 1 0 215 136 301 136;
#P fasten 14 0 1 0 227 136 301 136;
#P fasten 35 0 1 0 529 115 301 115;
#P fasten 39 0 1 0 543 115 301 115;
#P connect 31 0 33 0;
#P connect 33 0 32 0;
#P connect 32 0 10 0;
#P fasten 16 1 1 1 324 133 412 133;
#P fasten 16 2 1 2 347 127 523 127;
#P connect 24 0 27 0;
#P connect 28 0 26 0;
#P connect 26 0 25 0;
#P connect 27 0 25 0;
#P connect 29 0 25 0;
#P fasten 16 3 1 3 370 121 634 121;
#P connect 1 1 18 0;
#P fasten 30 1 29 0 770 302 732 302;
#P window clipboard copycount 42;

******************************************Shader**********************************

Shader for for modifying image contrast by interpolation
and extrapolation


< ![CDATA[

varying vec2 texcoord0;
varying vec2 texdim0;
varying vec4 V;
varying vec4 E;
varying vec3 N;

void main (void)

{
V = gl_ModelViewMatrix * gl_Vertex;
E = gl_ProjectionMatrixInverse * vec4(0.,0.,-1., 0.);
N = normalize(gl_NormalMatrix * gl_Normal);

texdim0 = vec2 (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));
texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
gl_Position = ftransform();
}
]]>

< ![CDATA[

varying vec2 texcoord0;
varying vec2 texdim0;
uniform sampler2DRect tex0;

varying vec4 V;
varying vec4 E;
varying vec3 N;

uniform vec2 scale;

void main (void)
{
vec3 Nn = scale.y*normalize(N);
vec3 Vn = scale.x*normalize(V.xyz);

/*vec3 In = normalize(V.xyz*E.w – E.xyz*V.w);
vec3 R = reflect(In, Nn);

vec2 reflectCoords = 0.5 + 0.5*normalize(R+vec3(0., 0., 1.)).xy;
reflectCoords *= texdim0;*/

vec3 R = Vn-2.*Nn*dot(Nn, Vn);
float m = 2.*sqrt(R.x*R.x + R.y*R.y + (R.z+1.)*(R.z+1.));
vec2 reflectCoords;

//because of flip in Gridshape’s texcoords
reflectCoords.s = (R.x/m + 0.5);
reflectCoords.t = 1.-(R.y/m + 0.5);
reflectCoords *= texdim0;

vec4 color = texture2DRect(tex0, reflectCoords);

//vec4 color = texture2DRect(tex0, texcoord0);

gl_FragColor = color;
//gl_FragColor = vec4((R), 1.);
}
]]>


September 25, 2006 | 12:28 am

And here’s a second way of scaling the texture in the shader with a
slightly different effect. Anyway, compare the 2 ways of scaling and
you can get the idea. There are many domains in which to do it in for
different kinds of funkiness.

wes


Shader for for modifying image contrast by interpolation
and extrapolation


< ![CDATA[

varying vec2 texcoord0;
varying vec2 texdim0;
varying vec4 V;
varying vec4 E;
varying vec3 N;

void main (void)

{
V = gl_ModelViewMatrix * gl_Vertex;
E = gl_ProjectionMatrixInverse * vec4(0.,0.,-1., 0.);
N = normalize(gl_NormalMatrix * gl_Normal);

texdim0 = vec2 (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));
texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
gl_Position = ftransform();
}
]]>

< ![CDATA[

varying vec2 texcoord0;
varying vec2 texdim0;
uniform sampler2DRect tex0;

varying vec4 V;
varying vec4 E;
varying vec3 N;

uniform vec2 scale;

void main (void)
{
vec3 scaleVertex = vec3(scale*V.xy, V.z);
vec3 Nn = normalize(N);
vec3 Vn = normalize(scaleVertex);

/*vec3 In = normalize(V.xyz*E.w – E.xyz*V.w);
vec3 R = reflect(In, Nn);

vec2 reflectCoords = 0.5 + 0.5*normalize(R+vec3(0., 0., 1.)).xy;
reflectCoords *= texdim0;*/

vec3 R = Vn-2.*Nn*dot(Nn, Vn);
float m = 2.*sqrt(R.x*R.x + R.y*R.y + (R.z+1.)*(R.z+1.));
vec2 reflectCoords;

//because of flip in Gridshape’s texcoords
reflectCoords.s = (R.x/m + 0.5);
reflectCoords.t = 1.-(R.y/m + 0.5);
reflectCoords *= texdim0;

vec4 color = texture2DRect(tex0, reflectCoords);

//vec4 color = texture2DRect(tex0, texcoord0);

gl_FragColor = color;
//gl_FragColor = vec4((R), 1.);
}
]]>


September 25, 2006 | 10:46 am

Hi Wes, thanks a lot! I didn’t think about using shaders. This will solve
the problem. Thanks to your quick response I might be able to catch up just
in time.

best, -thijs

On 9/25/06, Wesley Smith wrote:
>
> And here’s a second way of scaling the texture in the shader with a
> slightly different effect. Anyway, compare the 2 ways of scaling and
> you can get the idea. There are many domains in which to do it in for
> different kinds of funkiness.
>
> wes
>
>
> Shader for for modifying image contrast by
> interpolation
> and extrapolation

>

>

>
>
>

> < ![CDATA[
>
> varying vec2 texcoord0;
> varying vec2 texdim0;
> varying vec4 V;
> varying vec4 E;
> varying vec3 N;
>
> void main (void)
>
> {
> V = gl_ModelViewMatrix * gl_Vertex;
> E = gl_ProjectionMatrixInverse * vec4(0.,0.,-1., 0.);
> N = normalize(gl_NormalMatrix * gl_Normal);
>
> texdim0 = vec2
> (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));
> texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
> gl_Position = ftransform();
> }
> ]]>
>
>

> < ![CDATA[
>
> varying vec2 texcoord0;
> varying vec2 texdim0;
> uniform sampler2DRect tex0;
>
> varying vec4 V;
> varying vec4 E;
> varying vec3 N;
>
> uniform vec2 scale;
>
> void main (void)
> {
> vec3 scaleVertex = vec3(scale*V.xy, V.z);
> vec3 Nn = normalize(N);
> vec3 Vn = normalize(scaleVertex);
>
> /*vec3 In = normalize(V.xyz*E.w – E.xyz*V.w);
> vec3 R = reflect(In, Nn);
>
> vec2 reflectCoords = 0.5 + 0.5*normalize(R+vec3(0., 0., 1.)).xy;
> reflectCoords *= texdim0;*/
>
> vec3 R = Vn-2.*Nn*dot(Nn, Vn);
> float m = 2.*sqrt(R.x*R.x + R.y*R.y + (R.z+1.)*(R.z+1.));
> vec2 reflectCoords;
>
> //because of flip in Gridshape’s texcoords
> reflectCoords.s = (R.x/m + 0.5);
> reflectCoords.t = 1.-(R.y/m + 0.5);
> reflectCoords *= texdim0;
>
> vec4 color = texture2DRect(tex0, reflectCoords);
>
>
> //vec4 color = texture2DRect(tex0, texcoord0);
>
> gl_FragColor = color;
> //gl_FragColor = vec4((R), 1.);
> }
> ]]>
>
>

>
>


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