ColorifyShader.js 729 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Colorify shader
  5. */
  6. THREE.ColorifyShader = {
  7. uniforms: {
  8. "tDiffuse": { value: null },
  9. "color": { value: new THREE.Color( 0xffffff ) }
  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 vec3 color;",
  20. "uniform sampler2D tDiffuse;",
  21. "varying vec2 vUv;",
  22. "void main() {",
  23. "vec4 texel = texture2D( tDiffuse, vUv );",
  24. "vec3 luma = vec3( 0.299, 0.587, 0.114 );",
  25. "float v = dot( texel.xyz, luma );",
  26. "gl_FragColor = vec4( v * color, texel.w );",
  27. "}"
  28. ].join( "\n" )
  29. };