RGBShiftShader.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. var RGBShiftShader = {
  11. uniforms: {
  12. 'tDiffuse': { value: null },
  13. 'amount': { value: 0.005 },
  14. 'angle': { value: 0.0 }
  15. },
  16. vertexShader: [
  17. 'varying vec2 vUv;',
  18. 'void main() {',
  19. ' vUv = uv;',
  20. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  21. '}'
  22. ].join( '\n' ),
  23. fragmentShader: [
  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. ].join( '\n' )
  36. };
  37. export { RGBShiftShader };