Jump to content
  • Advertisement
Sign in to follow this  
dweeb

Texture blending

This topic is 5049 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 having a bit of a struggle with texture blending. All I want to do is to add 2 textures togheter. The first texture is just a regular image but the second has alpha. (I'm trying to create an overlay for my terrain). The result I'm looking for is to have the second picture added to the first one and the alpha of the second picture should not be added. I know that I need to use SetTextureStageState but I just cannot seem to find the correct mix to get what I want. Is there anyone who could let me know which different operation I should do. Is there any good tutorials which covers texture blending with the different operations. I've read through the SDK but descriptions are too short...

Share this post


Link to post
Share on other sites
Advertisement
I would seriously recommend you look into using Pixel Shaders. I think it's not absolutely NECESSARY for what you are looking to do, but having the knowledge of how to do it under your belt couldn't hurt. Plus, it'll be MUCH faster since it'll be using the processing power of the GPU rather than using up valuable CPU time ;) Also, you can add some nice effects in and stuff if you decide to

Share this post


Link to post
Share on other sites
To add two textures my immediate answer would be:


SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);

SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);

However, I don't follow what you mean by the alpha of the second image should not be added. Not be added to what?

-Mezz

Share this post


Link to post
Share on other sites
(I believe he means so he can fade from grass to stone e.g., thus doing so by only taking the amount of grass specified in the alpha-channel)

Share this post


Link to post
Share on other sites
Ah, so you could do something like linearly interpolate between the two textures based on alpha?
Perhaps this would suit your needs:

// stage 0
SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);

// stage 1
SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);

On the "stage 1" setting you can swap the values of ARG1 and ARG2 around if it doesn't give you the correct blending you want (this would depend on how your alpha is set up in the texture), the equation is actually

Output = Arg1 * Alpha + Arg2 * (1 - Alpha)
Where alpha is the alpha from the texture bound to the stage you're on.

-Mezz

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!