@@ -39,11 +39,14 @@ import Layout from "../../layouts/Layout.astro";
3939
4040 #define STRENGTH .75
4141
42- vec3 sepia(vec3 color) {
43- const vec3 sepiaColor = vec3(1.2, 1.0, 0.7);
44- float grayScale = dot(color, vec3(0.299, 0.587, 0.114));
45- return grayScale * sepiaColor;
46- }
42+ // sepia filter from the CSS specification : https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
43+ vec3 sepia(vec3 c){
44+ return c * mat3(
45+ 0.393, 0.769, 0.189,
46+ 0.349, 0.686, 0.168,
47+ 0.272, 0.534, 0.131
48+ );
49+ }
4750
4851 void main() {
4952 vec3 color = texture(uTexture, vUv).rgb;
@@ -56,27 +59,27 @@ import Layout from "../../layouts/Layout.astro";
5659 const { onAfterRender } = useWebGLCanvas({
5760 canvas: "#glCanvas",
5861 fragment: /* glsl */ `
59- in vec2 vUv;
60- uniform sampler2D uTexture;
61- uniform vec2 uResolution;
62- out vec4 fragColor;
63-
64- void main() {
65- vec2 textureResolution = vec2(textureSize(uTexture, 0));
66- float canvasRatio = uResolution.x / uResolution.y;
67- float textureRatio = textureResolution.x / textureResolution.y;
68-
69- vec2 uv = vUv - 0.5;
70- uv.x *= canvasRatio / textureRatio;
71- uv += 0.5;
72-
73- vec3 color = texture(uTexture, uv).rgb;
74- color *= step(0., uv.x) * (1. - step(1., uv.x));
75- color *= step(0., uv.y) * (1. - step(1., uv.y));
76-
77- fragColor = vec4(color, 1.);
78- }
79- `,
62+ in vec2 vUv;
63+ uniform sampler2D uTexture;
64+ uniform vec2 uResolution;
65+ out vec4 fragColor;
66+
67+ void main() {
68+ vec2 textureResolution = vec2(textureSize(uTexture, 0));
69+ float canvasRatio = uResolution.x / uResolution.y;
70+ float textureRatio = textureResolution.x / textureResolution.y;
71+
72+ vec2 uv = vUv - 0.5;
73+ uv.x *= canvasRatio / textureRatio;
74+ uv += 0.5;
75+
76+ vec3 color = texture(uTexture, uv).rgb;
77+ color *= step(0., uv.x) * (1. - step(1., uv.x));
78+ color *= step(0., uv.y) * (1. - step(1., uv.y));
79+
80+ fragColor = vec4(color, 1.);
81+ }
82+ `,
8083 uniforms: {
8184 uTexture: loadTexture("/images/lion.jpg"),
8285 },
0 commit comments