DotScreenShader.js 1.2 KB

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