LuminosityShader.js 670 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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:
  13. /* glsl */
  14. `
  15. varying vec2 vUv;
  16. void main() {
  17. vUv = uv;
  18. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  19. }`,
  20. fragmentShader:
  21. /* glsl */
  22. `
  23. #include <common>
  24. uniform sampler2D tDiffuse;
  25. varying vec2 vUv;
  26. void main() {
  27. vec4 texel = texture2D( tDiffuse, vUv );
  28. float l = linearToRelativeLuminance( texel.rgb );
  29. gl_FragColor = vec4( l, l, l, texel.w );
  30. }`
  31. };
  32. THREE.LuminosityShader = LuminosityShader;
  33. } )();