Monday, June 7, 2010

Explosion and implosion Pixel Shader

Explosion/Implosion filter can be modeled by shifting pixel outwards/towards the center of image by value which is proportional to pixel distance from the center of image.
Explosion/Implosion pixel shader code in GLSL:




uniform sampler2D tex;

void main()
{
vec2 cen = vec2(0.5,0.5) - gl_TexCoord[0].xy;
vec2 mcen = - // delete minus for implosion effect
0.07*log(length(cen))*normalize(cen);
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy+mcen);
}




By applying this filter to image below

we get such explosion effect

and such implosion effect

2 comments:

  1. Hi,

    I want to achieve a similar effect of implosion but linear. So what i want is to cut the center part of image and, join the both halfs without any sharp cut. I am able to cut the center part by below logic, but how to achieve a smooth merge, between them, is what i am wondering , right now there is a sharp cut. Something like edge blending, by blurring both halfs?
    Would appreciate your help. Below code achieves the cut of centre part.

    vec4 CurrentColor = texture2D(videoFrame, textureCoordinate.xy);
    if(textureCoordinate.y < 0.5){
    CurrentColor = texture2D(videoFrame,vec2(textureCoordinate.x,(textureCoordinate.y-0.125)));

    }
    else{
    CurrentColor = texture2D(videoFrame,vec2(textureCoordinate.x,(textureCoordinate.y+0.125)));
    }

    gl_FragColor = CurrentColor;

    ReplyDelete
  2. Please define the "smooth merge". Only YOU know how center pixels should look like ...

    ReplyDelete

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