DotScreenShader.js 1.2 KB

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