BleachBypassShader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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:
  17. /* glsl */
  18. `
  19. varying vec2 vUv;
  20. void main() {
  21. vUv = uv;
  22. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  23. }`,
  24. fragmentShader:
  25. /* glsl */
  26. `
  27. uniform float opacity;
  28. uniform sampler2D tDiffuse;
  29. varying vec2 vUv;
  30. void main() {
  31. vec4 base = texture2D( tDiffuse, vUv );
  32. vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 );
  33. float lum = dot( lumCoeff, base.rgb );
  34. vec3 blend = vec3( lum );
  35. float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) );
  36. vec3 result1 = 2.0 * base.rgb * blend;
  37. vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb );
  38. vec3 newColor = mix( result1, result2, L );
  39. float A2 = opacity * base.a;
  40. vec3 mixRGB = A2 * newColor.rgb;
  41. mixRGB += ( ( 1.0 - A2 ) * base.rgb );
  42. gl_FragColor = vec4( mixRGB, base.a );
  43. }`
  44. };
  45. THREE.BleachBypassShader = BleachBypassShader;
  46. } )();