LuminosityShader.js 645 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ( function () {
  2. /**
  3. * Luminosity
  4. * http://en.wikipedia.org/wiki/Luminosity
  5. */
  6. const LuminosityShader = {
  7. uniforms: {
  8. 'tDiffuse': {
  9. value: null
  10. }
  11. },
  12. vertexShader: /* glsl */`
  13. varying vec2 vUv;
  14. void main() {
  15. vUv = uv;
  16. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  17. }`,
  18. fragmentShader: /* glsl */`
  19. #include <common>
  20. uniform sampler2D tDiffuse;
  21. varying vec2 vUv;
  22. void main() {
  23. vec4 texel = texture2D( tDiffuse, vUv );
  24. float l = luminance( texel.rgb );
  25. gl_FragColor = vec4( l, l, l, texel.w );
  26. }`
  27. };
  28. THREE.LuminosityShader = LuminosityShader;
  29. } )();