xxxxxxxxxx
65
precision mediump float;
varying vec2 vTexCoord;
uniform sampler2D renderTex;
uniform vec2 curvature;
uniform vec2 resolution;
uniform vec2 scan_opacity;
uniform vec3 rgb_offset;
uniform float vignette_opacity;
uniform float brightness;
vec2 curveMap(vec2 uv) {
uv = uv * 2.0 - 1.0;
vec2 offset = abs(uv.yx) / curvature;
uv = uv + (uv * offset * offset);
uv = (uv * 0.5) + 0.5;
return uv;
}
vec4 vignette(vec2 uv, vec2 res, float o) {
float i = uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y);
return vec4(vec3(clamp(pow((res.x / 4.0) * i, o), 0.0, 1.0)), 1.0);
}
vec4 scanline(float u, float res, float o) {
float i = sin(u * res * PI * 2.0);
i = ((0.5 * i) + 0.5) * 0.9 + 0.1;
return vec4(vec3(pow(i, o)), 1.0);
}
void main() {
// Apply curvature distortion and sample
vec2 coord = curveMap(vTexCoord);
vec4 col = texture2D(renderTex, coord);
// Apply rgb channel offset
vec2 pix_size = vec2(1.0) / resolution;
vec4 r = texture2D(renderTex, coord + rgb_offset.r * pix_size);
vec4 g = texture2D(renderTex, coord + rgb_offset.g * pix_size);
vec4 b = texture2D(renderTex, coord + rgb_offset.b * pix_size);
col = vec4(r.r, g.g, b.b, col.a);
// Apply vignette intensity
col *= vignette(coord, resolution, vignette_opacity);
// Apply scanline intensity
col *= scanline(coord.x, resolution.y, scan_opacity.y);
col *= scanline(coord.y, resolution.x, scan_opacity.x);
// Increasing brightness to counteract scanline/vignette effect on intensity
col *= vec4(vec3(brightness), 1.0);
// Black out fragments outside the curvature
if (coord.x < 0.0 || coord.y < 0.0 || coord.x > 1.0 || coord.y > 1.0) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
} else {
gl_FragColor = col;
}
// Disable effects
//gl_FragColor = texture2D(renderTex, vTexCoord);
}