PixelShader.js 717 B

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