Forums > Jitter

texture coordinates for multiple texture glsl shader

September 4, 2006 | 10:26 am

hello,
i’m workin on a shader that masks and mixes multiple texutres.
i’m fiding a very curious thing;
my 3rd texture (uniform variable tex2 in the code below) doesn’t not receive its coordinates properly.
my fragment shader is good old "sh.passthru.xform.vp.glsl" which should pass thru coordinates for upto 8 separate textures.

however, if you look in the code below, line 148, you’ll see that i’m forced to use "texcoord1" when i’m reading texture points of "tex2". in this case things work out cuz my textures are the same size and all are in use all the time; however, if i DO actually use "texcoord2" then i only get the color of one pixel, i.e. texcoord2 is constant for whatever reason.

shader and patch are below…

—————jitter shader xml


Burn composite operator

texture dimensions

amp 0

amp 0

time 0

freq 0

amp 0

time 1

freq 1

amp 0

time 1

freq 1















< ![CDATA[

// texcoords
varying vec2 texcoord0;
varying vec2 texcoord1;
varying vec2 texcoord2;

//varying vec2 texcoord2;

// samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;
uniform sampler2DRect tex2;

// from outside
uniform vec2 texdim;
uniform float fade;
uniform float amp0;
uniform float time0;
uniform float freq0;
uniform float amp1;
uniform float time1;
uniform float freq1;
uniform float amp2;
uniform float time2;
uniform float freq2;

// entry point

float fm(float amp, float freq, float cf, float mf, float index, float time, float x)
{
float value = amp * cos(cf * (x+time) + index * cos(mf * (x+time)));
return(value);
}

float dist(float y,float fx)
{
//float d = float((y 0.));
//float d = (float((y
0.)))*abs(fx-y)/texdim[1]/fade;
float d = (float((y
0.)))*abs(fx-y)/fade;
d = atan(4.*sqrt(d))*.75
;
d = min(1.,d);
return(d);
}

void main()
{

float PI = 3.141592653589793238462643383279502884197169399375105820;
float x, y, fx, d, n;
vec4 mycolor;

n = 0.00001;

//texture 1 (red in test mode)
x = gl_TexCoord[0].s*PI*2./texdim[0];
y = gl_TexCoord[0].t/texdim[1]*2.-1.;
fx = fm(amp0,freq0,.2,3.,.1,time0,x);
d = dist(y,fx);
n = n + d;
// n = n + float(d>0.);

mycolor = d * texture2DRect(tex0, texcoord0);

//texture 2 (green in test mode)
x = gl_TexCoord[1].s*PI*2./texdim[0];
y = gl_TexCoord[1].t/texdim[1]*2.-1.;
fx = fm(amp1,freq1,.3,3.,1.,time1,x);
d = dist(y,fx);

n = n + d;
// n = n + float(d>0.);

mycolor = mycolor + d * texture2DRect(tex1, texcoord1);

//texture 3 (blue in test mode)
x = gl_TexCoord[2].s*PI*2./texdim[0];
y = gl_TexCoord[2].t/texdim[1]*2.-1.;
fx = fm(amp2,freq2,3.,.5,5.,time2,x);
d = dist(y,fx);

n = n + d;
// n = n + float(d>0.);

mycolor = mycolor + d * texture2DRect(tex2, texcoord1);
//mycolor = mycolor / n;
mycolor = mycolor / max(n,1.);
gl_FragColor = mycolor;
}

]]>

——————– patch
#P window setfont "Sans Serif" 12.;
#P window linecount 1;
#P comment 371 278 36 196620 test;
#B color 14;
#P toggle 350 278 15 0;
#P window setfont "Sans Serif" 9.;
#P hidden message 646 299 61 196617 1600 1400;
#P hidden message 543 302 37 196617 32 24;
#P message 592 301 49 196617 720 480;
#P window setfont "Sans Serif" 12.;
#P comment 9 52 106 196620 5. start render;
#B color 14;
#P toggle 150 489 15 0;
#P window setfont "Sans Serif" 9.;
#P message 150 507 52 196617 interp $1;
#P window setfont "Sans Serif" 12.;
#P comment 402 143 147 196620 2. choose texture dim;
#B color 14;
#P window setfont "Sans Serif" 9.;
#P hidden message 333 127 37 196617 36 24;
#P hidden message 364 166 49 196617 720 480;
#P message 345 146 49 196617 360 240;
#P window setfont "Sans Serif" 12.;
#P comment 599 272 107 196620 4. set textures;
#B color 14;
#P comment 701 79 102 196620 1. read shader;
#B color 14;
#P comment 421 208 118 196620 3. read movies;
#B color 14;
#P button 404 210 15 0;
#P window setfont "Sans Serif" 9.;
#N vpatcher 575 85 1665 881;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P comment 761 74 91 196617 test;
#P inlet 738 37 15 0;
#P newex 134 290 48 196617 loadbang;
#P message 692 291 95 196617 setall 255 0 0 255;
#P newex 672 315 129 196617 jit.matrix 4 char 360 240;
#P message 460 291 95 196617 setall 255 0 255 0;
#P newex 440 315 129 196617 jit.matrix 4 char 360 240;
#P newex 79 184 40 196617 b 3;
#P user gswitch2 27 124 39 32 0 0;
#P message 210 290 95 196617 setall 255 255 0 0;
#P newex 190 314 129 196617 jit.matrix 4 char 360 240;
#P outlet 941 291 15 0;
#P newex 887 185 110 196617 prepend param texdim;
#P inlet 563 29 15 0;
#P newex 27 183 40 196617 b 3;
#P inlet 47 53 15 0;
#P inlet 636 29 15 0;
#P button 550 137 15 0;
#P window linecount 1;
#P message 798 183 56 196617 dim $1 $2;
#P user jit.fpsgui 69 388 60 196617 3;
#P user jit.pwindow 544 390 27 21 0 1 0 0 1 0;
#P user jit.pwindow 139 391 27 21 0 1 0 0 1 0;
#P user jit.pwindow 332 389 27 21 0 1 0 0 1 0;
#P newex 573 393 160 196617 jit.gl.texture wavey @name tex2;
#P message 636 195 86 196617 read blading.mov;
#P newex 573 361 142 196617 jit.qt.movie 360 240 @vol 0.;
#P newex 361 391 160 196617 jit.gl.texture wavey @name tex1;
#P newex 167 391 160 196617 jit.gl.texture wavey @name tex0;
#P comment 233 55 91 196617 DV Source Movies;
#P message 375 190 83 196617 read dishes.mov;
#P newex 361 360 142 196617 jit.qt.movie 360 240 @vol 0.;
#P message 195 183 80 196617 read dozer.mov;
#P newex 167 357 142 196617 jit.qt.movie 360 240 @vol 0.;
#P connect 31 0 24 0;
#P connect 24 0 18 0;
#P connect 17 0 24 1;
#P connect 0 0 13 0;
#P connect 24 1 25 0;
#P connect 0 0 11 0;
#P fasten 14 0 0 0 803 234 172 234;
#P fasten 1 0 0 0 200 234 172 234;
#P fasten 18 0 0 0 32 235 172 235;
#P connect 0 0 5 0;
#P connect 22 0 5 0;
#P connect 14 0 22 0;
#P fasten 25 0 22 0 84 247 195 247;
#P connect 23 0 22 0;
#P connect 15 0 1 0;
#P connect 30 0 23 0;
#P connect 2 0 10 0;
#P fasten 14 0 2 0 803 208 366 208;
#P fasten 3 0 2 0 380 209 366 209;
#P fasten 18 1 2 0 47 237 366 237;
#P connect 2 0 6 0;
#P connect 26 0 6 0;
#P connect 15 0 3 0;
#P connect 14 0 26 0;
#P fasten 25 1 26 0 99 256 445 256;
#P connect 27 0 26 0;
#P connect 30 0 27 0;
#P connect 7 0 12 0;
#P connect 16 0 15 0;
#P fasten 14 0 7 0 803 208 578 208;
#P fasten 8 0 7 0 641 210 578 210;
#P fasten 18 2 7 0 62 237 578 237;
#P connect 7 0 9 0;
#P connect 28 0 9 0;
#P connect 15 0 8 0;
#P fasten 25 2 28 0 114 267 677 267;
#P connect 29 0 28 0;
#P connect 14 0 28 0;
#P connect 30 0 29 0;
#P connect 19 0 14 0;
#P connect 19 0 20 0;
#P connect 20 0 21 0;
#P pop;
#P newobj 275 279 57 196617 p textures;
#P toggle 643 509 15 0;
#P message 643 527 44 196617 fsaa $1;
#P message 606 347 247 196617 dim $1 $2 , dest_dim $1 $2 , texture tex0 tex1 tex2;
#N vpatcher 318 67 1454 685;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 949 249 63 196617 loadmess 4.;
#P window linecount 0;
#P message 636 87 31 196617 120.;
#P user gswitch2 356 35 39 32 1 0;
#P flonum 198 265 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 1019 354 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 1015 379 75 196617 param fade $1;
#P newex 638 316 55 196617 slide 3. 3.;
#P newex 292 317 55 196617 slide 3. 3.;
#P window linecount 0;
#P newex 18 317 55 196617 slide 3. 3.;
#P number 337 116 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 549 122 40 196617 / 128.;
#P newex 467 125 40 196617 / 128.;
#P newex 393 126 40 196617 / 128.;
#P newex 540 90 65 196617 drunk 128 2;
#P newex 464 92 65 196617 drunk 128 2;
#P window linecount 0;
#P newex 392 93 65 196617 drunk 128 2;
#P flonum 670 349 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 650 384 80 196617 param amp2 $1;
#P flonum 769 205 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 721 228 46 196617 / 1000.;
#P flonum 896 346 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 895 381 81 196617 param freq2 $1;
#P flonum 758 350 113 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 756 387 82 196617 param time2 $1;
#P flonum 317 344 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 303 379 80 196617 param amp1 $1;
#P flonum 47 344 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 18 381 80 196617 param amp0 $1;
#P flonum 422 200 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 147 202 57 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 374 223 40 196617 / 800.;
#P newex 185 103 48 196617 cpuclock;
#P flonum 568 346 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 198 346 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 200 381 81 196617 param freq0 $1;
#P message 567 381 81 196617 param freq1 $1;
#P newex 88 236 40 196617 / 500.;
#P flonum 411 345 113 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 409 382 82 196617 param time1 $1;
#P flonum 108 344 75 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 106 381 82 196617 param time0 $1;
#P inlet 184 36 15 0;
#P outlet 327 530 15 0;
#P connect 30 0 34 0;
#P connect 34 0 15 0;
#P connect 34 0 16 0;
#P connect 11 0 6 0;
#P connect 3 0 2 0;
#P connect 6 0 3 0;
#P connect 13 0 6 1;
#P connect 1 0 11 0;
#P connect 9 0 8 0;
#P connect 31 0 35 0;
#P connect 35 0 17 0;
#P connect 35 0 18 0;
#P connect 21 0 0 0;
#P connect 19 0 0 0;
#P connect 25 0 0 0;
#P connect 17 0 0 0;
#P connect 15 0 0 0;
#P connect 8 0 0 0;
#P connect 7 0 0 0;
#P connect 4 0 0 0;
#P connect 2 0 0 0;
#P connect 37 0 0 0;
#P connect 27 0 33 0;
#P connect 11 0 12 0;
#P connect 1 0 40 1;
#P connect 40 0 27 0;
#P connect 41 0 30 0;
#P connect 27 0 30 0;
#P connect 14 0 12 1;
#P connect 5 0 4 0;
#P connect 12 0 5 0;
#P connect 40 0 28 0;
#P connect 41 0 31 0;
#P connect 28 0 31 0;
#P connect 40 0 29 0;
#P connect 29 0 32 0;
#P connect 41 0 32 0;
#P connect 10 0 7 0;
#P connect 32 0 36 0;
#P connect 36 0 25 0;
#P connect 36 0 26 0;
#P connect 11 0 23 0;
#P connect 20 0 19 0;
#P connect 24 0 23 1;
#P connect 23 0 20 0;
#P connect 22 0 21 0;
#P connect 38 0 37 0;
#P connect 42 0 38 0;
#P pop;
#P newobj 173 254 50 196617 p control;
#P hidden newex 516 39 48 196617 loadbang;
#P message 568 80 125 196617 read wave-masks-08.jxs;
#P newex 568 40 157 196617 mxj quickie wave-masks-08.jxs;
#P message 406 470 34 196617 reset;
#P newex 406 489 80 196617 jit.gl.handle foo;
#P newex 224 552 203 196617 jit.gl.videoplane wavey @scale 1.333 1. 1.;
#P newex 224 414 130 196617 jit.gl.slab wavey @adapt 1;
#P toggle 594 510 15 0;
#P message 594 528 46 196617 sync $1;
#P toggle 521 509 15 0;
#P newex 521 485 38 196617 sel 27;
#P message 521 527 70 196617 fullscreen $1;
#P newex 521 551 162 196617 jit.window wavey @size 720 480;
#P user jit.fpsgui 39 230 60 196617 0;
#P number 67 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 20 76 15 0;
#P newex 20 102 51 196617 qmetro 2;
#P newex 20 135 265 196617 t b b erase b b b;
#P newex 20 446 142 196617 jit.gl.render wavey @ortho 2;
#P newex 521 461 40 196617 key;
#P comment 234 464 109 196617 Videoplane for display;
#P connect 18 0 19 0;
#P connect 5 0 4 0;
#P connect 4 0 3 0;
#P fasten 3 2 2 0 127 299 25 299;
#P fasten 3 0 2 0 25 299 25 299;
#P fasten 3 1 7 0 76 177 44 177;
#P connect 6 0 4 1;
#P connect 35 0 34 0;
#P fasten 3 3 21 0 178 181 178 181;
#P connect 21 0 14 0;
#P connect 22 0 14 0;
#P connect 3 4 14 0;
#P connect 25 0 14 0;
#P fasten 19 0 14 0 573 269;
#P fasten 16 0 15 0 411 516 229 516;
#P connect 14 0 15 0;
#P connect 34 0 15 0;
#P fasten 3 5 25 0 280 163 280 163;
#P hidden connect 32 0 25 1;
#P hidden connect 31 0 25 1;
#P connect 30 0 25 1;
#P connect 26 0 25 2;
#P connect 40 0 25 3;
#P connect 17 0 16 0;
#P fasten 1 0 10 0 526 478 526 478;
#P fasten 10 0 11 0 526 499 526 499;
#P connect 11 0 9 0;
#P fasten 9 0 8 0 526 546 526 546;
#P fasten 12 0 8 0 599 546 526 546;
#P fasten 23 0 8 0 648 548 638 548 526 548;
#P hidden connect 20 0 19 0;
#P connect 13 0 12 0;
#P connect 37 0 22 0;
#P hidden connect 38 0 22 0;
#P hidden connect 39 0 22 0;
#P connect 24 0 23 0;
#P window clipboard copycount 42;


Viewing 1 post (of 1 total)