Tuesday, June 15, 2010

Self-projection Pixel Shader

Image is several times scaled and projected on itself. This concrete GLSL pixel shader projects image on itself 2 times:

uniform sampler2D tex;

bool inRectangle(in vec2 xloc, in vec2 loc, in vec2 size) {
return xloc[0] >= loc[0] &&
xloc[1] >= loc[1] &&
xloc[0] <= loc[0]+size[0] &&
xloc[1] <= loc[1]+size[1];

void main()
vec2 start1 = vec2(0.19,0.11);
vec2 size1 = vec2(0.495,0.285);
vec2 start2 = start1 + start1*size1;
vec2 size2 = size1*size1;
if (inRectangle(gl_TexCoord[0].xy, start2, size2))
gl_FragColor = texture2D(tex, (gl_TexCoord[0].xy - start2)/size2);
else if (inRectangle(gl_TexCoord[0].xy, start1, size1))
gl_FragColor = texture2D(tex, (gl_TexCoord[0].xy - start1)/size1);
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);


and self-projected version of it

No comments:

Post a Comment

Comment will be posted after comment moderation.
Thank you for your appreciation.