Barrel / Distortion effect?

  • Example of denorm and clamping.

    > /////////////////////////////////////////////////////////
    // Barrel
    
    //The current foreground texture co-ordinate
    varying mediump vec2 vTex;
    //The foreground texture sampler, to be sampled at vTex
    uniform lowp sampler2D samplerFront;
    //The current foreground rectangle being rendered
    uniform mediump vec2 srcStart;
    uniform mediump vec2 srcEnd;
    //The current foreground source rectangle being rendered
    uniform mediump vec2 srcOriginStart;
    uniform mediump vec2 srcOriginEnd;
    //The current foreground source rectangle being rendered, in layout 
    uniform mediump vec2 layoutStart;
    uniform mediump vec2 layoutEnd;
    //The background texture sampler used for background - blending effects
    uniform lowp sampler2D samplerBack;
    //The current background rectangle being rendered to, in texture co-ordinates, for background-blending effects
    uniform mediump vec2 destStart;
    uniform mediump vec2 destEnd;
    //The time in seconds since the runtime started. This can be used for animated effects
    uniform mediump float seconds;
    //The size of a texel in the foreground texture in texture co-ordinates
    uniform mediump vec2 pixelSize;
    //The current layer scale as a factor (i.e. 1 is unscaled)
    uniform mediump float layerScale;
    //The current layer angle in radians.
    uniform mediump float layerAngle;
    
    //effect.fx
    precision mediump float;
    
    uniform mediump float scale;
    
    void main(void)
    {
    mediump vec2 n = (vTex - srcOriginStart) / (srcOriginEnd - srcOriginStart);
    
    vec2 st = n - 0.5;
    float theta = atan(st.x, st.y);
    float rad = sqrt(dot(st, st));
    rad *= 1.0 + scale * pow(rad, 2.0);
    
    n = clamp(vec2( 0.5 + sin(theta) * rad, n.y), vec2(0.), vec2(1.));
    
    gl_FragColor = texture2D(samplerFront, mix(srcOriginStart,srcOriginEnd,n));
    
    }
    

    Thank you for this and all who helped, managed to get this working as planned.

    A negative scale caused a pincushion along X and positive scale causes barrel along X.

    Thank you

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)