DotScreenShader.js 1.2 KB

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