LuminosityHighPassShader.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. Color
  3. } from 'three';
  4. /** @module LuminosityHighPassShader */
  5. /**
  6. * Luminosity high pass shader.
  7. *
  8. * @constant
  9. * @type {Object}
  10. */
  11. const LuminosityHighPassShader = {
  12. name: 'LuminosityHighPassShader',
  13. shaderID: 'luminosityHighPass',
  14. uniforms: {
  15. 'tDiffuse': { value: null },
  16. 'luminosityThreshold': { value: 1.0 },
  17. 'smoothWidth': { value: 1.0 },
  18. 'defaultColor': { value: new Color( 0x000000 ) },
  19. 'defaultOpacity': { value: 0.0 }
  20. },
  21. vertexShader: /* glsl */`
  22. varying vec2 vUv;
  23. void main() {
  24. vUv = uv;
  25. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  26. }`,
  27. fragmentShader: /* glsl */`
  28. uniform sampler2D tDiffuse;
  29. uniform vec3 defaultColor;
  30. uniform float defaultOpacity;
  31. uniform float luminosityThreshold;
  32. uniform float smoothWidth;
  33. varying vec2 vUv;
  34. void main() {
  35. vec4 texel = texture2D( tDiffuse, vUv );
  36. float v = luminance( texel.xyz );
  37. vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
  38. float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
  39. gl_FragColor = mix( outputColor, texel, alpha );
  40. }`
  41. };
  42. export { LuminosityHighPassShader };
粤ICP备19079148号