Sign in to follow this  
benryves

[MDX] Masking out a ceiling as sky..? (See picture)

Recommended Posts

I'm learning Managed DirectX programming, and my test project is a DOOM level loader/renderer:
As you can see, there's part of the level visible in the sky that shouldn't be (click for a bigger version). The brown wooden bits. DOOM would normally roof over the sky sector with a special texture. My engine detects that, and doesn't draw anything there so you can see the sky cylinder. I need to draw something there - a sort of mask - that will let the sky show through but also act against the z-buffer and block out the wooden walls that shouldn't be there. I hope this makes sense - I don't know if this is a common technique/requirements, and if so what the technical name is so I can research it.

Share this post


Link to post
Share on other sites
I couldn't quite understand the part where you said your engine skips drawing the ceiling. Is there geometry there you "manually" skip drawing, since you don't want to draw the ceiling.

If you do have geometry for the ceiling, but want the skybox/cylinder drawn instead, you could use the stencil buffer to mask out the area you want to draw the skybox in. This would require drawing the ceiling geometry first, and then afterwards drawing the skybox/cylinder and testing against the stencil buffer.

I must add, however, that some of the older type hardware (like my FX5200) really doesn't do stencil operations that quickly, so you'd want to perform as little as possible using the stencil buffer.

Since I'm not sure all that was clear enough, here's a simplified explaination:

0) Add the Stencil flag to the clear operation, to make sure it is getting clearer.
1) Draw all geometry normally like you do, skipping the ceiling.
2) Draw the ceiling geometry, with stencil writting enabled, and the Z-pass operation set to Increment.
3) Draw the sky box. Set a stencil condition of >0.

Hope this helps :).

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
I couldn't quite understand the part where you said your engine skips drawing the ceiling. Is there geometry there you "manually" skip drawing, since you don't want to draw the ceiling.
DOOM breaks up levels into sectors. A sector that has a floor or ceiling set to a particular texture (SKY_1) has a sky drawn on it without being mapped onto the polygon. When I split the sectors into polygons, if I see that it has this special texture I skip over it, and it's never added to the level's geometry.
So;
Quote:
If you do have geometry for the ceiling, ...
- I do. Currently, though, I ignore it (it gets split up, but isn't added to a vertex buffer like the rest of the floors/ceilings).

The stencil method sounds perfect, thanks a lot [smile]

Share this post


Link to post
Share on other sites

So you have the geometry for the sky area. Why not render that geometry with the sky texture and some special texture coordinate generation ? No need to bother with stencil operations.

Share this post


Link to post
Share on other sites
Quote:
Original post by Demus79

So you have the geometry for the sky area. Why not render that geometry with the sky texture and some special texture coordinate generation ? No need to bother with stencil operations.
It's a thought, but then I'd need to adjust the vertex buffer every time I moved. The stencil buffer solution sounds a little simpler.

Share this post


Link to post
Share on other sites
T2k pointed out another solution (in #gamedev) that seems even easier;
  1. Clear colour and z-buffer.
  2. Disable z-buffer writes, draw the sky.
  3. Enable z-buffer writes, disable colour buffer writes.
  4. Draw all the ceilings that correspond to areas of "sky".
  5. Switch colour buffer writes back on.
  6. Draw all the rest of the walls and (solid) floors and ceilings.

Share this post


Link to post
Share on other sites

Quote:

t's a thought, but then I'd need to adjust the vertex buffer every time I moved. The stencil buffer solution sounds a little simpler.


What if you used a vertex shader to calculate the texture coordinates ? As far as I can see it should be quite simple to calculate the coordinates.

Just a thought

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this