BleachBypassShader.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/#manual/en/introduction/Installation." );
  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. THREE.BleachBypassShader = {
  8. uniforms: {
  9. "tDiffuse": { value: null },
  10. "opacity": { value: 1.0 }
  11. },
  12. vertexShader: [
  13. "varying vec2 vUv;",
  14. "void main() {",
  15. " vUv = uv;",
  16. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  17. "}"
  18. ].join( "\n" ),
  19. fragmentShader: [
  20. "uniform float opacity;",
  21. "uniform sampler2D tDiffuse;",
  22. "varying vec2 vUv;",
  23. "void main() {",
  24. " vec4 base = texture2D( tDiffuse, vUv );",
  25. " vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 );",
  26. " float lum = dot( lumCoeff, base.rgb );",
  27. " vec3 blend = vec3( lum );",
  28. " float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) );",
  29. " vec3 result1 = 2.0 * base.rgb * blend;",
  30. " vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb );",
  31. " vec3 newColor = mix( result1, result2, L );",
  32. " float A2 = opacity * base.a;",
  33. " vec3 mixRGB = A2 * newColor.rgb;",
  34. " mixRGB += ( ( 1.0 - A2 ) * base.rgb );",
  35. " gl_FragColor = vec4( mixRGB, base.a );",
  36. "}"
  37. ].join( "\n" )
  38. };