PixelShader.js 677 B

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