RGBShiftShader.js 1.1 KB

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