BleachBypassShader.js 1.2 KB

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