RGBShiftShader.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. console.warn( "THREE.RGBShiftShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. /**
  3. * RGB Shift Shader
  4. * Shifts red and blue channels from center in opposite directions
  5. * Ported from http://kriss.cx/tom/2009/05/rgb-shift/
  6. * by Tom Butterworth / http://kriss.cx/tom/
  7. *
  8. * amount: shift distance (1 is width of input)
  9. * angle: shift angle in radians
  10. */
  11. THREE.RGBShiftShader = {
  12. uniforms: {
  13. "tDiffuse": { value: null },
  14. "amount": { value: 0.005 },
  15. "angle": { value: 0.0 }
  16. },
  17. vertexShader: [
  18. "varying vec2 vUv;",
  19. "void main() {",
  20. " vUv = uv;",
  21. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  22. "}"
  23. ].join( "\n" ),
  24. fragmentShader: [
  25. "uniform sampler2D tDiffuse;",
  26. "uniform float amount;",
  27. "uniform float angle;",
  28. "varying vec2 vUv;",
  29. "void main() {",
  30. " vec2 offset = amount * vec2( cos(angle), sin(angle));",
  31. " vec4 cr = texture2D(tDiffuse, vUv + offset);",
  32. " vec4 cga = texture2D(tDiffuse, vUv);",
  33. " vec4 cb = texture2D(tDiffuse, vUv - offset);",
  34. " gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
  35. "}"
  36. ].join( "\n" )
  37. };