DotScreenShader.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. import {
  9. Vector2
  10. } from "../../../build/three.module.js";
  11. var DotScreenShader = {
  12. uniforms: {
  13. "tDiffuse": { value: null },
  14. "tSize": { value: new Vector2( 256, 256 ) },
  15. "center": { value: new Vector2( 0.5, 0.5 ) },
  16. "angle": { value: 1.57 },
  17. "scale": { value: 1.0 }
  18. },
  19. vertexShader: [
  20. "varying vec2 vUv;",
  21. "void main() {",
  22. "vUv = uv;",
  23. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  24. "}"
  25. ].join( "\n" ),
  26. fragmentShader: [
  27. "uniform vec2 center;",
  28. "uniform float angle;",
  29. "uniform float scale;",
  30. "uniform vec2 tSize;",
  31. "uniform sampler2D tDiffuse;",
  32. "varying vec2 vUv;",
  33. "float pattern() {",
  34. "float s = sin( angle ), c = cos( angle );",
  35. "vec2 tex = vUv * tSize - center;",
  36. "vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * scale;",
  37. "return ( sin( point.x ) * sin( point.y ) ) * 4.0;",
  38. "}",
  39. "void main() {",
  40. "vec4 color = texture2D( tDiffuse, vUv );",
  41. "float average = ( color.r + color.g + color.b ) / 3.0;",
  42. "gl_FragColor = vec4( vec3( average * 10.0 - 5.0 + pattern() ), color.a );",
  43. "}"
  44. ].join( "\n" )
  45. };
  46. export { DotScreenShader };