Sign in to follow this  

Alpha blending

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

Why is drawing with alpha blending that much slower than not? are there any tricks to speed it up? I use alpha blending on my terrain where I draw the textures in layers in separate passes (I need more than a few textures per chunk). First layer is the base texture with black areas for where the layers go - this is drawn with no alpha. I then draw the layers on top blending them as I go.

It's pretty quick and I'm happy with the performance but when I look directly down at the terrain so the blended area covers the whole screen, I lose a millisecond or so for 3 or 4 DIPs compared to looking across the terrain with 30 or 40 DIPs and only a quarter of the screen covered by blended area.

Obviously I'm not trying to optimise too early, I'm just curious as to why and whether there are any tricks to improve the speed.

I'm using DX9 at the moment and I don't think I'm doing anything out of the ordinary.

Thanks

Edit: actually, I just tried removing the alpha blend flags from my terrain shader so it just draws the solid terrain layers and still cost an extra 1ms. I guess that means my layer shader is too expensive rather than the alpha blending. Hmm... So tempting to optimise!!

Share this post


Link to post
Share on other sites

The main reason that alpha blending is slower is due to the fact that you aren't just writing memory - you first have to read the existing pixel values, perform the blend operation, and then write again.  So you are increasing the per-pixel operations performed, and you are significantly increasing the bandwidth being consumed.

 

Is it possible for you to do the blending in the pixel shader instead of in the blend unit?  I wouldn't be afraid to experiment a little and see if you can do something better, but just don't get sidetracked into searching for 0.5 ms time improvement until it becomes apparent that you need that time!

Share this post


Link to post
Share on other sites

There's another option that can make alpha blending faster. Enable alpha testing (or use clip() in the shader).

 

It's most helpful where memory bandwidth is limited as it trades off shader instructions for blending work. For that reason, the effect tends to be most noticeable on lower end hardware.

Share this post


Link to post
Share on other sites
Thanks guys. I think most of my time in my layer shader is going in the pixel shader's texture reads. I'm doing:

1) diffuse read
2) base texture read
3) blender tile read
4) 4 x blend map reads
5) normal read
6) specular read
7) bump read
8) detail read

I can optimise 4) down to 1 read but otherwise I need all the others I think.

Turning alpha off doesn't really give me any speed boost so clearly my pixel shader needs some work.

Jason, what did you mean by doing the blending in the pixel shader? Wouldn't that require 2 passes?

Share this post


Link to post
Share on other sites

Even without knowing what kind of GPU you're using, 1ms to fill the entire screen with a terrain shader sounds pretty cheap!That's a mere 6% of your frametime for a 60Hz budget.


I'm using an nvidia GT750m (on my MacBook Pro) with a 2.5GHz quad core i7.

Filling the screen (ie looking directly down at the ground) with no terrain layers (so just showing the default terrain material) which is around 1-2 DIPs, is approximately 2ms, painting the terrain on this view to fill the screen is approximately 3.5ms (in total). My budget is 16 so it does feels like I've got a lot to spare and to be fair the game will never have this viewing angle so I'm not overly concerned just yet. I'll reduce those 4 blend map reads down to one and peg this shader as a possible future optimise.

Share this post


Link to post
Share on other sites

This topic is 1110 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this