File tree 4 files changed +32
-16
lines changed
content/Backgrounds/Dither
tailwind/Backgrounds/Dither
ts-default/Backgrounds/Dither
ts-tailwind/Backgrounds/Dither
4 files changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -114,18 +114,22 @@ const float bayerMatrix8x8[64] = float[64](
114
114
);
115
115
116
116
vec3 dither(vec2 uv, vec3 color) {
117
- int x = int(uv.x * resolution.x) % 8;
118
- int y = int(uv.y * resolution.y) % 8;
117
+ vec2 scaledCoord = floor(uv * resolution / pixelSize);
118
+ int x = int(mod(scaledCoord.x, 8.0));
119
+ int y = int(mod(scaledCoord.y, 8.0));
119
120
float threshold = bayerMatrix8x8[y * 8 + x] - 0.25;
120
- color += threshold;
121
+ float step = 1.0 / (colorNum - 1.0);
122
+ color += threshold * step;
123
+ float bias = 0.2;
124
+ color = clamp(color - bias, 0.0, 1.0);
121
125
return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0);
122
126
}
123
127
124
128
void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) {
125
129
vec2 normalizedPixelSize = pixelSize / resolution;
126
130
vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize);
127
131
vec4 color = texture2D(inputBuffer, uvPixel);
128
- color.rgb = dither(uvPixel , color.rgb);
132
+ color.rgb = dither(uv , color.rgb);
129
133
outputColor = color;
130
134
}
131
135
` ;
Original file line number Diff line number Diff line change @@ -112,18 +112,22 @@ const float bayerMatrix8x8[64] = float[64](
112
112
);
113
113
114
114
vec3 dither(vec2 uv, vec3 color) {
115
- int x = int(uv.x * resolution.x) % 8;
116
- int y = int(uv.y * resolution.y) % 8;
115
+ vec2 scaledCoord = floor(uv * resolution / pixelSize);
116
+ int x = int(mod(scaledCoord.x, 8.0));
117
+ int y = int(mod(scaledCoord.y, 8.0));
117
118
float threshold = bayerMatrix8x8[y * 8 + x] - 0.25;
118
- color += threshold;
119
+ float step = 1.0 / (colorNum - 1.0);
120
+ color += threshold * step;
121
+ float bias = 0.2;
122
+ color = clamp(color - bias, 0.0, 1.0);
119
123
return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0);
120
124
}
121
125
122
126
void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) {
123
127
vec2 normalizedPixelSize = pixelSize / resolution;
124
128
vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize);
125
129
vec4 color = texture2D(inputBuffer, uvPixel);
126
- color.rgb = dither(uvPixel , color.rgb);
130
+ color.rgb = dither(uv , color.rgb);
127
131
outputColor = color;
128
132
}
129
133
` ;
Original file line number Diff line number Diff line change @@ -114,18 +114,22 @@ const float bayerMatrix8x8[64] = float[64](
114
114
);
115
115
116
116
vec3 dither(vec2 uv, vec3 color) {
117
- int x = int(uv.x * resolution.x) % 8;
118
- int y = int(uv.y * resolution.y) % 8;
117
+ vec2 scaledCoord = floor(uv * resolution / pixelSize);
118
+ int x = int(mod(scaledCoord.x, 8.0));
119
+ int y = int(mod(scaledCoord.y, 8.0));
119
120
float threshold = bayerMatrix8x8[y * 8 + x] - 0.25;
120
- color += threshold;
121
+ float step = 1.0 / (colorNum - 1.0);
122
+ color += threshold * step;
123
+ float bias = 0.2;
124
+ color = clamp(color - bias, 0.0, 1.0);
121
125
return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0);
122
126
}
123
127
124
128
void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) {
125
129
vec2 normalizedPixelSize = pixelSize / resolution;
126
130
vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize);
127
131
vec4 color = texture2D(inputBuffer, uvPixel);
128
- color.rgb = dither(uvPixel , color.rgb);
132
+ color.rgb = dither(uv , color.rgb);
129
133
outputColor = color;
130
134
}
131
135
` ;
Original file line number Diff line number Diff line change @@ -112,18 +112,22 @@ const float bayerMatrix8x8[64] = float[64](
112
112
);
113
113
114
114
vec3 dither(vec2 uv, vec3 color) {
115
- int x = int(uv.x * resolution.x) % 8;
116
- int y = int(uv.y * resolution.y) % 8;
115
+ vec2 scaledCoord = floor(uv * resolution / pixelSize);
116
+ int x = int(mod(scaledCoord.x, 8.0));
117
+ int y = int(mod(scaledCoord.y, 8.0));
117
118
float threshold = bayerMatrix8x8[y * 8 + x] - 0.25;
118
- color += threshold;
119
+ float step = 1.0 / (colorNum - 1.0);
120
+ color += threshold * step;
121
+ float bias = 0.2;
122
+ color = clamp(color - bias, 0.0, 1.0);
119
123
return floor(color * (colorNum - 1.0) + 0.5) / (colorNum - 1.0);
120
124
}
121
125
122
126
void mainImage(in vec4 inputColor, in vec2 uv, out vec4 outputColor) {
123
127
vec2 normalizedPixelSize = pixelSize / resolution;
124
128
vec2 uvPixel = normalizedPixelSize * floor(uv / normalizedPixelSize);
125
129
vec4 color = texture2D(inputBuffer, uvPixel);
126
- color.rgb = dither(uvPixel , color.rgb);
130
+ color.rgb = dither(uv , color.rgb);
127
131
outputColor = color;
128
132
}
129
133
` ;
You can’t perform that action at this time.
0 commit comments