Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Here's what I'd like to achieve:

  1. Rendering a first pass of objects in my scene, using standard depth comparison
  2. Rendering another pass of objects in the same scene, but with the following rules:
    • A Pixel of the 2nd pass always override the first pass (no depth compare between them)
    • Use Depth comparison between pixels written from the second pass.

In English I want depth comparison made inside each pass but I always want the second pass pixels to override the first pass ones.

Some things I've thought:

  • I tried to think about using stencil to solve this, but I couldn't find a way.
  • I know I could render into a separate target the second pass then composite the result into the first, but I'd like to avoid that.
  • I could use two separate Depth Buffer, one dedicated to each pass. (I never tried, but I figure it's possible to switch the depth buffer in a Render Target "on the fly")

Any idea of the best solution?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

You could draw the first pass, then clear the depth buffer and draw the second pass. (Assuming you don't need depth values from the first pass at any point later in your pipeline.)

share|improve this answer
    
Ok, this is not totally what I wanted to do, but it makes sense to go that way. I may have to shuffle some rendering, but clearing the depth buffer is the best way. I could also go for two Depth Buffers I tested it and it works great! Anyway, thank you for your answer! –  Nock Jun 11 '12 at 18:26
add comment

Another way of doing this is to partition your depth range using two viewports - the first viewport has depth range 0 to 0.5 and the second has depth range 0.5 to 1, but otherwise they are identical. Your "first pass" would therefore go into the second viewport, and your "second pass" into the first.

That would have the advantage of enabling you to draw your objects in a more-or-less order-independent manner, but at the tradeoff of reduced depth buffer precision. Depending on the rest of your program's requirements this may or may not be a big deal.

share|improve this answer
    
Yes, I thought about this one, but I'm not ready to give up precious depth range for this feature! :) –  Nock Jun 11 '12 at 16:28
    
Nathan Reed's answer is probably the best way then. –  Jimmy Shelter Jun 11 '12 at 16:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.