Alphatest -> bad performance

Hi

Well, i just tested how to setup my engine, to get the best performance out of it.

I then enabled alpha-testing. From earlier tests i knew, that it is for free.
Now i rendered flat polys, no texturing, no blending and stuff.
I don´t have any polys/pixels, that get filtered out by the alpha-test, but i didn´t expect a hit, because of my previous experience.

Now i enabled it, with AlphaFunc set to
GL_GEQUAL/0.95
and my FPS dropped from 270 to 220 !!!

At the moment i render around 3000 triangles per frame, in one (or two) calls, with VBO.

Could it be, that alphatest works only for free, when texturing is enabled? nVidia said, that they can render flat polys with twice the speed of textured ones. Could it be, that they dropped alpha-test support for them to speed it up a bit more, since it doesn´t make much sense to use alpha-test for flat polys, at all?

I am just curious. I don´t need alpha-testing for flat polys (who does?), but now i know to make sure to DISABLE it, when rendering without textures.

And another thing: Can anyone tell me, what dithering is good for? I could not find any translation for that word, and i could not find any description, what effect dithering gives, when it is enabled (except for some speed penalty).

BTW: I am running on WinXP, a GF Ti 4200 and the 44.03 drivers.

Thanks,
Jan.

dithering is enabled by default, basically if you’re running at less than 24/32 bit rgba a (computationally) cheap ordered dither is applied to the framebuffer (which is still quite effective).

edit: think grainy gifs… if you’re running at high enough resolution, pixels of slightly different colours blend to approximate the true (intended) colour. fairly effective in 16 bit colour - and cheap, since the dither pattern only depends on a given pixel’s position in the framebuffer (as far as i can remember from the gl spec).

on my “jesus woz ere” gf2 pro/gts the cost of enabling it is tiny as far as i can remember…

[This message has been edited by mattc (edited 07-31-2003).]

So dithering smooths the colors in a post-process a bit?

Originally posted by Jan2000:
Can anyone tell me, what dithering is good for?

Personally, I find the concept of dithering best explained with some images. Found this, which is basic enough: http://www.webstyleguide.com/graphics/dither.html

Could it be, that alphatest works only for free, when texturing is enabled?

Yes. Well, not exactly, but close enough.

The idea is ths. Basic glTexEnv fragment processing for 0 or 1 texture takes 1 cycle. Now, texture accessing/filtering takes 1 cycle. You can’t do fragment processing until you have the texture (the way nVidia does it on the GeForce 4’s, anyway), so the total time is 2 cycles.

Now, post-fragment effects (alpha test, blending, etc) take some amount of time. However, if the fragment processing takes 3 cycles, and the post-fragment effects take 1, then the entire process only takes 3 cycles, because the process is pipelined.

Given that, if you do single texturing, you’re taking 2 cycles per fragment. If normal post-fragment (no alpha test) operations only take 1 cycle (and it can’t take less), then the total time is only 2 cycles. If you take away the texture access, then the total time is only 1 cycle.

But, if you make the post-fragment processing take 2 cycels (add an alpha test, for example), then you’re guarenteed that the overall process will take at least 2 cycles.

What you’re seeing is that, given single texturing and one tex-env combiner, your total per-pixel processing time is no less than 2 cycles. So, if you change your post-fragment ops to take 2 cycles, you won’t notice a different; it is essentially free. If you speed up your fragment processing (drop the texture access), then you’ll notice the speed difference, because the limitting factor in speed is now the post-fragment operations.

So, yes, what you’re seeing makes total sense.

Thanks to all of you.
Now i understand the slowdown, and now i know what difference to look for when dithering is enabled. Have to test that dithering stuff someday and test how big the quality improvement is.
Well, for now, i still have flat-shaded polys but that will change soon!

Thanks again,
Jan.

Well those dithering examples are terribly misleading, although the text is better. It shows high quality vs dithered low quality, but dithering infact improves a low quality and uses the SAME number of bits to show better quality by trying to reconstruct the mid tones of the original high quality image. So to fully understand dithering instead of going Full Quality -> Low Quality, any explanation should show Full Quality -> Low Quality No Dither -> Low Quality With Dither

Looking at just the images you’d think dithering was a bad thing, but it is infact a GOOD THING most of the time, it’s the lack of precision that’s the bad thing that dithering tries to improve upon.

This is an important distinction for OpenGL because it’s not like web rendering (which always uses dithering when going to fewer bits). OpenGL always has the same number of bits whether or not you dither, so disabling it will show banding, enabling it will eliminate banding but show high frequency dither noise. It will not be like 24 bit RGB vs 8 bit dithered RGB. It’ll be more like 8 bit non dithered vs 8 bit dithered (# bits will vary with implementation 8 bit is LOW).

[This message has been edited by dorbie (edited 08-01-2003).]

Yes, my first impression was “that looks terrible”.
But then i read the text and understood that those “terrible looking” images used a much lower precision.
But is it still possible to use dithering with a 32/24 bit color-buffer? Or is it only possible when using 16 or 8 bit?

Jan.

Older anecdotal evidence suggests that dithering would only be active in 16 bit color, regardless of you glEnable-ing it or not. But Gf2MX vs Radeon 1 days was the last time I actually checked.

Dunno how modern hw handles this.

Yes this is possible, however there’s nothing stopping you dithering 24 bit images provided you have higher precision going in from somewhere. You might have to look very closely to see it or even do some image processing.

High end SGI systems used to do this (Reality Engine 2 class systems), I forget the details though it’s been a while. It can help avoid banding in your darkest shadowed areas especially when you crank up gamma correction.

Just switch to 16 bpp, render something Gouraud shaded with dithering enabled and look closely with a zoom tool.
You will see an ordered dither pattern, looks similar to a checkered pattern with two nearby colors, which is invisble to the human eye at a distance.
Do the same with dithering disabled and see some color banding instead.