RGBShiftShader.js 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * RGB Shift Shader
  3. * Shifts red and blue channels from center in opposite directions
  4. * Ported from http://kriss.cx/tom/2009/05/rgb-shift/
  5. * by Tom Butterworth / 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. uniforms: {
  12. 'tDiffuse': { value: null },
  13. 'amount': { value: 0.005 },
  14. 'angle': { value: 0.0 }
  15. },
  16. vertexShader: /* glsl */`
  17. varying vec2 vUv;
  18. void main() {
  19. vUv = uv;
  20. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  21. }`,
  22. fragmentShader: /* glsl */`
  23. uniform sampler2D tDiffuse;
  24. uniform float amount;
  25. uniform float angle;
  26. varying vec2 vUv;
  27. void main() {
  28. vec2 offset = amount * vec2( cos(angle), sin(angle));
  29. vec4 cr = texture2D(tDiffuse, vUv + offset);
  30. vec4 cga = texture2D(tDiffuse, vUv);
  31. vec4 cb = texture2D(tDiffuse, vUv - offset);
  32. gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);
  33. }`
  34. };
  35. export { RGBShiftShader };