BleachBypassShader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /** @module BleachBypassShader */
  2. /**
  3. * Bleach bypass shader [http://en.wikipedia.org/wiki/Bleach_bypass] based on
  4. * [Nvidia Shader library]{@link http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html#post_bleach_bypass}.
  5. *
  6. * @constant
  7. * @type {Object}
  8. */
  9. const BleachBypassShader = {
  10. name: 'BleachBypassShader',
  11. uniforms: {
  12. 'tDiffuse': { value: null },
  13. 'opacity': { value: 1.0 }
  14. },
  15. vertexShader: /* glsl */`
  16. varying vec2 vUv;
  17. void main() {
  18. vUv = uv;
  19. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  20. }`,
  21. fragmentShader: /* glsl */`
  22. uniform float opacity;
  23. uniform sampler2D tDiffuse;
  24. varying vec2 vUv;
  25. void main() {
  26. vec4 base = texture2D( tDiffuse, vUv );
  27. float lum = luminance( 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. };
  39. export { BleachBypassShader };
粤ICP备19079148号