RGBShiftShader.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @module RGBShiftShader
  3. * @three_import import { RGBShiftShader } from 'three/addons/shaders/RGBShiftShader.js';
  4. */
  5. /**
  6. * RGB Shift Shader
  7. * Shifts red and blue channels from center in opposite directions
  8. * Ported from https://web.archive.org/web/20090820185047/http://kriss.cx/tom/2009/05/rgb-shift/
  9. * by Tom Butterworth / https://web.archive.org/web/20090810054752/http://kriss.cx/tom/
  10. *
  11. * amount: shift distance (1 is width of input)
  12. * angle: shift angle in radians
  13. *
  14. * @constant
  15. * @type {ShaderMaterial~Shader}
  16. */
  17. const RGBShiftShader = {
  18. name: 'RGBShiftShader',
  19. uniforms: {
  20. 'tDiffuse': { value: null },
  21. 'amount': { value: 0.005 },
  22. 'angle': { value: 0.0 }
  23. },
  24. vertexShader: /* glsl */`
  25. varying vec2 vUv;
  26. void main() {
  27. vUv = uv;
  28. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  29. }`,
  30. fragmentShader: /* glsl */`
  31. uniform sampler2D tDiffuse;
  32. uniform float amount;
  33. uniform float angle;
  34. varying vec2 vUv;
  35. void main() {
  36. vec2 offset = amount * vec2( cos(angle), sin(angle));
  37. vec4 cr = texture2D(tDiffuse, vUv + offset);
  38. vec4 cga = texture2D(tDiffuse, vUv);
  39. vec4 cb = texture2D(tDiffuse, vUv - offset);
  40. gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);
  41. }`
  42. };
  43. export { RGBShiftShader };