DotScreenShader.js 1.2 KB

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