LWJGL Forum

Programming => OpenGL => Topic started by: Obsyd on May 09, 2012, 15:30:33

Title: Rasterization, my way.
Post by: Obsyd on May 09, 2012, 15:30:33
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!  :)
Title: Re: Rasterization, my way.
Post by: spasi on May 09, 2012, 15:44:59
You need to use alpha test (see GL_ALPHA_TEST and glAlphaFunc).
Title: Re: Rasterization, my way.
Post by: Obsyd on May 09, 2012, 16:21:37
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... :)
Title: Re: Rasterization, my way.
Post by: spasi on May 09, 2012, 16:36:11
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.