PixelShader.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. console.warn( "THREE.PixelShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author wongbryan / http://wongbryan.github.io
  4. *
  5. * Pixelation shader
  6. */
  7. THREE.PixelShader = {
  8. uniforms: {
  9. "tDiffuse": { value: null },
  10. "resolution": { value: null },
  11. "pixelSize": { value: 1. },
  12. },
  13. vertexShader: [
  14. "varying highp vec2 vUv;",
  15. "void main() {",
  16. "vUv = uv;",
  17. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  18. "}"
  19. ].join( "\n" ),
  20. fragmentShader: [
  21. "uniform sampler2D tDiffuse;",
  22. "uniform float pixelSize;",
  23. "uniform vec2 resolution;",
  24. "varying highp vec2 vUv;",
  25. "void main(){",
  26. "vec2 dxy = pixelSize / resolution;",
  27. "vec2 coord = dxy * floor( vUv / dxy );",
  28. "gl_FragColor = texture2D(tDiffuse, coord);",
  29. "}"
  30. ].join( "\n" )
  31. };