Jump to content
  • Advertisement
Sign in to follow this  
RobMaddison

Terrain 'holes'

This topic is 2102 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Afternoon all, hope you're all having a great day.

I'm at work but my mind is wandering onto my game engine.

I was wondering about the Z buffer. Is it possible to reset a pixel's depth in the depth buffer mid-scene? So if I wanted to draw arbitrary holes in my terrain, could I draw my terrain with z buffer enabled, then switch it off, draw something that is 'under' the terrain and draw perhaps the walls of the hole with the z buffer back on?

Think of a hole on a golf putting green. I draw the green (minus hole), switch off the z buffer, draw an ellipse under the terrain, switch z buffer back on and then draw the sides of the hole.

Is this possible? Or is there a better way? The shapes I want to cut out of the terrain are going to be arbitrary so I can't really substitute a terrain triangle for one with a hole model in it.

Thanks

Share this post


Link to post
Share on other sites
Advertisement


Think of a hole on a golf putting green. I draw the green (minus hole), switch off the z buffer, draw an ellipse under the terrain, switch z buffer back on and then draw the sides of the hole.

Is this possible?
In theory: yes.

In practice: no.

I spent quite some effort on that. I used to go with a "hole map" which would discard terrain fragments on alpha test. Nowadays, it would probably be a distance map. Problem is it is very hard to get the intersections right and unless the geometry is completely "embeddeding" the boundary there will be gaps. Most of the time, they're not very noticeable but I grew confident the only way to deal with them was a proper geometry manipulation.

Share this post


Link to post
Share on other sites

You can do a similar thing without a stencil buffer too. Get your artists to make two parts to the golf hole, the hole geometry itself, and a cap (geometry that would represent the lid of the hole). Then when it's time to render you do:

 

- Render the normal golf hole geometry.

- Render the golf hole 'cap' geometry with z-write on and a little z-bias. Use a frame buffer mask or blend mode or something to avoid writing anything to the frame buffer.

- Render the terrain normally, it will now leave a hole

Share this post


Link to post
Share on other sites

You can do a similar thing without a stencil buffer too. Get your artists to make two parts to the golf hole, the hole geometry itself, and a cap (geometry that would represent the lid of the hole). Then when it's time to render you do:

 

- Render the normal golf hole geometry.

- Render the golf hole 'cap' geometry with z-write on and a little z-bias. Use a frame buffer mask or blend mode or something to avoid writing anything to the frame buffer.

- Render the terrain normally, it will now leave a hole

This sounds like a good idea at first, but you'd have to make a cap that stands out of the terrain, to avoid z-fighting between the cap and terrain, but if the cap is above the terrain, that will cause the hole to be shaped like the cap along the view direction, which would cause problems if the camera is (extremely?) close to the ground - getting a cap shape that wouldn't cause z-fighting and wouldn't be noticeable sounds tricky. If the hole is on top of a high, narrow hill, and the camera is looking at it from below, the cap would cut a whole into the sky, or whatever else is behind there.

Edited by tonemgub

Share this post


Link to post
Share on other sites

You can do a similar thing without a stencil buffer too. Get your artists to make two parts to the golf hole, the hole geometry itself, and a cap (geometry that would represent the lid of the hole). Then when it's time to render you do: - Render the normal golf hole geometry.- Render the golf hole 'cap' geometry with z-write on and a little z-bias. Use a frame buffer mask or blend mode or something to avoid writing anything to the frame buffer.- Render the terrain normally, it will now leave a hole

This sounds like a good idea at first, but you'd have to make a cap that stands out of the terrain, to avoid z-fighting between the cap and terrain, but if the cap is above the terrain, that will cause the hole to be shaped like the cap along the view direction, which would cause problems if the camera is (extremely?) close to the ground - getting a cap shape that wouldn't cause z-fighting and wouldn't be noticeable sounds tricky. If the hole is on top of a high, narrow hill, and the camera is looking at it from below, the cap would cut a whole into the sky, or whatever else is behind there.

C0lumbo's idea was pretty much was I was thinking you could do with the zenable on/off thing, but it would still work I think. He mentioned adding a little zbias (which I assume means initially drawing the hole 'cap' with zenable on and colour off but very slightly closer to the camera in screen space z (meaning the hole's silhouette would be identical wherever along the screen space z axis you draw it). That would place the cap in the zbuffer slightly closer and when you draw the terrain, it should leave a hole.

Is that about right, C0lumbo?

So the order would be, sides of hole first (zenable on and colour on), cap of hole (zenable on, colour off, adjust final z coord), terrain with normal state

Share this post


Link to post
Share on other sites

If the hole is on top of a high, narrow hill, and the camera is looking at it from below, the cap would cut a whole into the sky, or whatever else is behind there.

If the hole is on top of a high, narrow hill, and the camera is looking at it from below, the cap would cut a whole into the sky, or whatever else is behind there.


The cap in this example would be facing away from the viewer wouldn't it? Meaning it'll get discarded anyway

Share this post


Link to post
Share on other sites
The cap in this example would be facing away from the viewer wouldn't it? Meaning it'll get discarded anyway

I guess you're imagining the cap to be a disc parallel to the ground, while I'm imagining it to be a speherical or cylindrical shape (or whatever sahpe he wants), with only a small part protruding above the ground? The part of the sphere that protrudes from the top of the hill would still be visible. But It think even with a disc shape and back-face clipping, you'd have problems placing it on the ground so as to avoid z-fighting - if you place it too far up from the ground, the hole will appear displaced, and the fact that it would disappear when looking at it from below wouldn't be a very nice-looking effect either. Maybe it can be fixed with depth-bias. Of course, this all depends on what requirements the op has related to the possible angle the hole can be seen at.

 

I'm also not sure how using the cap-model geometry for the hole fits in with the op's idea of "arbitrary".

 

So the order would be, sides of hole first (zenable on and colour on), cap of hole (zenable on, colour off, adjust final z coord), terrain with normal state

 

Yes, that would work. smile.png I thought you wanted to avoid using geometry... If you already have the sides of the hole as geometry, then it would be pretty hard to match the stencil to the shape of your geometry or vice-versa, so the cap ideea is better. You still have to align the sides of the hole geometry to the terrain - you'll get artifacts if they don't align properly?

Edited by tonemgub

Share this post


Link to post
Share on other sites

The cap in this example would be facing away from the viewer wouldn't it? Meaning it'll get discarded anyway

I guess you're imagining the cap to be a disc parallel to the ground, while I'm imagining it to be a speherical or cylindrical shape (or whatever sahpe he wants), with only a small part protruding above the ground? The part of the sphere that protrudes from the top of the hill would still be visible. But It think even with a disc shape and back-face clipping, you'd have problems placing it on the ground so as to avoid z-fighting - if you place it too far up from the ground, the hole will appear displaced, and the fact that it would disappear when looking at it from below wouldn't be a very nice-looking effect either. Maybe it can be fixed with depth-bias. Of course, this all depends on what requirements the op has related to the possible angle the hole can be seen at.
 
I'm also not sure how using the cap-model geometry for the hole fits in with the op's idea of "arbitrary".
 

So the order would be, sides of hole first (zenable on and colour on), cap of hole (zenable on, colour off, adjust final z coord), terrain with normal state

 
Yes, that would work. :) I thought you wanted to avoid using geometry... If you already have the sides of the hole as geometry, then it would be pretty hard to match the stencil to the shape of your geometry or vice-versa, so the cap ideea is better. You still have to align the sides of the hole geometry to the terrain - you'll get artifacts if they don't align properly?

No, I don't need to avoid using geometry, in fact that's the way I had it planned. I was wondering about the alignments, I'll just have to be careful with it I guess. The player won't be able to see the holes too closely so it should be fine and the 'holes' will actually be a thick trench cut out of the terrain. Thought a golf hole might have been easier to explain!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!