DotScreenShader.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. console.warn( "THREE.DotScreenShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * Dot screen shader
  6. * based on glfx.js sepia shader
  7. * https://github.com/evanw/glfx.js
  8. */
  9. THREE.DotScreenShader = {
  10. uniforms: {
  11. "tDiffuse": { value: null },
  12. "tSize": { value: new THREE.Vector2( 256, 256 ) },
  13. "center": { value: new THREE.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. };