Jump to content
  • Advertisement
Sign in to follow this  
LevyDee

Blend textures in HLSL

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

Hello, it has been a long time since I have worked in hlsl and when I did I was never a prodigy by any means. My scenario is this. I have three textures. I would like to alpha blend them starting with texture one as the base, then blend two and then finally blend three using the alpha channel(A8R8G8B8 format). Im pretty sure multiple passes are unnecessary and I really dont have much of a clue how to get this achieved. I feel it should be pretty simple. Basically what would my pixel shader look like?

 

Thank you for any help!

Share this post


Link to post
Share on other sites
Advertisement

I'm not really sure what your goal is, but according to Wikipedia, here's how to alpha-blend partially-transparent colors (not tested).

float4 blend(float4 A, float4 B)
{
   float4 C;
   C.a = A.a + (1 - A.a) * B.a;
   C.rgb = (1 / C.a) * (A.a * A.rgb + (1 - A.a) * B.a * B.rgb);
   return C;
}

float4 D = blend(blend(A, B), C);

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!