shaders/phosphor-basic.frag
author František Kučera <franta-hg@frantovo.cz>
Tue, 26 Dec 2023 23:46:45 +0100
branchv_0
changeset 28 4cbd9c0beb4c
parent 21 bcc53967ab3c
permissions -rw-r--r--
pass texture xattr 'shader-shark.texture.scale' to the shaders as 'uTextureScale' + update variable locations on each shader reload

#version 330 core

uniform  sampler2D  uTexture;
uniform  float      uTextureScale;
in       vec2       vTextureXY;
out      vec4       fColor;

vec4 grayscale(vec4 original) {
	const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
	float luminance = dot(original.rgb, luminanceWeighting);
	return vec4(vec3(luminance), original.a);
}

vec4 invert(vec4 original) {
	original = clamp(original, 0.0, 1.0);
	return vec4(vec3(1.) - original.rgb, original.a);
}

float rand(vec2 co) {
    return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}

void main() {
	fColor = texture(uTexture, vTextureXY).rgba;

	// fColor = grayscale(fColor);
	// fColor = invert(fColor);
	fColor = (fColor-rand(vTextureXY)*0.3) * 1.6;

	float lineCount = textureSize(uTexture, 0).y / uTextureScale;
	fColor.xyz *= abs(sin(radians(vTextureXY.y * 180. * lineCount)));

	// float columnCount = textureSize(uTexture, 0).x / uTextureScale;
	// fColor.xyz *=
	//  clamp(abs(sin(radians(vTextureXY.x * 180. * columnCount)))+0.6, 0., 1.);

	// fColor = grayscale(fColor) * vec4(1.00, 0.80, 0.10, 1.00); // amber
	fColor = grayscale(fColor) * vec4(0.30, 0.80, 0.20, 1.00); // green

	// let us move decades ago, when screens were greener and future brighter
}