DotScreenShader.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {
  2. Vector2
  3. } from '../../../build/three.module.js';
  4. /**
  5. * Dot screen shader
  6. * based on glfx.js sepia shader
  7. * https://github.com/evanw/glfx.js
  8. */
  9. var DotScreenShader = {
  10. uniforms: {
  11. 'tDiffuse': { value: null },
  12. 'tSize': { value: new Vector2( 256, 256 ) },
  13. 'center': { value: new Vector2( 0.5, 0.5 ) },
  14. 'angle': { value: 1.57 },
  15. 'scale': { value: 1.0 }
  16. },
  17. vertexShader: [
  18. 'varying vec2 vUv;',
  19. 'void main() {',
  20. ' vUv = uv;',
  21. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  22. '}'
  23. ].join( '\n' ),
  24. fragmentShader: [
  25. 'uniform vec2 center;',
  26. 'uniform float angle;',
  27. 'uniform float scale;',
  28. 'uniform vec2 tSize;',
  29. 'uniform sampler2D tDiffuse;',
  30. 'varying vec2 vUv;',
  31. 'float pattern() {',
  32. ' float s = sin( angle ), c = cos( angle );',
  33. ' vec2 tex = vUv * tSize - center;',
  34. ' vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * scale;',
  35. ' return ( sin( point.x ) * sin( point.y ) ) * 4.0;',
  36. '}',
  37. 'void main() {',
  38. ' vec4 color = texture2D( tDiffuse, vUv );',
  39. ' float average = ( color.r + color.g + color.b ) / 3.0;',
  40. ' gl_FragColor = vec4( vec3( average * 10.0 - 5.0 + pattern() ), color.a );',
  41. '}'
  42. ].join( '\n' )
  43. };
  44. export { DotScreenShader };