# Texturing - color blending

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

## Recommended Posts

Hi everyone. Happy new year. Quick question on blending RGB values. I have a routine to generate a procedural texture using 4 base textures - water, sand, grass, and rock. I now want to make a second pass of that generated texture and "blend" in some more textures. The first pass of course takes the appropriate amounts of color from the 4 base textures to generate each pixel (region based). The second pass has to somehow take the current pixel RGB values and combine with the new texture pixel RGB multiplied by the region % for the pixel at that height. I'm having trouble figuring out the technique to use here. ie. Say we have a green grass area and I want to combine with a grey/black pixel that has a blend factor of 0.1 say. How do I keep the green and blend in the grey multiplied by 0.1? I have tried a number of methods, but most just leave me with th grey - which contrasts starkly with the neighbouring greens, or I simply end up lightening the current green to almost white. I know, my explanation is as clear as mud :) Thanks.

##### Share on other sites
Don't you just mean:

Original_Colour += (Weight * New_Colour)

That way, you'd have:

RGB(255,0,0) += (0.1 * RGB(128,128,128)

RGB( 255 + 12.8, 12.8, 12.8 ) -- > RGB( 255, 13, 13 )

which, unless I'm very much mistaken, is what you want?

To do a complex blending based on decoding the previous blend factors isn't possible as far as I know:

say the Original_Colour was a weighted combination of your 4 base textures:

Original_Colour = A*Tex0 + B*Tex1 + C*Tex2 + D*Tex3

And you then wanted to come along and add in a grey component based only on where Tex1 is (i.e. the 'B' quantity), you'd really need to know the original weighting factor - just taking "Original_Colour" makes it very difficult, if not impossible, to get the weighting factors back again.

hth
Jack

##### Share on other sites
Quote:
 Original post by jollyjeffersDon't you just mean:Original_Colour += (Weight * New_Colour)That way, you'd have:RGB(255,0,0) += (0.1 * RGB(128,128,128)RGB( 255 + 12.8, 12.8, 12.8 ) -- > RGB( 255, 13, 13 )which, unless I'm very much mistaken, is what you want?

Not exactly. That's the technique used to generate the base texture. Now I want to go revisit that and add in more textures at specific locations. Adding in only lightens the existing color and moves it more towards white. I need to transition between two. Actually, that answers my question. I need to interpolate between the two colors using the weight as the multiplier. I tested with this little routine and it works fine. For the test I transition over 10 steps and I can move from source to destination correctly. Looks ok.

int sR=0; int sG=99; int sB=33;int dR=63; int dG=63; int dB=63;int nR=0; int nG=0; int nB=0;for (int i = 1; i <= 10; i++) {  glPushMatrix();    glTranslatef(1.0f,(float)-5.0f+i,0.0f);    nR=(float)sR+(((dR-sR)/10.0f)*i);    nG=(float)sG+(((dG-sG)/10.0f)*i);    nB=(float)sB+(((dB-sB)/10.0f)*i);    glColor4f(nR/255.0f,nG/255.0f,nB/255.0f,1.0f);    DrawEllipse(1.0f,0.5f);  glPopMatrix();}

Thanks a lot for responding Jack. Hope East Anglia is not too cold (I'm from the north of England originally. Now in Tokyo - has 2 inches of snow yesterday actually, which is probably more than the UK).

[Edited by - Fahrenheit451 on January 7, 2006 10:22:39 AM]

##### Share on other sites
Got it working btw. The grey color is the additional texture colors blended in with the base terrain. That would normally be green/bown all the way up the hill.

before

after

[Edited by - Fahrenheit451 on January 7, 2006 10:15:16 AM]

##### Share on other sites
Bit slow replying... been away from the computer for a while [grin]

Quote:
 Thanks a lot for responding Jack. Hope East Anglia is not too cold (I'm from the north of England originally. Now in Tokyo - has 2 inches of snow yesterday actually, which is probably more than the UK).

I'm starting to forget what snow is like... definitely hasn't been any in East Anglia yet. I'm moving back to Hampshire tomorrow, the chances of seeing any snow down there aren't going to be any better [sad]..

As a little side note, your function you devised is functionally the same as the linear alpha-blending equation: a + t * (b - a) where a is your initial colour/value, b is your final colour/value and t is the weight where 0.0==a and 1.0==b.

The pic's look damn good as well.

Jack

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633348
• Total Posts
3011462

×