[PD] gem pix shear
jack at rybn.org
Sun Aug 2 14:31:47 CEST 2009
Good explanations Marius. Thanx to share this.
Le mardi 28 juillet 2009 à 16:18 -0300, marius schebella a écrit :
> 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.
> 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.x is the original x position. (a float value)
> // gl_TexCoord.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.x+gl_TexCoord.y*shear.x;
> float y = gl_TexCoord.y+gl_TexCoord.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
> > 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.
> Pd-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
More information about the Pd-list