Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: How to render without flickering?

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2003
    Posts
    12

    How to render without flickering?

    Hi,

    I have a boulevard walkthrough with trees at the sides of the boulevard. The trees consist very small leaves on their branches.

    I want to create a movie of the boulevard, but far tree leaves flicker very frequeny!
    Using mipmaps is out of the question to me, because it creates a halo around the leaf texture (because the trasparent texels are blended with the leaf texels).
    In addition the mipmaps magnify the leaves size when looking from not near distance.

    The reason for the flickering is the z-buffer, which has 24 bits (This is the maximum I have succeeded to get).

    In order to solve the problem I have decided to render my scene as follows:

    I splitted my frustum into very small sub frustums and rendered to each one of the frustums from back to front and accumulated the color buffer.

    Code :
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
     
      for(int = i; i < numOfFrustum; ++i)
      {
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        setFrustum(subFrustum[i]);
        renderScene();
        glClear(GL_DEPTH_BUFFER_BIT);
      }

    no matter how small how make my sub frustums the tree leaves don't stop to flicker.

    How can I stop the flickering without using mipmaps???
    (about sorting the leaves from back to front, it seems hard to me , as each tree consists dozens of thousands of leaves)

    Thanks,

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jan 2004
    Location
    .dk
    Posts
    123

    Re: How to render without flickering?

    Maybe the solution is to use mipmaps, but remove the artifacts due to mipmapping. A way to do this is the use the euclidian distance transform (if you don't know it, look it up, it's rather simple) - to preprocess the textures for use with mipmapping.

    If you're sure about the problem being the z-buffer, mipmaps won't help. Are you using a "linear" or "nearest" min-filter? Linear is better.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: How to render without flickering?

    I render trees the same way and far away trees do not flicker, no tree is flickering at all So you must be doing something wrong.

    Do you use alpha test? This could remove the "halo".

    Jan

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: How to render without flickering?

    The problem is likely that the tree leaves sit on a texture surrounded by non-leaf color, which causes halos when filtering. Make all of the texture greenish (leaf color), even where it is transparent, and MIP mapping will work fine.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2012
    Location
    175064460
    Posts
    1

    Re: How to render without flickering?

    Perhaps you should consider "baking" the tree leaves - i.e. pre-render them into a new bitmap and use that for your animation.

    Using the pre-baked image with mipmapping may produce a better result for far trees also.

  6. #6
    Member Regular Contributor remdul's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands
    Posts
    335

    Re: How to render without flickering?

    Assuming the flicker you see is actually 'shimmer' (or 'jitter') of the tree leaf textures, the proper way to solve this is to enable mipmapping. At any rate, it has little to do with z-buffer (and z-fighting as you suggested).

    Enabling anisotropic filtering should reduce the 'halo' effect with mipmapping you describingd. See http://www.opengl.org/wiki/Texture#A...opic_filtering .

    Also ensure that the leaf textures have clean alpha-edges, and if possible non-tiling (change GL_WRAP to GL_CLAMP_TO_EDGE). Mipmapping can sometimes cause pixels outside the polygon boundaries to spill inwards, producing the halo you describe. Typically, try to keep at ~8 pixels clear of the image borders.

    Play with the alpha-test reference value (glAlphaFunc) to see if that prevents the leafs from becoming invisible or, conversely, to thick.

    Balancing out the average alpha value of the texture may also work for you (i.e. if you scale down the image in PhotoShop down to 1x1 pixels, the alpha channel value should be '127', mid-gray).

    Also, what Jon Watte mentioned above. If you use color-keying to produce the alpha channel, certainly replace the mask color. The average of the color channel (minus mask color of course) should be sufficient in most cases. Avoid pre-multiplied alpha.

    Also, as Mikkel Gjoel suggested, distance textures may produce cleaner alpha-tested edges (see: http://www.valvesoftware.com/publica...nification.pdf ). I tried this for vegetation, and the improvement wasn't as noticable as I expected. It seems to work better with more refined shapes such as glyphs. So YMMV.

    I've had much luck with alpha-to-coverage transparancy. This requires enabling multisampling however, though will as side effect also improve your image quality in other areas. See http://www.opengl.org/wiki/Multisampling . Tip: with alpha-to-coverage transparancy you may need to scale the alpha 2x. You can do that in your GLSL shader, or if you use FFP, tweak the alpha test reference value (glAlphaFunc).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •