Jump to content
  • Advertisement
Sign in to follow this  
Pfhoenix

Coloring Textures

This topic is 4762 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

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 this post


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

Thanks for the reply,
- Pfhoenix

Share this post


Link to post
Share on other sites
I use something like this:

Relevant render states:
D3DRS_ALPHABLENDENABLE TRUE
D3DRS_SRCBLEND D3DBLEND_SRCALPHA
D3DRS_DESTBLEND D3DBLEND_INVSRCALPHA
Relevant texture stage states (all for stage 0):
D3DTSS_COLOROP D3DTOP_MODULATE (default)
D3DTSS_COLORARG1 D3DTA_TEXTURE (default)
D3DTSS_COLORARG2 D3DTA_TFACTOR
D3DTSS_ALPHAOP D3DTOP_MODULATE
D3DTSS_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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Pfhoenix
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

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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!