Archived

This topic is now archived and is closed to further replies.

Drythe

Speed Up Alpha Blending

Recommended Posts

Whenever I scale a primitive with alpha blending too much the framerate goes way down. Is there any way to speed up the rendering in code? thx

Share this post


Link to post
Share on other sites
doesn''t it resize it anyway? i tried 64x64 (originally 128x128) and it''s just as slow unfortunately. I think it''s just taking a long time to draw the pixels on screen or something. As soon as I take off alpha blend it''s liquid smooth (but no transparency obviously).

Share this post


Link to post
Share on other sites
How big is the part of screen usually covered with blended object ? If it slows down especially when the object is covering bigger part of screen, then it is fillrate, I think.

What is the gfx card you are using ?


VladR
Avenger game

Share this post


Link to post
Share on other sites
i''m rendering about 5 quads with 64x64 textures (*.png) and when they cover about 50% or more of the screen it goes from 60fps to about 4. I''m using a GF2 vid card.

Share this post


Link to post
Share on other sites
Since I`m currently switching 4 gfx cards (TNT1, GF2MX, GF2GTS, GF3) on a daily basis, I could test it at home if you send it to me.
But it seems to be a fillrate problem since it appears mainly when transparent quads cover more than 50% of screen.

Are you rendering some smoke particles ? Can`t this be achieved through Alpha Testing ? It is supposed to be faster than alpha blending. So will you send it to me to test it ?

VladR
Avenger game

Share this post


Link to post
Share on other sites
1) Change the resolution and bitdepth of the screen with the same stuff being rendered. If it affects the frame rate, then fillrate is your likely bottleneck. Alpha blending uses up more fill rate because as well as plotting the pixel, the original pixel must be read. Also you lose most of the benefit from depth buffering.


2) If the polygons have areas which are totally transparent (i.e. alpha at around 0%), turn on alpha-test with a reference value of 0. A pixel which fails alpha test doesn''t write to the frame buffer or go through blending so doesn''t use so much fill rate for those areas. Beware though that alpha test does move Z test to later in the pipe so some early-Z-reject schemes stop working so your more expensive pixel shader setups may turn into another bottleneck.


3) The reverse of the above - if you have a lot of opaque pixels you can do the alpha in two passes. The first pass with full Z buffer writes and testing on and all alpha which isn''t ~100% rejected (i.e. only render opaque pixels). The second pass with alpha test as in point #2 to reject 0 pixels and blending on as usual for the rest. Rendering a large body of water (sea, lake etc) is the kind of thing that would benefit from this (assuming stuff like Fresnel term changing the alpha value).


4) If ever you''re scaling these textures **down**, i.e. minifying, then ALWAYS use MipMapping or you''ll be inefficient in texel cache terms.


5) Check if there''s a difference between all your polygons being all on screen and the same polygons straddling the edges of the screen. Although you should be benefitting from guardband, it''s still a test I''d do to see if clipping was somehow killing you.


6) Unfortunate reality: fillrate is the biggest limitation on most chips. Be careful and/or clever with how much see-through/glowy stuff you use and how you use it (most games come up against fillrate issues at some time or other).


7) There''s a presentation at the developer.nvidia.com site called something like "balancing the pipeline" that I''d recommend you download - it explains:

a. how to detect which bottlenecks are affecting you

b. how to reduce the problem

c. what you can trade (e.g. if you''re fillrate limited, increase your polycount etc)


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Is there any difference between an alpha blend as just a flat color without a texture that would somehow make it different?

[edited by - valles on June 4, 2003 1:40:22 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Drythe
how do i get only semi-transparent pixels to pass the alpha test?



Some examples:

// all alpha values != 0 get rendered
// i.e. those that aren''t 100% transparent get rendered
D3DRS_ALPHAREF=0
D3DRS_ALPHAFUNC=D3DCMP_NOTEQUAL

// all alpha values != 0xFF (1.0) get rendered
// i.e. those that aren''t 100% opaque get rendered
D3DRS_ALPHAREF=0xFF
D3DRS_ALPHAFUNC=D3DCMP_NOTEQUAL

// all alpha values > 127 (~0.5) get rendered
D3DRS_ALPHAREF=0x7F
D3DRS_ALPHAFUNC=D3DCMP_GREATER


etc...


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
quote:
Original post by valles
Is there any difference between an alpha blend as just a flat color without a texture that would somehow make it different?

[edited by - valles on June 4, 2003 1:40:22 AM]


1) Depends on your SetTextureStageState() calls, i.e. what YOU have asked the API/hardware to do.

2) In terms of actual blending, no there's no difference. Obviously having alpha in a texture gives you per-pixel control over alpha.

3) If you don't use any texture for colour AND alpha, then you save a texture lookup and potentially a texture unit so you might see performance benefits IF your bottleneck is in that area.

Are you seeing a particular problem or is this just a curiosity?

--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - S1CA on June 4, 2003 5:50:18 AM]

Share this post


Link to post
Share on other sites
Actually I have noticed substantial increases in framerate using only diffuse-alphablending polygons over using texture-based alphablending. Try it yourself: Create a nice big quad taking up the screen and compare SELECTARG1:DIFFUSE vs MODULATE:TEXTURE & DIFFUSE.

~CGameProgrammer( );

Share this post


Link to post
Share on other sites
quote:
Original post by CGameProgrammer
Actually I have noticed substantial increases in framerate using only diffuse-alphablending polygons over using texture-based alphablending. Try it yourself: Create a nice big quad taking up the screen and compare SELECTARG1:DIFFUSE vs MODULATE:TEXTURE & DIFFUSE.



Although it is of course entirely hardware and particular bottleneck dependent. The first key thing you should always do is identify the bottleneck(s) in YOUR app on YOUR target hardware.

The difference that disabling texturing makes WILL vary depending on what''s going on with the rest of the pipeline. It''ll make very little difference for example if vertex throughput or frame buffer bandwidth is your bottleneck. It''ll make a substantial difference in a contrived (IMO) test application. A normal app comes somewhere inbetween.

In practical terms, I''d still disable texturing for a depth write pass for example. I wouldn''t disable it if caused bad batching.

Share this post


Link to post
Share on other sites
quote:
Original post by S1CA
quote:
Original post by CGameProgrammer
Actually I have noticed substantial increases in framerate using only diffuse-alphablending polygons over using texture-based alphablending. Try it yourself: Create a nice big quad taking up the screen and compare SELECTARG1:DIFFUSE vs MODULATE:TEXTURE & DIFFUSE.



Although it is of course entirely hardware and particular bottleneck dependent. The first key thing you should always do is identify the bottleneck(s) in YOUR app on YOUR target hardware.

The difference that disabling texturing makes WILL vary depending on what''s going on with the rest of the pipeline. It''ll make very little difference for example if vertex throughput or frame buffer bandwidth is your bottleneck. It''ll make a substantial difference in a contrived (IMO) test application. A normal app comes somewhere inbetween.

In practical terms, I''d still disable texturing for a depth write pass for example. I wouldn''t disable it if caused bad batching.


Yes it is hardware-dependent, but every single game I''ve played had major slowdown when a texture-alpha-blended billboard was close to the viewer, regardless of whether it''s Half-Life, Quake 3, UT, GTA3, or my engine, so I wouldn''t say it only happens in "contrived" applications.

Specifically, in my engine going from diffuse to texture put the framerate from ~27 to ~19. I had about 20 polygons of varying size in front of me though, as it was a hacked example -- I took my fireball code and made the fireball hover in midair, and then I fired it and observed the framerate. I changed the blending from (srcalpha/invsrcalpha, modulate texture*diffuse) to (srcalpha/one, selectarg1 diffuse) and tried it again.

~CGameProgrammer( );

Share this post


Link to post
Share on other sites
quote:
Yes it is hardware-dependent, but every single game I''ve played had major slowdown when a texture-alpha-blended billboard was close to the viewer, regardless of whether it''s Half-Life, Quake 3, UT, GTA3, or my engine, so I wouldn''t say it only happens in "contrived" applications.


Out of interest, how did you determine that this was a result of those apps blending with their polygons with textures as opposed to simply being FILLRATE BOUND?

Screen sized, alpha blended quads will suck up fillrate and therefore kill framerate, entirely regardless of whether they have a texture applied or not. Indeed fillrate is one of the most common graphics bottlenecks on any platform.


quote:
Specifically, in my engine going from diffuse to texture put the framerate from ~27 to ~19. I had about 20 polygons of varying size in front of me though, as it was a hacked example -- I took my fireball code and made the fireball hover in midair, and then I fired it and observed the framerate. I changed the blending from (srcalpha/invsrcalpha, modulate texture*diffuse) to (srcalpha/one, selectarg1 diffuse) and tried it again.


Yep, your app, your test hardware. I don''t actually think we''re disagreeing at all here - I''m just pointing out that although you''re likely to see "some" performance benefit, you won''t always see "significant" benefit from turning off textures. Particularly in an app which has a fully loaded frame (i.e. an average frame from a game) or a bottleneck in a different place.


BTW: your texture(s) wasn''t being minified (with respect to screen space area) anywhere without mipmapping being used was it?, or trilinear filtered?

Share this post


Link to post
Share on other sites
The texture was a very simple 16x16 "glow" which was close enough to take up most of the screen, so it was definitely stretched, not shrunk. I know of the slowdown you''re talking about, though I can''t remember the reason for it.

~CGameProgrammer( );

Share this post


Link to post
Share on other sites