[PD] gem pix shear

marius schebella marius.schebella at gmail.com
Tue Jul 28 21:18:28 CEST 2009


Py Fave wrote:
> so nice .
> exactly a good starting point for me .
> simple and efficient.
> you made it specially for me ? :-)
> 
> i'm trying to learn some glsl and i am not really fluent in it for the 
> moment.
> to say the less.
> but reading your code makes me willing to try things.

hi,
yes, atm I am trying to port shaders to pd and help people get started 
with it (it's part of my work for pdcon09, there is more to come...).

here is a version that will make it more clear what is going on. it does 
exactly the same thing as the shader I posted before, but splits the 
steps and has more comments.

------ snip stripeshear.frag ------

// create diamond pattern
// shear (x/y) will change the angle of the diamonds
// offset (x/y) will move pattern left/right/up/down
// resize (x/y) will resize the height/width

// sampler2D is the texture connected in Gem
uniform sampler2D texture;

// the data type vec2 means a vector of 2 floats,
// to set this value from Pd send a list, e.g.
// "shear 1.5 -0.7"
uniform vec2 shear;
uniform vec2 offset;
uniform vec2 resize;

// take the pixel from position x/y and apply a new location to it
// in the last line "texture" means the particular pixel
// and "texCoord" the position where it will be drawn
// the rest is the transformation from the original position to the // 
diamond pattern
void main(void)
{	
	// gl_TexCoord[0].x is the original x position. (a float value)
	// gl_TexCoord[0].y the y position.
	// to shear the image add an offset based on the x/y position
	// and the factor "shear".
	float x = gl_TexCoord[0].x+gl_TexCoord[0].y*shear.x;
	float y = gl_TexCoord[0].y+gl_TexCoord[0].x*shear.y;

	// to shift the whole pattern right/left or up down
	// add an offset
	// to access the values of the vector you can use
	// shear.xy (both) or shear.x or shear.y
	// shear.s is the same as shear.x and the same as
	// shear.r (letters stand for typical vectors: stuv, xyz, rgba)
	x = x + offset.x;
	y = y + offset.y;
	
	// finally multiply the position offset to change
	// the size of x and/or y
	x = x*resize.x;
	y = y*resize.y;
	
	// this step is not really necessary, but shows
	// how to put 2 floats into a vec2
	vec2 texCoord = vec2(x,y);

	// finally output the result as
	// gl_FragColor, which is a built-in glsl function
	gl_FragColor = texture2D(texture, texCoord);
}


-------- snip end

marius.








> 
> Thanks
> 
> py
> 
> 
> 2009/7/28 marius schebella <marius.schebella at gmail.com 
> <mailto:marius.schebella at gmail.com>>
> 
>     Py Fave wrote:
> 
>         Thanks for your help.
> 
>         i would like to output a pix with this transformation,with image
>         wrapping around ,
>         so shearXY is not very practical in my situation.
> 
>         i would prefer to avoid using pix_snap too.
> 
>         i need it to be quite fast, working on a live 25 fps
>         720*576(cropped to square) video feed.
> 
>         any other otions?
> 
>         would a GLSL shader do it ?
> 
> 
>     look at the attached shader, maybe it does what you want?
>     marius.
> 
> 





More information about the Pd-list mailing list