RGBShiftShader.js 1.1 KB

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