ColorifyShader explanation

Hi,

I would appreciate an explanation for how ColorifyShader works.

vec4 texel = texture2D( tDiffuse, vUv );
vec3 luma = vec3( 0.299, 0.587, 0.114 );
float v = dot( texel.xyz, luma );
gl_FragColor = vec4( v * color, texel.w );

What’s luma? What does it even mean (I’m not an english native speaker)? and what are these very specific numbers?
Why do we take the dot product of the texel and the luma to receive the final color?

Thanks!

It’s the brightness of a color.

It’s a formula for computing luma (the so called Rec. 601 luma).

The computation allows you to change the fragment’s color but maintain its original brightness.

3 Likes

Thanks @Mugen87!

Why when I play with the alpha component in the last line, it doesn’t seem to have any effect?

You probably have to set the transparent property to true for the respective shader material.

2 Likes