PixelShader.js 688 B

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