LuminosityHighPassShader.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @author bhouston / http://clara.io/
  3. *
  4. * Luminosity
  5. * http://en.wikipedia.org/wiki/Luminosity
  6. */
  7. import {
  8. Color
  9. } from "../../../build/three.module.js";
  10. var LuminosityHighPassShader = {
  11. shaderID: "luminosityHighPass",
  12. uniforms: {
  13. "tDiffuse": { value: null },
  14. "luminosityThreshold": { value: 1.0 },
  15. "smoothWidth": { value: 1.0 },
  16. "defaultColor": { value: new Color( 0x000000 ) },
  17. "defaultOpacity": { value: 0.0 }
  18. },
  19. vertexShader: [
  20. "varying vec2 vUv;",
  21. "void main() {",
  22. "vUv = uv;",
  23. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  24. "}"
  25. ].join("\n"),
  26. fragmentShader: [
  27. "uniform sampler2D tDiffuse;",
  28. "uniform vec3 defaultColor;",
  29. "uniform float defaultOpacity;",
  30. "uniform float luminosityThreshold;",
  31. "uniform float smoothWidth;",
  32. "varying vec2 vUv;",
  33. "void main() {",
  34. "vec4 texel = texture2D( tDiffuse, vUv );",
  35. "vec3 luma = vec3( 0.299, 0.587, 0.114 );",
  36. "float v = dot( texel.xyz, luma );",
  37. "vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );",
  38. "float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );",
  39. "gl_FragColor = mix( outputColor, texel, alpha );",
  40. "}"
  41. ].join("\n")
  42. };
  43. export { LuminosityHighPassShader };