diff --git a/src/content/Backgrounds/Dither/Dither.jsx b/src/content/Backgrounds/Dither/Dither.jsx index 74a51a41..e8e1d868 100644 --- a/src/content/Backgrounds/Dither/Dither.jsx +++ b/src/content/Backgrounds/Dither/Dither.jsx @@ -114,10 +114,14 @@ const float bayerMatrix8x8[64] = float[64]( ); vec3 dither(vec2 uv, vec3 color) { - int x = int(uv.x * resolution.x) % 8; - int y = int(uv.y * resolution.y) % 8; + vec2 scaledCoord = floor(uv * resolution / pixelSize); + int x = int(mod(scaledCoord.x, 8.0)); + int y = int(mod(scaledCoord.y, 8.0)); float threshold = bayerMatrix8x8[y * 8 + x] - 0.25; - color += threshold; + float step = 1.0 / (colorNum - 1.0); + color += threshold * step; + float bias = 0.2; + color = clamp(color - bias, 0.0, 1.0); return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0); } @@ -125,7 +129,7 @@ void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) { vec2 normalizedPixelSize = pixelSize / resolution; vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize); vec4 color = texture2D(inputBuffer, uvPixel); - color.rgb = dither(uvPixel, color.rgb); + color.rgb = dither(uv, color.rgb); outputColor = color; } `; diff --git a/src/tailwind/Backgrounds/Dither/Dither.jsx b/src/tailwind/Backgrounds/Dither/Dither.jsx index 215aa5d3..e25f7084 100644 --- a/src/tailwind/Backgrounds/Dither/Dither.jsx +++ b/src/tailwind/Backgrounds/Dither/Dither.jsx @@ -112,10 +112,14 @@ const float bayerMatrix8x8[64] = float[64]( ); vec3 dither(vec2 uv, vec3 color) { - int x = int(uv.x * resolution.x) % 8; - int y = int(uv.y * resolution.y) % 8; + vec2 scaledCoord = floor(uv * resolution / pixelSize); + int x = int(mod(scaledCoord.x, 8.0)); + int y = int(mod(scaledCoord.y, 8.0)); float threshold = bayerMatrix8x8[y * 8 + x] - 0.25; - color += threshold; + float step = 1.0 / (colorNum - 1.0); + color += threshold * step; + float bias = 0.2; + color = clamp(color - bias, 0.0, 1.0); return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0); } @@ -123,7 +127,7 @@ void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) { vec2 normalizedPixelSize = pixelSize / resolution; vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize); vec4 color = texture2D(inputBuffer, uvPixel); - color.rgb = dither(uvPixel, color.rgb); + color.rgb = dither(uv, color.rgb); outputColor = color; } `; diff --git a/src/ts-default/Backgrounds/Dither/Dither.tsx b/src/ts-default/Backgrounds/Dither/Dither.tsx index ca7390ea..b53c2c2d 100644 --- a/src/ts-default/Backgrounds/Dither/Dither.tsx +++ b/src/ts-default/Backgrounds/Dither/Dither.tsx @@ -114,10 +114,14 @@ const float bayerMatrix8x8[64] = float[64]( ); vec3 dither(vec2 uv, vec3 color) { - int x = int(uv.x * resolution.x) % 8; - int y = int(uv.y * resolution.y) % 8; + vec2 scaledCoord = floor(uv * resolution / pixelSize); + int x = int(mod(scaledCoord.x, 8.0)); + int y = int(mod(scaledCoord.y, 8.0)); float threshold = bayerMatrix8x8[y * 8 + x] - 0.25; - color += threshold; + float step = 1.0 / (colorNum - 1.0); + color += threshold * step; + float bias = 0.2; + color = clamp(color - bias, 0.0, 1.0); return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0); } @@ -125,7 +129,7 @@ void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) { vec2 normalizedPixelSize = pixelSize / resolution; vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize); vec4 color = texture2D(inputBuffer, uvPixel); - color.rgb = dither(uvPixel, color.rgb); + color.rgb = dither(uv, color.rgb); outputColor = color; } `; diff --git a/src/ts-tailwind/Backgrounds/Dither/Dither.tsx b/src/ts-tailwind/Backgrounds/Dither/Dither.tsx index 36ef9fc1..9e795c2c 100644 --- a/src/ts-tailwind/Backgrounds/Dither/Dither.tsx +++ b/src/ts-tailwind/Backgrounds/Dither/Dither.tsx @@ -112,10 +112,14 @@ const float bayerMatrix8x8[64] = float[64]( ); vec3 dither(vec2 uv, vec3 color) { - int x = int(uv.x * resolution.x) % 8; - int y = int(uv.y * resolution.y) % 8; + vec2 scaledCoord = floor(uv * resolution / pixelSize); + int x = int(mod(scaledCoord.x, 8.0)); + int y = int(mod(scaledCoord.y, 8.0)); float threshold = bayerMatrix8x8[y * 8 + x] - 0.25; - color += threshold; + float step = 1.0 / (colorNum - 1.0); + color += threshold * step; + float bias = 0.2; + color = clamp(color - bias, 0.0, 1.0); return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0); } @@ -123,7 +127,7 @@ void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) { vec2 normalizedPixelSize = pixelSize / resolution; vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize); vec4 color = texture2D(inputBuffer, uvPixel); - color.rgb = dither(uvPixel, color.rgb); + color.rgb = dither(uv, color.rgb); outputColor = color; } `;