DotScreenShader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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: `varying vec2 vUv;
  26. void main() {
  27. vUv = uv;
  28. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  29. }`,
  30. fragmentShader: `uniform vec2 center;
  31. uniform float angle;
  32. uniform float scale;
  33. uniform vec2 tSize;
  34. uniform sampler2D tDiffuse;
  35. varying vec2 vUv;
  36. float pattern() {
  37. float s = sin( angle ), c = cos( angle );
  38. vec2 tex = vUv * tSize - center;
  39. vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * scale;
  40. return ( sin( point.x ) * sin( point.y ) ) * 4.0;
  41. }
  42. void main() {
  43. vec4 color = texture2D( tDiffuse, vUv );
  44. float average = ( color.r + color.g + color.b ) / 3.0;
  45. gl_FragColor = vec4( vec3( average * 10.0 - 5.0 + pattern() ), color.a );
  46. }`
  47. };
  48. THREE.DotScreenShader = DotScreenShader;
  49. } )();