BleachBypassShader.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. float lum = luminance( 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 };
粤ICP备19079148号