DotScreenShader.js 1.2 KB

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