GrayScaleShader.js 706 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @author Mugen87 / https://github.com/Mugen87
  3. *
  4. * see https://en.wikipedia.org/wiki/Grayscale
  5. *
  6. */
  7. THREE.GrayScaleShader = {
  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. "const vec3 weight = vec3( 0.2126, 0.7152, 0.0722 );",
  23. "vec3 color = texture2D( tDiffuse, vUv ).rgb;",
  24. "float luminance = dot( color, weight );",
  25. "gl_FragColor = vec4( vec3( luminance ), 1 );",
  26. "}"
  27. ].join( "\n" )
  28. };