Skip to content

Commit cb519a2

Browse files
committed
Color banding dithering
1 parent 4b1e263 commit cb519a2

File tree

1 file changed

+9
-1
lines changed
  • common/src/main/resources/assets/lambda/shaders/fragment/renderer

1 file changed

+9
-1
lines changed

common/src/main/resources/assets/lambda/shaders/fragment/renderer/rect_filled.frag

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ in float v_Shade;
1515
out vec4 color;
1616

1717
#define SMOOTHING 0.25
18+
#define NOISE_GRANULARITY 0.005
19+
20+
vec4 noise() {
21+
// https://shader-tutorial.dev/advanced/color-banding-dithering/
22+
float random = fract(sin(dot(v_TexCoord, vec2(12.9898, 78.233))) * 43758.5453);
23+
float ofs = mix(-NOISE_GRANULARITY, NOISE_GRANULARITY, random);
24+
return vec4(ofs, ofs, ofs, 0.0);
25+
}
1826

1927
vec4 shade() {
2028
if (v_Shade != 1.0) return v_Color;
@@ -41,5 +49,5 @@ vec4 round() {
4149
}
4250

4351
void main() {
44-
color = shade() * round();
52+
color = shade() * round() + noise();
4553
}

0 commit comments

Comments
 (0)