Skip to content

Instantly share code, notes, and snippets.

@Elv13
Created November 9, 2021 01:15
Show Gist options
  • Save Elv13/a26fad4374487960dafbe47785adcd3f to your computer and use it in GitHub Desktop.
Save Elv13/a26fad4374487960dafbe47785adcd3f to your computer and use it in GitHub Desktop.
#define PI 3.14159
#define colorRange 24.0
uniform vec2 resolution;
uniform sampler2D tex;
uniform float opacity;
uniform float time;
uniform bool invert_color;
// https://www.shadertoy.com/view/lsBfRc
vec3 makeBloom(float lod, vec2 offset, vec2 bCoord){
vec2 pixelSize = 1.0 / vec2(resolution.x, resolution.y);
offset += pixelSize;
float lodFactor = exp2(lod);
vec3 bloom = vec3(0.0);
vec2 scale = lodFactor * pixelSize;
vec2 coord = (bCoord.xy-offset)*lodFactor;
float totalWeight = 0.0;
if (any(greaterThanEqual(abs(coord - 0.5), scale + 0.5)))
return vec3(0.0);
for (int i = -5; i < 5; i++) {
for (int j = -5; j < 5; j++) {
float wg = pow(1.0-length(vec2(i, j)) * 0.125,6.0);
bloom = pow(texture2D(tex, vec2(i, j) * scale + lodFactor * pixelSize + coord, lod).rgb, vec3(2.2))*wg + bloom;
totalWeight += wg;
}
}
bloom /= totalWeight;
return bloom;
}
vec2 deformUv(vec2 uv) {
float yMul = 0.92 - 0.08 * sin(uv.x * PI);
if(uv.y >= 0.5) {
return vec2(uv.x, yMul*(uv.y-0.5)+0.5 );
}
else {
return vec2(uv.x, 0.5+yMul*(uv.y-0.5));
}
}
vec4 scanLine( in vec4 c, in float y )
{
float scanLines = 280.0;
float intensity = 1.0 + 0.2 * sin(y * scanLines * 2.0*PI);
vec4 result = vec4(intensity * c.rgb, 1.0);
return result;
}
// Intensity of the image is faded around the edges
float edgeIntensity(vec2 uv) {
float edgeIntensityX = 1.0;
if( uv.x < 0.1) {
edgeIntensityX = 0.7 + 0.3*(uv.x/0.1);
}
else if( uv.x > 0.90) {
edgeIntensityX = 0.7 + 0.3*((1.0-uv.x)/0.1);
}
float edgeIntensityY = 1.0;
if( uv.y < 0.15) {
edgeIntensityY = 0.6 + 0.4*(uv.y/0.15);
}
else if( uv.y > 0.85) {
edgeIntensityY = 0.6 + 0.4*((1.0-uv.y)/0.15);
}
return edgeIntensityX*edgeIntensityY;
}
// Make bright colors split their red and blue channels.
vec4 color_separation(sampler2D image, vec2 uv) {
vec4 left = texture2D(image, uv);
vec4 right = texture2D(image, uv + vec2(0.0025, 0.0));
vec3 color = vec3(left.r, right.gb);
color = clamp(color, 0.0, 1.0);
return vec4(color, 1.0);
}
vec4 applyBloon(vec2 uv) {
vec3 blur = makeBloom(0.0, vec2(1.0/resolution.x,1.0/resolution.y), uv);
/*blur += makeBloom(0.0, vec2(0.3/resolution.x,0.0), uv);
blur += makeBloom(0.0, vec2(0.0,0.3/resolution.y), uv);
blur += makeBloom(0.0, vec2(0.1/resolution.x,0.3/resolution.y), uv);
blur += makeBloom(6.0, vec2(0.2,0.3), uv);*/
return vec4(pow(blur, vec3(1.0 / 2.2)), 1.0);
}
void main() {
vec2 uv = vec2(gl_TexCoord[0].xy);
//vec2 uv = deformUv(gl_TexCoord[0].xy);
vec4 color = color_separation(tex, uv);
//vec4 color = texture2D(tex, uv);
color = scanLine(color, uv.y*2.0f);
//color += applyBloon(uv);
color.rgb *= edgeIntensity(uv);
gl_FragColor = color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment