## how to calculate RGB transparence in shader programs?

Oct 4, 2006 at 1:21pm

# how to calculate RGB transparence in shader programs?

hello,
i have a texture,
and i’d like to apply a colored tint to it;
i’d like the percentage of this tint to be a controllable parameter.

now, it makes sense that if i multiply the RGB values of a pixel in my texture by my tint-color’s fractional RGB values (i.e. devide values between 0 and 255 by 255), then i get the color i want; but i wanna get less of that color than %100;

if i were doing this in jitter, i would place another plane in front of my video plane for instance, and give it an alpha transparence; i’m wondering how i can get the same effect by calculating the RGB values of each pixel “by hand”, as i have to do in the fragment shader of my program.

i tried to find a formula online but i don’t think i’ve found the best color resources on the web yet…

thank you,
a

#27963
Oct 4, 2006 at 1:58pm

For this, the most straightforward way would be to use the mix() function:
mix(source,tint-color,amount);
Remember that in this case amount can (and should) be a vec4.

Hope that helps.

Andrew

#85295
Oct 4, 2006 at 2:20pm

of course!
sorry, obvious question…
and then i found all the compositing examples and now i have more ways to do what i wanted than i ever would want.

on the other hand, i’m noticing something that i don’t quite undertsand. when i use your suggested mix(source, tint, amount) expression, i find that if i define ‘amount’ as a uniform vec4 and send it in from out, i get two very different results if send things like “amoung .5″ and “amount .5 .5 .5 .5″; it actually seems to me like “amount .5″ gives the correct result, i.e. 1/2 way between the source and the tint… what does each of these actualy do?

yours,
a

#85296

You must be logged in to reply to this topic.