BleachBypassShader.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. console.warn( "THREE.BleachBypassShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * Bleach bypass shader [http://en.wikipedia.org/wiki/Bleach_bypass]
  6. * - based on Nvidia example
  7. * http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html#post_bleach_bypass
  8. */
  9. THREE.BleachBypassShader = {
  10. uniforms: {
  11. "tDiffuse": { value: null },
  12. "opacity": { value: 1.0 }
  13. },
  14. vertexShader: [
  15. "varying vec2 vUv;",
  16. "void main() {",
  17. " vUv = uv;",
  18. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  19. "}"
  20. ].join( "\n" ),
  21. fragmentShader: [
  22. "uniform float opacity;",
  23. "uniform sampler2D tDiffuse;",
  24. "varying vec2 vUv;",
  25. "void main() {",
  26. " vec4 base = texture2D( tDiffuse, vUv );",
  27. " vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 );",
  28. " float lum = dot( lumCoeff, base.rgb );",
  29. " vec3 blend = vec3( lum );",
  30. " float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) );",
  31. " vec3 result1 = 2.0 * base.rgb * blend;",
  32. " vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb );",
  33. " vec3 newColor = mix( result1, result2, L );",
  34. " float A2 = opacity * base.a;",
  35. " vec3 mixRGB = A2 * newColor.rgb;",
  36. " mixRGB += ( ( 1.0 - A2 ) * base.rgb );",
  37. " gl_FragColor = vec4( mixRGB, base.a );",
  38. "}"
  39. ].join( "\n" )
  40. };