Forums > Jitter

repos shader

March 28, 2007 | 4:42 pm

I’m starting to jump into shaders (again), and I’m taking a look at the td.repos shader. I’m sorta confused, though, as it seems that the repos matrix really only needs to be 1 plane, as the 2nd plane seems ignored – see adjoining patch. Is that a mistake in the helper patch ("meant to be 1 plane") or a mistake in the shader ("oh, forgot to…")?
I’d love to figure out how to make an analog of jit.repos, where plane 0 maps x, and plane 1 maps y. As it is, it seems to apply the same distortion to x and y using plane 0…

Peter

#P window setfont Arial 9.;
#P window linecount 4;
#P comment 183 465 114 131137545 this just demonstrates that the 2nd plane in the repos matrix seems to be meaningless;
#P window linecount 1;
#P newex 221 312 27 131137545 t b i;
#P user jit.pwindow 337 398 47 35 0 1 0 0 1 0;
#P user jit.pwindow 389 398 47 35 0 1 0 0 1 0;
#P newex 341 375 58 131137545 jit.unpack 2;
#P newex 285 333 48 131137545 jit.pack 2;
#P newex 309 311 91 131137545 jit.op @op * @val 0;
#P toggle 184 444 15 0;
#P newex 219 291 27 131137545 + 1;
#P newex 254 351 52 131137545 switch 2 1;
#P newex 275 268 45 131137545 jit.matrix;
#P newex 285 290 58 131137545 jit.unpack 2;
#P hidden newex 275 228 48 131137545 loadbang;
#P newex 275 247 97 131137545 jit.noise 1 char 10 10;
#P toggle 500 153 15 0;
#P toggle 455 153 15 0;
#P newex 410 172 100 131137545 pak boundmode 0. 0.;
#P toggle 398 152 15 0;
#P toggle 366 152 15 0;
#P newex 334 172 75 131137545 pak mode 0. 0.;
#P flonum 312 152 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 277 152 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 254 172 69 131137545 pak amt 0. 0.;
#P newex 254 200 76 131137545 prepend param;
#P newex 264 405 32 131137545 print;
#P message 168 202 67 131137545 getparamlist;
#P newex 21 145 70 131137545 jit.window fa;
#P newex 158 425 182 131137545 jit.gl.videoplane fa @scale 1.333 1. 1.;
#P newex 21 123 121 131137545 jit.gl.render fa @ortho 2;
#P newex 21 79 58 131137545 t b b erase;
#P newex 158 382 149 131137545 jit.gl.slab fa @file td.repos.jxs;
#P message 274 75 27 131137545 stop;
#P flonum 302 55 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 302 75 42 131137545 rate $1;
#P message 199 76 74 131137545 read dozer.mov;
#P flonum 62 37 35 9 0.5 0 1 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 21 37 15 0;
#P newex 21 58 51 131137545 qmetro 2;
#P newex 158 127 144 131137545 jit.qt.movie 320 240;
#P window setfont "Sans Serif" 9.;
#P comment 200 445 100 196617 on = blank 2nd plane;
#P connect 29 0 30 1;
#P connect 29 0 28 0;
#P connect 38 0 29 0;
#P connect 38 1 30 0;
#P connect 31 0 38 0;
#P connect 30 0 9 1;
#P connect 30 0 35 0;
#P connect 3 0 2 0;
#P connect 2 0 10 0;
#P connect 10 0 11 0;
#P fasten 10 2 11 0 74 105 26 105;
#P connect 4 0 2 1;
#P fasten 5 0 1 0 204 117 163 117;
#P fasten 8 0 1 0 279 117 163 117;
#P fasten 6 0 1 0 307 117 163 117;
#P fasten 10 1 1 0 50 117 163 117;
#P fasten 14 0 9 0 173 223 163 223;
#P connect 1 0 9 0;
#P fasten 16 0 9 0 259 223 163 223;
#P connect 9 0 12 0;
#P connect 32 0 31 0;
#P connect 17 0 16 0;
#P fasten 20 0 16 0 339 194 259 194;
#P fasten 23 0 16 0 415 194 259 194;
#P fasten 9 1 15 0 302 404 269 404;
#P connect 26 0 29 0;
#P connect 18 0 17 1;
#P connect 28 0 34 0;
#P connect 34 0 30 2;
#P connect 7 0 6 0;
#P connect 28 1 33 0;
#P connect 19 0 17 2;
#P hidden connect 27 0 26 0;
#P connect 33 0 34 1;
#P connect 35 0 37 0;
#P connect 21 0 20 1;
#P connect 22 0 20 2;
#P connect 35 1 36 0;
#P connect 24 0 23 1;
#P connect 25 0 23 2;
#P window clipboard copycount 40;


March 28, 2007 | 6:52 pm

Hello Peter,

the result you are seeing is probably related to how are planes in
jit.matrix mapped to texture. If you supply repos shader with 4-plane
(argb) matrix, ‘red’ and ‘green’ plane define how much pixels move
horizontally and verticaly.
checkout patch pasted below.

cheers,
nesa

#P window setfont "Sans Serif" 9.;
#P flonum 736 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P comment 687 211 48 196617 green:y;
#P comment 597 211 34 196617 red: x;
#P newex 613 382 79 196617 pak 0. 0. 0. 0.;
#P window setfont Arial 9.;
#P newex 613 405 96 131137545 jit.matrix 4 char 10 10;
#P window setfont "Sans Serif" 9.;
#P comment 685 348 34 196617 blue;
#P hidden message 363 112 14 196617 1;
#P flonum 684 363 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 591 362 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont Arial 9.;
#P hidden newex 395 57 48 131137545 loadbang;
#P toggle 502 164 15 0;
#P toggle 458 164 15 0;
#P newex 413 189 100 131137545 pak boundmode 0. 0.;
#P toggle 401 163 15 0;
#P toggle 369 163 15 0;
#P newex 337 189 75 131137545 pak mode 0. 0.;
#P flonum 315 163 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 280 163 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 257 189 69 131137545 pak amt 0. 0.;
#P newex 257 217 76 131137545 prepend param;
#P newex 264 405 32 131137545 print;
#P message 168 202 67 131137545 getparamlist;
#P newex 21 145 70 131137545 jit.window fa;
#P newex 158 425 182 131137545 jit.gl.videoplane fa @scale 1.333 1. 1.;
#P newex 21 123 121 131137545 jit.gl.render fa @ortho 2;
#P newex 21 79 58 131137545 t b b erase;
#P newex 158 382 149 131137545 jit.gl.slab fa @file td.repos.jxs;
#P message 274 75 27 131137545 stop;
#P flonum 302 55 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 302 75 42 131137545 rate $1;
#P message 199 76 74 131137545 read dozer.mov;
#P flonum 62 37 35 9 0.5 0 1 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 21 37 15 0;
#P newex 21 58 51 131137545 qmetro 2;
#P newex 158 127 144 131137545 jit.qt.movie 320 240;
#P window setfont "Sans Serif" 9.;
#P comment 589 345 34 196617 alpha;
#P flonum 559 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P hidden flonum 559 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222
0 0 0;
#P noclick;
#P hidden flonum 736 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222
0 0 0;
#P noclick;
#P connect 31 0 35 3;
#P connect 30 0 35 0;
#P connect 34 0 12 1;
#P fasten 38 0 35 2 664 287;
#P fasten 1 0 35 2 600 253 706 253 664 287;
#P fasten 2 0 35 1 641 286;
#P connect 35 0 34 0;
#P hidden connect 32 0 21 0;
#P hidden connect 32 0 22 0;
#P hidden connect 32 0 24 0;
#P hidden connect 32 0 25 0;
#P hidden connect 29 0 32 0;
#P connect 28 0 26 2;
#P connect 27 0 26 1;
#P connect 25 0 23 2;
#P connect 24 0 23 1;
#P connect 22 0 20 2;
#P connect 10 0 9 0;
#P connect 21 0 20 1;
#P fasten 12 1 18 0 302 404 269 404;
#P fasten 26 0 19 0 418 211 262 211;
#P fasten 23 0 19 0 342 211 262 211;
#P connect 20 0 19 0;
#P connect 12 0 15 0;
#P fasten 19 0 12 0 262 240 163 240;
#P connect 4 0 12 0;
#P fasten 17 0 12 0 173 223 163 223;
#P fasten 13 1 4 0 50 117 163 117;
#P fasten 9 0 4 0 307 117 163 117;
#P fasten 11 0 4 0 279 117 163 117;
#P fasten 8 0 4 0 204 117 163 117;
#P connect 7 0 5 1;
#P fasten 13 2 14 0 74 105 26 105;
#P connect 13 0 14 0;
#P connect 5 0 13 0;
#P connect 6 0 5 0;
#P fasten 0 0 35 1 705 253 661 253 699 149 694 149 656 253 599 253
641 287;
#P window clipboard copycount 39;


March 28, 2007 | 7:19 pm

Hi Peter,
Yes, I goofed. By default, a 2-plane matrix get passed to a texture as
lumalpha color mode, which means that inside of a shader these planes
get assigned as (lum,lum,lum,alpha). So, the code for accessing the
vector should be "look.ra" or "look.xw" instead of "look.xy". I hope
that makes sense. The following shader code should work.

Andrew



distortion based on position map in second inlet






< ![CDATA[

// Andrew Benson – andrewb@cycling74.com
//Copyright 2006 – Cycling ’74

//spatial repositioning based on 2D LUT

//setup for 2 texture
varying vec2 texcoord0;
varying vec2 texcoord1;
varying vec2 texdim0;
uniform vec2 amt;
uniform vec2 mode;
uniform vec2 boundmode;
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

void main()
{

vec4 look = texture2DRect(tex1,texcoord1);//sample repos texture
vec2 rela = ((look.ra-0.5)*texdim0*amt*2.)+texcoord0;//relative
coordinates
vec2 abso = look.ra*texdim0*amt;//absolute coordinates
vec2 coord = mix(abso,rela,clamp(mode, 0., 1.));

vec2 wrap = mod(coord,texdim0);
vec2 fold = mix(wrap,texdim0-wrap,floor(mod(coord,
texdim0*2.)/texdim0));

coord = mix(wrap,fold,clamp(boundmode, 0., 1.)); //use boundmode
vec4 repos = texture2DRect(tex0, coord);

// output texture
gl_FragColor = repos;
}
]]>


March 28, 2007 | 7:27 pm

nice use of patch chords, there, nesa

On 3/28/07, nesa wrote:
> Hello Peter,
>
> the result you are seeing is probably related to how are planes in
> jit.matrix mapped to texture. If you supply repos shader with 4-plane
> (argb) matrix, ‘red’ and ‘green’ plane define how much pixels move
> horizontally and verticaly.
> checkout patch pasted below.
>
> cheers,
> nesa
>
> #P window setfont "Sans Serif" 9.;
> #P flonum 736 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P comment 687 211 48 196617 green:y;
> #P comment 597 211 34 196617 red: x;
> #P newex 613 382 79 196617 pak 0. 0. 0. 0.;
> #P window setfont Arial 9.;
> #P newex 613 405 96 131137545 jit.matrix 4 char 10 10;
> #P window setfont "Sans Serif" 9.;
> #P comment 685 348 34 196617 blue;
> #P hidden message 363 112 14 196617 1;
> #P flonum 684 363 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 591 362 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window setfont Arial 9.;
> #P hidden newex 395 57 48 131137545 loadbang;
> #P toggle 502 164 15 0;
> #P toggle 458 164 15 0;
> #P newex 413 189 100 131137545 pak boundmode 0. 0.;
> #P toggle 401 163 15 0;
> #P toggle 369 163 15 0;
> #P newex 337 189 75 131137545 pak mode 0. 0.;
> #P flonum 315 163 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 280 163 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 257 189 69 131137545 pak amt 0. 0.;
> #P newex 257 217 76 131137545 prepend param;
> #P newex 264 405 32 131137545 print;
> #P message 168 202 67 131137545 getparamlist;
> #P newex 21 145 70 131137545 jit.window fa;
> #P newex 158 425 182 131137545 jit.gl.videoplane fa @scale 1.333 1. 1.;
> #P newex 21 123 121 131137545 jit.gl.render fa @ortho 2;
> #P newex 21 79 58 131137545 t b b erase;
> #P newex 158 382 149 131137545 jit.gl.slab fa @file td.repos.jxs;
> #P message 274 75 27 131137545 stop;
> #P flonum 302 55 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
> #P message 302 75 42 131137545 rate $1;
> #P message 199 76 74 131137545 read dozer.mov;
> #P flonum 62 37 35 9 0.5 0 1 2001 0 0 0 221 221 221 222 222 222 0 0 0;
> #P toggle 21 37 15 0;
> #P newex 21 58 51 131137545 qmetro 2;
> #P newex 158 127 144 131137545 jit.qt.movie 320 240;
> #P window setfont "Sans Serif" 9.;
> #P comment 589 345 34 196617 alpha;
> #P flonum 559 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P hidden flonum 559 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222
> 0 0 0;
> #P noclick;
> #P hidden flonum 736 209 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222
> 0 0 0;
> #P noclick;
> #P connect 31 0 35 3;
> #P connect 30 0 35 0;
> #P connect 34 0 12 1;
> #P fasten 38 0 35 2 664 287;
> #P fasten 1 0 35 2 600 253 706 253 664 287;
> #P fasten 2 0 35 1 641 286;
> #P connect 35 0 34 0;
> #P hidden connect 32 0 21 0;
> #P hidden connect 32 0 22 0;
> #P hidden connect 32 0 24 0;
> #P hidden connect 32 0 25 0;
> #P hidden connect 29 0 32 0;
> #P connect 28 0 26 2;
> #P connect 27 0 26 1;
> #P connect 25 0 23 2;
> #P connect 24 0 23 1;
> #P connect 22 0 20 2;
> #P connect 10 0 9 0;
> #P connect 21 0 20 1;
> #P fasten 12 1 18 0 302 404 269 404;
> #P fasten 26 0 19 0 418 211 262 211;
> #P fasten 23 0 19 0 342 211 262 211;
> #P connect 20 0 19 0;
> #P connect 12 0 15 0;
> #P fasten 19 0 12 0 262 240 163 240;
> #P connect 4 0 12 0;
> #P fasten 17 0 12 0 173 223 163 223;
> #P fasten 13 1 4 0 50 117 163 117;
> #P fasten 9 0 4 0 307 117 163 117;
> #P fasten 11 0 4 0 279 117 163 117;
> #P fasten 8 0 4 0 204 117 163 117;
> #P connect 7 0 5 1;
> #P fasten 13 2 14 0 74 105 26 105;
> #P connect 13 0 14 0;
> #P connect 5 0 13 0;
> #P connect 6 0 5 0;
> #P fasten 0 0 35 1 705 253 661 253 699 149 694 149 656 253 599 253
> 641 287;
> #P window clipboard copycount 39;
>
>
>


March 28, 2007 | 7:31 pm

I should also note that with the given changes, this shader will take
the first and fourth plane of an input texture (as opposed to matrix
input). This might not be preferred in some cases.

AB


March 30, 2007 | 3:32 pm

nesa: bottoms up :)
This helps a lot.

P.


March 30, 2007 | 8:47 pm

for the sake of the archives, it is also worth noting that becuase the input texture is char 0-255 data, it doesn’t seem to be an exact analog of jit.repos, which takes long data as the reposition map. Absolute maps for anything images with resolution higher than 255×255 won’t be able to remap "any pixel anywhere".
That’s not to say this shader is not totally bitchin’, but it does illuminate a limitation, I suppose.


March 30, 2007 | 10:07 pm

Toy could use a compression technique and unpack the [0-255] data
which is [0, 1] in the shader and instead make it [-1, 1] or some
other range.

wes

On 3/30/07, pnyboer

wrote:
>
> for the sake of the archives, it is also worth noting that becuase the input texture is char 0-255 data, it doesn’t seem to be an exact analog of jit.repos, which takes long data as the reposition map. Absolute maps for anything images with resolution higher than 255×255 won’t be able to remap "any pixel anywhere".
> That’s not to say this shader is not totally bitchin’, but it does illuminate a limitation, I suppose.
> –
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> The Lifespan
> 2 oz brandy
> 1/2 oz orgeat
> 1/2 oz maraschino
> 3/4 oz mix of (meyer) lemon and (yellow) grapefruit juice
> Shake with ice and serve in a Pernod-rinsed cocktail glass
>


March 30, 2007 | 10:34 pm

One solution to this might be to use the "relative" mode, @param mode 1.
And use the param amt to scale the distortion. Another solution would
be to pass in your matrix as float32 (0.-1.), in which case you won’t
get any linear interpolation. This is a limitation of most hardware
when using floating-point textures.

AB


March 30, 2007 | 10:36 pm

Sorry, misunderstood your previous post. The real answer is to use
float textures although these have issues as well.

wes

On 3/30/07, Wesley Smith wrote:
> Toy could use a compression technique and unpack the [0-255] data
> which is [0, 1] in the shader and instead make it [-1, 1] or some
> other range.
>
> wes
>
> On 3/30/07, pnyboer

wrote:
> >
> > for the sake of the archives, it is also worth noting that becuase the input texture is char 0-255 data, it doesn’t seem to be an exact analog of jit.repos, which takes long data as the reposition map. Absolute maps for anything images with resolution higher than 255×255 won’t be able to remap "any pixel anywhere".
> > That’s not to say this shader is not totally bitchin’, but it does illuminate a limitation, I suppose.
> > –
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > The Lifespan
> > 2 oz brandy
> > 1/2 oz orgeat
> > 1/2 oz maraschino
> > 3/4 oz mix of (meyer) lemon and (yellow) grapefruit juice
> > Shake with ice and serve in a Pernod-rinsed cocktail glass
> >
>


March 30, 2007 | 11:01 pm

the reason I found this out was the unusual results I was getting trying to use the cartopol example in the jit.repos.help file. I finally realized it was becuause of the need for long types to describe the pixel coordinates…


March 30, 2007 | 11:02 pm

but it is good to know that the floating point textures will be left un-interpolated – I was wondering how to get rid of that!


March 30, 2007 | 11:10 pm

It probably wouldn’t be too hard to put together an upsampling shader
that does 4-point linear interpolation using the fract(xy) and 3 mix()
operations.

AB

pnyboer wrote:
> but it is good to know that the floating point textures will be left un-interpolated – I was wondering how to get rid of that!
> –
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> The Lifespan
> 2 oz brandy
> 1/2 oz orgeat
> 1/2 oz maraschino
> 3/4 oz mix of (meyer) lemon and (yellow) grapefruit juice
> Shake with ice and serve in a Pernod-rinsed cocktail glass


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