dithering_pars_fragment.glsl.js 608 B

1234567891011121314151617181920
  1. export default /* glsl */`
  2. #ifdef DITHERING
  3. // based on https://www.shadertoy.com/view/MslGR8
  4. vec3 dithering( vec3 color ) {
  5. //Calculate grid position
  6. float grid_position = rand( gl_FragCoord.xy );
  7. //Shift the individual colors differently, thus making it even harder to see the dithering pattern
  8. vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
  9. //modify shift according to grid position.
  10. dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
  11. //shift the color by dither_shift
  12. return color + dither_shift_RGB;
  13. }
  14. #endif
  15. `;