Results 1 to 9 of 9

Thread: Z-buffer

  1. #1
    Member Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    55

    Z-buffer

    I've made a program wich uses reflexion with the stencil buffer, and it works very well. But I've a question to make it work better.
    First I explain what I do : i draw the scene to be reflected, then i draw the mirror with stencil writing, i scale(1,-1,1), blend, invert culling, and then redraw the scene with a stencil test. Since I want to draw many objects in the scene, I have to use the z-buffer again. So i clear it after drawing the mirror, and it works perfectly, because where the reflected scene is hide, stencil is 0. But i was wondering if there was another way than clearing depth-buffer. I mean, can i draw the mirror with the depth test but without writing into the z-buffer ? And will it go faster with this method rather than with mine ?
    thx
    Antoche

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Z-buffer

    There is a way to do this without clearing the z-buffer. First you draw the reflection(s), then the floor (with blending), and then you draw the object(s) to be reflected... No problems with cleaning the z-buffer.

    And to answer another of your questions. You can disable z-buffer with glDepthMask(GL_FALSE | GL_TRUE). GL_FALSE disable z-buffer updates (still doing z-buffer tests), and GL_TRUE enables i again.

    Bob

  3. #3
    Member Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    55

    Re: Z-buffer

    But in your technique, I can't know where to draw the reflection. I mean, the reflection needs to be drawn only in the mirror and not elsewhere. If I draw the reflection first, and if for example a part of the reflection is outside the mirror, it will be drawn entirely whereas it didn't need to. And if i draw the mirror first to know where not to draw the reflection, the mirror will hide the reflection with th depth test.
    Do you understand what I want to say (my english is very poor) ?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Z-buffer

    Yes, I know what you mean, and I forgot about it.

    1: disable updates to z- and frame-buffer
    2: draw mirror to stencil buffer
    3: enable updates to z- and frame-buffer
    4: draw reflections
    5: draw mirror
    6: draw objects

    Hope this is correct...

    You disable updates to buffers with commands similar to the one i mentioned above.

    Bob

    [This message has been edited by Bob (edited 02-24-2000).]

  5. #5
    Member Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    55

    Re: Z-buffer

    OK, now I understand. But your technique is not as god as mine because you've to draw twice the mirror while I draw it only once
    Antoche

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Z-buffer

    Not as good as mine? Heh, depends on how you look at it, I don't have to clear my depthbuffer

    You have to remember one thing, you are clearing your depthbuffer in the middle of the scene, and that may cause problems later. What if you want to draw something behind the object to be reflected AFTER you drawn the reflections? This is where you get problems, you just cleared your depthbuffer and there is NO WAY OpenGL knows there is something "in front" of what you are drawing.

    If you use my technique, you can atleast save th depthbuffer.

    Remember: reflections make a scene more realistic, and if you want to make it more realistic, you have to offer something else, speed in this case.

    I'm not saying your technique is bad, if this is all you need, then there is no problems with what you are doing. But if you want to draw some more objects, it might be nice with an untouched dephbuffer.

    Bob

    [This message has been edited by Bob (edited 02-25-2000).]

  7. #7
    Member Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    55

    Re: Z-buffer

    Yeah, but if I use glDepthMask() instead of clearing z-buffer, I only draw the mirror once, and if it's hide, it will go faster because stencil will be blank, whereas you draw all the reflection even if there is something hiding the mirror.

    Antoche

  8. #8
    Junior Member Newbie
    Join Date
    Feb 2000
    Posts
    1

    Re: Z-buffer

    Duh... just start recursing the database from furthest to nearest "node", drawing portals as you go. When you are recursing to closer node, just draw the portal ( write only to depth+stencil buffer ).

    This way the depth buffer is updated with the portal polygon's "shape", and depth as it it located in the node we are about to draw next.

    The stencil refvalue should start from 0x0, and increase every time you recurse ( ++refvalue ). This way you do not have to CLEAR the stencil, just draw the portal polygon with depth+stencil.

    PROS:
    * don't have to clear at each recursion, which is good for the fillrate

    CONS:
    * cannot recurse more than 256 times with 8bit stencil ( heck, this should be plenty

    COMMENTS:
    * If you use stencils for fx, then the clearing should be done, ofcourse.


    Cheers,
    Jukka / T3D

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Z-buffer

    Well, we can keep on tossing comments back and forth for ages...
    There are several ways of doing reflections, and all techniques has it's own pros and cons. Just test what technique that works best for you, then use it.

    By the way, jukka3d... Don't you have to sort all objects/polygons if you want to draw them from back to front? And as far as I know, sorting is not too fast when sorting loads of stuff

    Bob

Similar Threads

  1. Alpha blending issues, when drawing frame buffer into default buffer.
    By Goran Milovanovic in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-08-2015, 08:11 AM
  2. Replies: 5
    Last Post: 09-09-2014, 04:06 PM
  3. Corrupted data during mapped buffer! (Uniform Buffer Objects)
    By FrankBoltzmann in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-24-2014, 03:15 AM
  4. Replies: 6
    Last Post: 01-16-2006, 11:27 PM
  5. Depth buffer and stencil buffer / Alpha test
    By greg2 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-05-2004, 01:50 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