ColoredDotScreenShader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {
  2. Vector2
  3. } from 'three';
  4. /**
  5. * Dot screen shader
  6. * based on glfx.js sepia shader
  7. * https://github.com/evanw/glfx.js
  8. */
  9. const ColoredDotScreenShader = {
  10. name: 'ColoredDotScreenShader',
  11. uniforms: {
  12. 'tDiffuse': { value: null },
  13. 'tSize': { value: new Vector2( 256, 256 ) },
  14. 'center': { value: new Vector2( 0.5, 0.5 ) },
  15. 'angle': { value: 1.57 },
  16. 'scale': { value: 1.0 }
  17. },
  18. vertexShader: /* glsl */`
  19. varying vec2 vUv;
  20. void main() {
  21. vUv = uv;
  22. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  23. }`,
  24. fragmentShader: /* glsl */`
  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. gl_FragColor = vec4( vec3(color.r, color.g, color.b) * pattern(), color.a );
  40. }`
  41. };
  42. export { ColoredDotScreenShader };