BleachBypassShader.js 1.2 KB

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