Back to shaders
Shader test bench
V002 CRT Displacement.fs
runnable fragment
Complete GLSL fragment shader. Stronghold runs it directly when the browser can compile it.
Code
uniform sampler2D inputImage;
uniform float Amount;
precision mediump float;
/*{
"CATEGORIES": [
"Distortion Effect",
"Retro",
"v002"
],
"CREDIT": "by vade",
"DESCRIPTION": "CRT Displacement, emulating the look of curved CRT Displays",
"INPUTS": [
{
"NAME": "inputImage",
"TYPE": "image"
},
{
"DEFAULT": 0.5,
"MAX": 1,
"MIN": 0,
"NAME": "Amount",
"TYPE": "float"
}
],
"ISFVSN": "2"
}
*/
void main (void)
{
vec2 t1, t2;
vec2 ctr = u_resolution / 2.0;
t1 = gl_FragCoord.xy;
float a = -0.0;
float b = -.1 * Amount;
float c = -.0;
float d = 1.0 - 1.1 * ( a + b + c );
float r1, r2;
float unit = length(ctr) / 2.0;
r1 = distance( t1, ctr )/unit;
r2 = r1 *( r1*( r1 * (a*r1 + b) + c) + d );
float sc = step( 0.0 , r1) * ( r1/(r2 + .000001)) + (1.0 - step( 0.0 , r1));
t2 = ctr + ( t1 - ctr) * sc;
gl_FragColor = texture2D(inputImage, (t2) / u_resolution.xy);
if ((t2.x < 0.0)
||(t2.y < 0.0)
||(t2.x > u_resolution.x)
||(t2.y > u_resolution.y))
{
gl_FragColor = vec4(0.0);
}
}