PixelShader.js 658 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Pixelation shader
  3. */
  4. const PixelShader = {
  5. uniforms: {
  6. 'tDiffuse': { value: null },
  7. 'resolution': { value: null },
  8. 'pixelSize': { value: 1 },
  9. },
  10. vertexShader: /* glsl */`
  11. varying highp vec2 vUv;
  12. void main() {
  13. vUv = uv;
  14. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  15. }`,
  16. fragmentShader: /* glsl */`
  17. uniform sampler2D tDiffuse;
  18. uniform float pixelSize;
  19. uniform vec2 resolution;
  20. varying highp vec2 vUv;
  21. void main(){
  22. vec2 dxy = pixelSize / resolution;
  23. vec2 coord = dxy * floor( vUv / dxy );
  24. gl_FragColor = texture2D(tDiffuse, coord);
  25. }`
  26. };
  27. export { PixelShader };