Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [FRAGMENT SHADER]
- precision mediump float;
- varying vec2 texCoords;
- uniform sampler2D render_texture;
- uniform vec2 screen_size;
- uniform vec2 swirl_center;
- uniform float swirl_radius;
- uniform float swirl_amount;
- uniform float swirl_strength;
- vec2 swirl(vec2 coords)
- {
- //Convert to poolar coordinates
- //Get the relative position to the swirl_center
- coords = coords - swirl_center;
- float r = length(coords);
- if(r <= swirl_radius)
- {
- float phi = atan(coords.y, coords.x);
- float distortion = pow(swirl_amount * ((swirl_radius - r) / swirl_radius), 2);
- if(swirl_amount >= 0)
- phi = phi + distortion;
- else
- phi = phi - distortion;
- coords.x = r * cos(phi);
- coords.y = r * sin(phi);
- }
- //Convert it back to global space
- return coords + swirl_center;
- }
- void main()
- {
- vec2 coords = texCoords * screen_size;
- coords = swirl(coords);
- coords /= screen_size;
- gl_FragColor = texture2D(render_texture, coords);
- }
- [VERTEX SHADER]
- layout(location = 0) in vec3 vertexPos;
- layout(location = 1) in vec2 vertexUV;
- varying vec2 texCoords;
- void main()
- {
- gl_Position = vec4(vertexPos, 1.f);
- texCoords = vertexUV;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement