PixelShader.js 730 B

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