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!
tfreifeld:
What’s luma?
It’s the brightness of a color.
In video, luma represents the brightness in an image (the "black-and-white" or achromatic portion of the image). Luma is typically paired with chrominance. Luma represents the achromatic image, while the chroma components represent the color information. Converting R′G′B′ sources (such as the output of a three-CCD camera) into luma and chroma allows for chroma subsampling: because human vision has finer spatial sensitivity to luminance ("black and white") differences than chromatic differences, v...
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