2
0

LuminosityShader.js 712 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Luminosity
  5. * http://en.wikipedia.org/wiki/Luminosity
  6. */
  7. var LuminosityShader = {
  8. uniforms: {
  9. "tDiffuse": { value: null }
  10. },
  11. vertexShader: [
  12. "varying vec2 vUv;",
  13. "void main() {",
  14. "vUv = uv;",
  15. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  16. "}"
  17. ].join( "\n" ),
  18. fragmentShader: [
  19. "#include <common>",
  20. "uniform sampler2D tDiffuse;",
  21. "varying vec2 vUv;",
  22. "void main() {",
  23. "vec4 texel = texture2D( tDiffuse, vUv );",
  24. "float l = linearToRelativeLuminance( texel.rgb );",
  25. "gl_FragColor = vec4( l, l, l, texel.w );",
  26. "}"
  27. ].join( "\n" )
  28. };
  29. export { LuminosityShader };