@@ -144,19 +144,34 @@ void main()
144144#endif
145145
146146#if defined(r_dithering)
147- const float bayer[ 16 ] = {
148- 0 .0f, 8 .0f, 2 .0f, 10 .0f,
149- 12 .0f, 4 .0f, 14 .0f, 6 .0f,
150- 3 .0f, 11 .0f, 1 .0f, 9 .0f,
151- 15 .0f, 7 .0f, 13 .0f, 5 .0f
152- };
153-
154- float dither = bayer[
155- int ( mod ( gl_FragCoord .x, 4.0 ) ) +
156- int ( mod ( gl_FragCoord .y, 4.0 ) ) * 4
157- ] / 16.0 ;
158-
159- color.rgb += vec3 ( ( dither - 0.50 ) / 255.0 );
147+ {
148+ vec3 dithered = color.rgb;
149+
150+ const float bayer[ 16 ] = {
151+ 0 .0f, 8 .0f, 2 .0f, 10 .0f,
152+ 12 .0f, 4 .0f, 14 .0f, 6 .0f,
153+ 3 .0f, 11 .0f, 1 .0f, 9 .0f,
154+ 15 .0f, 7 .0f, 13 .0f, 5 .0f
155+ };
156+
157+ float dither = bayer[
158+ int ( mod ( gl_FragCoord .x, 4.0 ) ) +
159+ int ( mod ( gl_FragCoord .y, 4.0 ) ) * 4
160+ ] / 16.0 ;
161+
162+ dithered += vec3 ( ( dither - 0.50 ) / 255.0 );
163+
164+ float threshold = 0 .0004f;
165+
166+ if ( ( color.r + color.g + color.b ) < ( 3 * threshold ) )
167+ {
168+ color.rgb = dithered;
169+
170+ #if defined(r_showDithering)
171+ color.r = 1 .0f;
172+ #endif
173+ }
174+ }
160175#endif
161176
162177 color.rgb = clamp ( color.rgb, vec3 ( 0 .0f ), vec3 ( 1 .0f ) );
0 commit comments