LuminosityShader.js 768 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @module LuminosityShader
  3. * @three_import import { LuminosityShader } from 'three/addons/shaders/LuminosityShader.js';
  4. */
  5. /**
  6. * Luminosity shader.
  7. *
  8. * @constant
  9. * @type {ShaderMaterial~Shader}
  10. */
  11. const LuminosityShader = {
  12. name: 'LuminosityShader',
  13. uniforms: {
  14. 'tDiffuse': { value: null }
  15. },
  16. vertexShader: /* glsl */`
  17. varying vec2 vUv;
  18. void main() {
  19. vUv = uv;
  20. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  21. }`,
  22. fragmentShader: /* glsl */`
  23. #include <common>
  24. uniform sampler2D tDiffuse;
  25. varying vec2 vUv;
  26. void main() {
  27. vec4 texel = texture2D( tDiffuse, vUv );
  28. float l = luminance( texel.rgb );
  29. gl_FragColor = vec4( l, l, l, texel.w );
  30. }`
  31. };
  32. export { LuminosityShader };