shaders/phosphor-basic.frag
author František Kučera <franta-hg@frantovo.cz>
Sat, 06 Jan 2024 01:04:15 +0100
branchv_0
changeset 33 3aae6275b683
parent 28 4cbd9c0beb4c
permissions -rw-r--r--
xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#version 330 core
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
2
3faef2f5128e better GLSL variable names
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     3
uniform  sampler2D  uTexture;
28
4cbd9c0beb4c pass texture xattr 'shader-shark.texture.scale' to the shaders as 'uTextureScale' + update variable locations on each shader reload
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
     4
uniform  float      uTextureScale;
2
3faef2f5128e better GLSL variable names
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     5
in       vec2       vTextureXY;
14
ceeb36fad818 transparency/alpha: simple binary transparent/opaque, no blending, just discard some fragments
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
     6
out      vec4       fColor;
0
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
14
ceeb36fad818 transparency/alpha: simple binary transparent/opaque, no blending, just discard some fragments
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
     8
vec4 grayscale(vec4 original) {
4
9aba96f0b001 fragment shader: add grayscale() function
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     9
	const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
14
ceeb36fad818 transparency/alpha: simple binary transparent/opaque, no blending, just discard some fragments
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    10
	float luminance = dot(original.rgb, luminanceWeighting);
ceeb36fad818 transparency/alpha: simple binary transparent/opaque, no blending, just discard some fragments
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    11
	return vec4(vec3(luminance), original.a);
4
9aba96f0b001 fragment shader: add grayscale() function
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    12
}
9aba96f0b001 fragment shader: add grayscale() function
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    13
18
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    14
vec4 invert(vec4 original) {
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    15
	original = clamp(original, 0.0, 1.0);
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    16
	return vec4(vec3(1.) - original.rgb, original.a);
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    17
}
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    18
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    19
float rand(vec2 co) {
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    20
    return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    21
}
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    22
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    23
void main() {
14
ceeb36fad818 transparency/alpha: simple binary transparent/opaque, no blending, just discard some fragments
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    24
	fColor = texture(uTexture, vTextureXY).rgba;
18
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    25
4
9aba96f0b001 fragment shader: add grayscale() function
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    26
	// fColor = grayscale(fColor);
18
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    27
	// fColor = invert(fColor);
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    28
	fColor = (fColor-rand(vTextureXY)*0.3) * 1.6;
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    29
28
4cbd9c0beb4c pass texture xattr 'shader-shark.texture.scale' to the shaders as 'uTextureScale' + update variable locations on each shader reload
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
    30
	float lineCount = textureSize(uTexture, 0).y / uTextureScale;
18
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    31
	fColor.xyz *= abs(sin(radians(vTextureXY.y * 180. * lineCount)));
14
ceeb36fad818 transparency/alpha: simple binary transparent/opaque, no blending, just discard some fragments
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    32
28
4cbd9c0beb4c pass texture xattr 'shader-shark.texture.scale' to the shaders as 'uTextureScale' + update variable locations on each shader reload
František Kučera <franta-hg@frantovo.cz>
parents: 21
diff changeset
    33
	// float columnCount = textureSize(uTexture, 0).x / uTextureScale;
18
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    34
	// fColor.xyz *=
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    35
	//  clamp(abs(sin(radians(vTextureXY.x * 180. * columnCount)))+0.6, 0., 1.);
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    36
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    37
	// fColor = grayscale(fColor) * vec4(1.00, 0.80, 0.10, 1.00); // amber
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    38
	fColor = grayscale(fColor) * vec4(0.30, 0.80, 0.20, 1.00); // green
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    39
c4384f43c739 new shader: phosphor-basic.frag
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    40
	// let us move decades ago, when screens were greener and future brighter
0
bb715a82a8f1 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
}