Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TheMummy

How to blend two colours ????

This topic is 6769 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I want to combine two colours to a new colour, for example for transparncy and for lighting effects. How do I calculate the resulting colour ? Rres = (Ra+Rb) / 2 Bres = (Ba+BB) / 2 .... ???? Is there a difference between the blending with lights and the blending with transparent surfaces? (additive/subtractive colour mixing ????) Can somone explain. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
If you are writing your own rendering engine (using no API) then I can''t help you, but if you are using GL, then just look in the Red Book for the blending/lighting equations.
You can find this book on the internet - just look over on Nehe''s site for the link

-Mezz

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here''s a simple alpha-blending equation:

C = A*a + B*(1-a)
= A*a + B - B*a
= B + (A-B)*a // simplified

where a (your alpha value) is in the range from 0.0 to 1.0

In terms of color components RGB, you can express this as:

Cr = Br + (Ar - Br)*a // red
Cg = Bg + (Ag - Bg)*a // green
Cb = Bb + (Ab - Bb)*a // blue

So, when a is 0, your resulting color C will be B.
When a is 1, your resulting color C will be A.

A 50% blend would be:
A*0.5 + B*(1-0.5) = A*1/2 + B*1/2 = (A+B) / 2

which is exactly what you had in your post above.

Share this post


Link to post
Share on other sites
Thanks,
Lightmap blending:
What would I have to do when I have two lightmaps, and I want to combine them into one. The lightmaps have a R,G,B and an Alpha channel?

Illumination:
In a shortened german Version of the Red Book I found a formula: a light with the color A hits a surface with the color B, the resulting color displayed on screen will be C.

C = A * B

Cr = Ar * Br
Cg = Ag * Bg
Cb = Ab * Bb

BUT where is the alpha channel? I have an Alpha channel in my lightmaps (well, will have...) How would I have to calculate the resulting color? Blend the two colors or multiply them? I am a bit slow in understanding.

Share this post


Link to post
Share on other sites
Just like in real world. If theres for example one light pointing on a wall, and then anoter light is pointing on this position too, it is as double as bright as before.

R1 + R2 = Rl _//red light

If it is no light, just blending 2 textures, you must calculate it like this:

(R1 + R2) /2 = Rb _//Red blend



Edited by - Anonymous Poster on 4/18/00 2:56:09 AM

Share this post


Link to post
Share on other sites
Are you sure?
quote: (R1 + R2) /2 = Rb _//Red blend

that would be:
(R1red + R2red) / 2 = Rbred
(R1green + R2green) / 2 = Rbgreen
(R1blue + R2blue) / 2 = Rbblue
(R1alpha + R2alpha) / 2 = Rbalpha

When I blend two Texels with 4 channels shall I then ignore the alpha values ??

Share this post


Link to post
Share on other sites
Hello again,
I still wait for a reply ;-) !
I have two Lightmaps of a polygon, I want to combine them into one Lightmap to save memory and render time. What is the correct formula to combine them ?

HELP ME PLEASE !!!!!

Share this post


Link to post
Share on other sites
To combine two lightmaps you should add the values, because it they represent two lightsources and light is additive, so do it like this:

NewMap = Min(LightMap1 + LightMap2, MaxLight)

Where MaxLight is set to the maximum value that your lightmaps can have (28-1 = 255 for 8 bit channels). Do this for each channel (Red, Green, and Blue) and pixel in the lightmaps.

I don''t know what you want to use the alpha channel in your lightmap for, but it certainly isn''t for combining two lightmaps.

When you light your polygons with the lightmap you are should multiply the color of the polygon with the color of the lightmap.

DestColor = PolyColor*LightmapColor





- WitchLord

Share this post


Link to post
Share on other sites
Hi WitchLord,

A few months ago I asked a web-friend how lightmaps work. He replied that there are two textures a solid and a transparent one, the lightmap . First I have to draw the solid and then I have to blend the other one. So I thought I need an Alpha Channel and a blending function like: SCREEN = SOLID*(1-alpha) + LIGHTMAP*alpha <- like the GL_ONE_MINUS_SOURCE_ALPHA in ogl.

Is that wrong ?

Edited by - TheMummy on 5/4/00 7:06:55 AM

Share this post


Link to post
Share on other sites
Yes it''s wrong. The lightmap is supposed to ''simulate'' the lighting that OGL or D3D do at the vertices, i.e. the light is multiplied with the color of the material (texture). That is why the blending function should be

glBlendFunc(GL_DST_COLOR, GL_ZERO);

when rendering the lightmap.

This multiplies the color of the lightmap with the color that is already in the framebuffer (from the solid texture).

The lightmap is transparent in the effect that if you don''t render the solid texture first, you can see what is behind the lightmap (unless it''s completely black). The lightmap should in other words not have a alpha channel.


- WitchLord

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!