ColorifyShader.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. console.warn( "THREE.ColorifyShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * Colorify shader
  6. */
  7. THREE.ColorifyShader = {
  8. uniforms: {
  9. "tDiffuse": { value: null },
  10. "color": { value: new THREE.Color( 0xffffff ) }
  11. },
  12. vertexShader: [
  13. "varying vec2 vUv;",
  14. "void main() {",
  15. " vUv = uv;",
  16. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  17. "}"
  18. ].join( "\n" ),
  19. fragmentShader: [
  20. "uniform vec3 color;",
  21. "uniform sampler2D tDiffuse;",
  22. "varying vec2 vUv;",
  23. "void main() {",
  24. " vec4 texel = texture2D( tDiffuse, vUv );",
  25. " vec3 luma = vec3( 0.299, 0.587, 0.114 );",
  26. " float v = dot( texel.xyz, luma );",
  27. " gl_FragColor = vec4( v * color, texel.w );",
  28. "}"
  29. ].join( "\n" )
  30. };