PixelShader.js 718 B

123456789101112131415161718192021222324
  1. ( function () {
  2. /**
  3. * Pixelation shader
  4. */
  5. var 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;', 'void main() {', 'vUv = uv;', 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}' ].join( '\n' ),
  18. fragmentShader: [ 'uniform sampler2D tDiffuse;', 'uniform float pixelSize;', 'uniform vec2 resolution;', 'varying highp vec2 vUv;', 'void main(){', 'vec2 dxy = pixelSize / resolution;', 'vec2 coord = dxy * floor( vUv / dxy );', 'gl_FragColor = texture2D(tDiffuse, coord);', '}' ].join( '\n' )
  19. };
  20. THREE.PixelShader = PixelShader;
  21. } )();