LuminosityHighPassShader.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ( function () {
  2. /**
  3. * Luminosity
  4. * http://en.wikipedia.org/wiki/Luminosity
  5. */
  6. const LuminosityHighPassShader = {
  7. shaderID: 'luminosityHighPass',
  8. uniforms: {
  9. 'tDiffuse': {
  10. value: null
  11. },
  12. 'luminosityThreshold': {
  13. value: 1.0
  14. },
  15. 'smoothWidth': {
  16. value: 1.0
  17. },
  18. 'defaultColor': {
  19. value: new THREE.Color( 0x000000 )
  20. },
  21. 'defaultOpacity': {
  22. value: 0.0
  23. }
  24. },
  25. vertexShader: /* glsl */`
  26. varying vec2 vUv;
  27. void main() {
  28. vUv = uv;
  29. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  30. }`,
  31. fragmentShader: /* glsl */`
  32. uniform sampler2D tDiffuse;
  33. uniform vec3 defaultColor;
  34. uniform float defaultOpacity;
  35. uniform float luminosityThreshold;
  36. uniform float smoothWidth;
  37. varying vec2 vUv;
  38. void main() {
  39. vec4 texel = texture2D( tDiffuse, vUv );
  40. vec3 luma = vec3( 0.299, 0.587, 0.114 );
  41. float v = dot( texel.xyz, luma );
  42. vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
  43. float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
  44. gl_FragColor = mix( outputColor, texel, alpha );
  45. }`
  46. };
  47. THREE.LuminosityHighPassShader = LuminosityHighPassShader;
  48. } )();