PixelShader.js 700 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Pixelation shader
  3. */
  4. var 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. };
  29. export { PixelShader };