DotScreenShader.js 1.5 KB

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