BleachBypassShader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. name: 'BleachBypassShader',
  8. uniforms: {
  9. 'tDiffuse': { value: null },
  10. 'opacity': { value: 1.0 }
  11. },
  12. vertexShader: /* glsl */`
  13. varying vec2 vUv;
  14. void main() {
  15. vUv = uv;
  16. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  17. }`,
  18. fragmentShader: /* glsl */`
  19. uniform float opacity;
  20. uniform sampler2D tDiffuse;
  21. varying vec2 vUv;
  22. void main() {
  23. vec4 base = texture2D( tDiffuse, vUv );
  24. vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 );
  25. float lum = dot( lumCoeff, base.rgb );
  26. vec3 blend = vec3( lum );
  27. float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) );
  28. vec3 result1 = 2.0 * base.rgb * blend;
  29. vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb );
  30. vec3 newColor = mix( result1, result2, L );
  31. float A2 = opacity * base.a;
  32. vec3 mixRGB = A2 * newColor.rgb;
  33. mixRGB += ( ( 1.0 - A2 ) * base.rgb );
  34. gl_FragColor = vec4( mixRGB, base.a );
  35. }`
  36. };
  37. export { BleachBypassShader };