PDA

View Full Version : Color Masking



Rodrix
10-03-2006, 07:14 AM
Hi there!
I am now working on my grass.
I got some textures with black backgruound and I want opengl to drop the black pixels.

I tried converting the black pixels to an alpha channel and then applying blending but that gets too expensive (my FPS go down considerably). Alpha test produces horrible results.

Is there another way to drop the black pixels without using blending?

Thanks in advance! :)

ZbuffeR
10-03-2006, 07:50 AM
no.
You can use both alpha test(reduce fillrate needs) and alpha blend (smooth edges).

k_szczech
10-03-2006, 08:18 AM
Alpha test produces horrible results.Actually most grass implementations I've seen use alpha test only. So if you get bad results, then there is something wrong with your texture (I strongly suggest not to represent transparent pixels as some special color like black - create RGBA textures directly in graphics program and save to some format that supports RGBA, like .png)

zeoverlord
10-03-2006, 08:47 AM
*begin mini rant*
Or .tga, Surrounding pixels always affect other pixels when using any type of blending, so if you are doing grass then the surrounding pixels should be whatever color the grass is, in fact it should be hard to see the boarder between grass and non grass unless you look at the alpha map, which should in it self never contain any hard edges.

Unless you have a few spare cores on idle and can sort all the grass in the world in real time, one should always use alpha testing to draw all the grass and such, and then use some blur or supersampling filter on it to remove all/most the artifacts created by alphatesting.
It is definitely easier to render grass into a fbo that has from the beginning been colored green (or whatever is the main color of the vegitation) and then use alpha blending to merge it with the original rendering.
*end mini rant*

And btw this will also be in one of the new upcoming NeHe lessons, teaching blending to beginners, wonder why no one ever thought of that before.

Rodrix
10-03-2006, 05:23 PM
Thanks guys!
Your answers were really useful! :)

What alpha test func do you consider healthy?
I am using GREATER 0.5.

Making this value higher, produces a more frame-rate limited result, right?

Thanks!
Cheers! :)
Rod

P.S: Yes... that tutorial is definitely missing!. Most begginers learn about blending and alpha test *after* realizing that nothing works as they wanted!!! haha
P.S 2: Any one know of were to get some nice grass textures with alpha background!? I found some wonderful plants and grasses but all textures contain black background and changing black to alpha doesn't look as good (no mask provided).
Here is the link I found :http://www.loopix-project.com/
(Click on Freebies).

Rodrix
10-03-2006, 05:33 PM
...Wait!!!

How is it that the users use these files with black background!? I've seen these files with black background used by other engines too...

Can I drop the black pixels using alpha test and telling OpenGL to consider RGB(0,0,0) as alpha channel!?
(That would mean no extra Photoshop work and pixel borders correction)

Thanks!

zeoverlord
10-04-2006, 08:19 AM
It depends on how you use it, if you use mipmapping the black pixels would inevitably start to blend together with the visible ones at a certain distance, however, many don't use blending like that on grass or other sprites, and those who do know about this.
There is a nice chapter about it in GPU gems 2.

About dropping black pixels, yes it's possible if you do it at load time, but the pixels would still be black, alpha is a separate color channel not a replacement for the other color channels, fixing it in photoshop is still the simplest solution.

Regarding the lessons, blending and alpha testing will be lesson 07-08, is that early enough?