# Coloring Textures

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

## Recommended Posts

I'm just getting started in dealing with texture stages. I'm trying to not just colorize a texture, but then also have it alpha'd against the destination properly. I currently set texture stage 0 to BLENDFACTORALPHA and set COLORARG1 to to TEXTURE and COLORARG2 to TFACTOR. I can color the texture, no problem, but I can't seem to figure out how to take that result and then still properly alpha it on the destination surface. My surface alpha is set to SRCCOLOR, and the destination alpha is set to SRCALPHA. Any pointers would be greatly appreciated. - Pfhoenix

##### Share on other sites
Did you set ALPHAARG1 and ALPHAARG2 appropriately?

##### Share on other sites
Hmm, nope, what should they be set to (and should they be set in the same texture stage)?

- Pfhoenix

##### Share on other sites
I use something like this:
Relevant render states:D3DRS_ALPHABLENDENABLE   TRUED3DRS_SRCBLEND           D3DBLEND_SRCALPHAD3DRS_DESTBLEND          D3DBLEND_INVSRCALPHARelevant texture stage states (all for stage 0):D3DTSS_COLOROP           D3DTOP_MODULATE (default)D3DTSS_COLORARG1         D3DTA_TEXTURE (default)D3DTSS_COLORARG2         D3DTA_TFACTORD3DTSS_ALPHAOP           D3DTOP_MODULATED3DTSS_ALPHAARG1         D3DTA_TEXTURE (default)D3DTSS_ALPHAARG2         D3DTA_TFACTOR

The result is about what you are looking for, I think.
EDIT: Oh yeah, that's for Direct3D 8.1. Any differences (between 8.1 and 9.0, or between what I do and the effect you want) should be pretty easy to sort out with the help of the documentation.

##### Share on other sites
I'm using DX9, though I don't think there's a difference in this area.

Sadly, the modulate settings didn't accomplish what I wanted. Maybe I explained myself poorly :

Given a Texture T and a Color C (both of which have alpha channel), I want to Color-shade T by C (using the alpha of C), and then have the resulting tinted T alpha properly on the destination surface (using the alpha of T, which shouldn't be modified by C).

I tried playing around with ALPHAREPLICATE, but didn't see any results in testing.

- Pfhoenix

##### Share on other sites
Quote:
 Original post by PfhoenixI'm using DX9, though I don't think there's a difference in this area.Sadly, the modulate settings didn't accomplish what I wanted. Maybe I explained myself poorly :Given a Texture T and a Color C (both of which have alpha channel), I want to Color-shade T by C (using the alpha of C), and then have the resulting tinted T alpha properly on the destination surface (using the alpha of T, which shouldn't be modified by C).I tried playing around with ALPHAREPLICATE, but didn't see any results in testing. - Pfhoenix

You're still not making a ton of sense. It sounds like you want to mix the color channels and the alpha channels somehow, but I don't think that is what you meant. Explain it like this (assumes all color components are in the range of 0.0 to 1.0):

result.alpha = texture0.alpha*tfactor.alpha;
result.red = texture0.red*tfactor.red;
result.green = texture0.green*tfactor.green;
result.blue = texture0.blue*tfactor.blue;

That is what the settings I gave you does to produce it's intermediate output, which is then alpha blended with the current destination color to produce the new one. I can try to write up the alpha blending function, as well, if that is where your problem is.

##### Share on other sites
You were right; I had turned off ALPHABLENDENABLE at one point (as a test), and had forgotten to re-enable it.

Thanks for your help, it works.

- Pfhoenix

• 10
• 17
• 9
• 13
• 41