PixelShader.js 726 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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:
  18. /* glsl */
  19. `
  20. varying highp vec2 vUv;
  21. void main() {
  22. vUv = uv;
  23. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  24. }`,
  25. fragmentShader:
  26. /* glsl */
  27. `
  28. uniform sampler2D tDiffuse;
  29. uniform float pixelSize;
  30. uniform vec2 resolution;
  31. varying highp vec2 vUv;
  32. void main(){
  33. vec2 dxy = pixelSize / resolution;
  34. vec2 coord = dxy * floor( vUv / dxy );
  35. gl_FragColor = texture2D(tDiffuse, coord);
  36. }`
  37. };
  38. THREE.PixelShader = PixelShader;
  39. } )();