Results 1 to 7 of 7

Thread: Color Masking

  1. #1
    Senior Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Color Masking

    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!

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Color Masking

    no.
    You can use both alpha test(reduce fillrate needs) and alpha blend (smooth edges).

  3. #3
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Color Masking

    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)

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Color Masking

    *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.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Re: Color Masking

    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).

  6. #6
    Senior Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Re: Color Masking

    ...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!

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Color Masking

    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?

Similar Threads

  1. color masking a glTexSubImage2D call
    By mh104 in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-04-2009, 02:09 PM
  2. Transparency/color masking blending help!!
    By RS543 in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 04-06-2009, 08:20 PM
  3. Color masking/changing of textures
    By jfern in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-02-2007, 06:12 AM
  4. Masking to show player color....problem please help
    By glBomb in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-28-2006, 01:24 AM
  5. Clearing and masking color attachments using FBOs and DBs
    By gamefreedom in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 05-29-2006, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean