BleachBypassShader.js 1.2 KB

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