BleachBypassShader.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Bleach bypass shader [http://en.wikipedia.org/wiki/Bleach_bypass]
  5. * - based on Nvidia example
  6. * http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html#post_bleach_bypass
  7. */
  8. THREE.BleachBypassShader = {
  9. uniforms: {
  10. "tDiffuse": { value: null },
  11. "opacity": { value: 1.0 }
  12. },
  13. vertexShader: [
  14. "varying vec2 vUv;",
  15. "void main() {",
  16. "vUv = uv;",
  17. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  18. "}"
  19. ].join( "\n" ),
  20. fragmentShader: [
  21. "uniform float opacity;",
  22. "uniform sampler2D tDiffuse;",
  23. "varying vec2 vUv;",
  24. "void main() {",
  25. "vec4 base = texture2D( tDiffuse, vUv );",
  26. "vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 );",
  27. "float lum = dot( lumCoeff, base.rgb );",
  28. "vec3 blend = vec3( lum );",
  29. "float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) );",
  30. "vec3 result1 = 2.0 * base.rgb * blend;",
  31. "vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb );",
  32. "vec3 newColor = mix( result1, result2, L );",
  33. "float A2 = opacity * base.a;",
  34. "vec3 mixRGB = A2 * newColor.rgb;",
  35. "mixRGB += ( ( 1.0 - A2 ) * base.rgb );",
  36. "gl_FragColor = vec4( mixRGB, base.a );",
  37. "}"
  38. ].join( "\n" )
  39. };