Results 1 to 3 of 3

Thread: A basic ripple warper

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2011

    A basic ripple warper

    Hello all,
    I'm planning to do a simple ripple warper to an image. When the user clicks on the image, it is consider as the center of the ripple and a ripple must be created. I'm planning to create a very basic script which has nothing to do with reflection or refraction. I don't know what kind of warping function to be used to get ripple effect. Can anyone help me? Thanks in advance.


  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    UK, London

    Re: A basic ripple warper

    You're in luck as I just happen to have one of those shaders...

    Vertex Shader:
    Code :
    #version 120
    varying vec2 texCoord0;
    void main(void)
      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
      texCoord0.xy =;
    Code :
    #version 120
    varying vec2 texCoord0;
    sceneTex (sampler2D): the final scene image.
    paramv2 (vec2): mouse position (in texture coord space: [0 ; 1]).
    time (float): shockwave elapsed time in second.
    paramv4 (vec3): shockwave parameters
    Ouputs: color buffer
    uniform sampler2D scenetex; // texunit #0
    uniform vec2 paramv2; // Mouse position
    uniform vec4 paramv4; // 10.0, 0.8, 0.1, effect elapsed time
    void main()
      vec2 uv = texCoord0.xy;
      vec2 texCoord = uv;
      float distancefromcenter = distance(uv, paramv2);
      if ( (distancefromcenter <= (paramv4.w + paramv4.z)) &amp;&amp;
           (distancefromcenter >= (paramv4.w - paramv4.z)) )
        float diff = (distancefromcenter - paramv4.w);
        float powDiff = 1.0 - pow(abs(diff*paramv4.x), paramv4.y);
        float diffTime = diff  * powDiff;
        vec2 diffUV = normalize(uv - paramv2);
        texCoord = uv + (diffUV * diffTime);
      gl_FragColor = texture2D(scenetex, texCoord);

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2011

    Re: A basic ripple warper

    Thanks for your reply BionicBytes. But if you don't mind can you explain the fragment shader part? I don't get it.


Similar Threads

  1. water ripple
    By sklim in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 08-14-2010, 04:01 AM
  2. water ripple + reflection
    By candy in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-07-2010, 04:11 PM
  3. water ripple calculation
    By wow in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-19-2004, 06:04 AM
  4. Making a ripple
    By Structural in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 01-05-2003, 12:31 PM
  5. Ripple Effect in 2D
    By Ashtray_W in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-15-2001, 11:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean