LuminosityShader.js 690 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Luminosity
  5. * http://en.wikipedia.org/wiki/Luminosity
  6. */
  7. THREE.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. "uniform sampler2D tDiffuse;",
  20. "varying vec2 vUv;",
  21. "void main() {",
  22. "vec4 texel = texture2D( tDiffuse, vUv );",
  23. "vec3 luma = vec3( 0.299, 0.587, 0.114 );",
  24. "float v = dot( texel.xyz, luma );",
  25. "gl_FragColor = vec4( v, v, v, texel.w );",
  26. "}"
  27. ].join( "\n" )
  28. };