Rasterization, my way.

Started by Obsyd, May 09, 2012, 15:30:33

Previous topic - Next topic

Obsyd

Hello there!
I'm trying to tell opengl to not rasterize a few pixels. I have been looking around for a while on the net, but I can't seem to find a simple way to do what I would like.
I'm rendering a textured quad that has ~50% transparent pixels (pic). The better way would be to render 2 triangles so opengl won't do anything with the transparent pixels. I tried it with 2 triangles but the performance got worse.  ???
So I'm looking for a way to "mask"(not even rasterize) the transparent area of my quad.

Stencil buffers might help me in my problem, but I'm not sure.. :(
(Got like 2000 quads in a VBO)

The pink area represents the transparent area. (the texture is GL_BGRA)

Thank you!  :)

spasi

You need to use alpha test (see GL_ALPHA_TEST and glAlphaFunc).

Obsyd

Thanks spasi!

It works! I'm probably lookin for something that is not so trivial. :(

This glAlphaFunc(GL_GREATER, 0.1f); gives me the same performance as glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);.
And when I turn off GL_BLEND or glAlphaFunc (I'm not using them both at the same time) I get the same performance.
So my performance is the same with and without working with transparent pixels.

I thought that I can somehow get better performance when I tell opengl that it should not do anything with the transparent pixels.
It looks like that the cost of doing this is the same as rasterizing the whole quad.

Or :)
I'm doing something really wrong... :)

spasi

Alpha test does provide a performance benefit, but it depends on the rendered scene's complexity and the shading cost of the discarded fragments. There are also situations that will not let the GPU perform an early alpha test (that is, discard the fragment before the fragment shader is executed), but that's a bit rare.