PixelShader.js 658 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 };