LuminosityHighPassShader.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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:
  26. /* glsl */
  27. `
  28. varying vec2 vUv;
  29. void main() {
  30. vUv = uv;
  31. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  32. }`,
  33. fragmentShader:
  34. /* glsl */
  35. `
  36. uniform sampler2D tDiffuse;
  37. uniform vec3 defaultColor;
  38. uniform float defaultOpacity;
  39. uniform float luminosityThreshold;
  40. uniform float smoothWidth;
  41. varying vec2 vUv;
  42. void main() {
  43. vec4 texel = texture2D( tDiffuse, vUv );
  44. vec3 luma = vec3( 0.299, 0.587, 0.114 );
  45. float v = dot( texel.xyz, luma );
  46. vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
  47. float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
  48. gl_FragColor = mix( outputColor, texel, alpha );
  49. }`
  50. };
  51. THREE.LuminosityHighPassShader = LuminosityHighPassShader;
  52. } )();