LuminosityHighPassShader.js 1.2 KB

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