Sign in to follow this  

Viewport Depth Usage?

This topic is 2836 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

I've never really understood the depth parameter in a viewport. The width is used for converting from clip space x (-1,1) to viewport x (0,say 1024). The height is the same except for y. But the depth value for a viewport is specified as a float and is usually (0.0,1.0). But after projection the z/w value is already within(0.0,1.0), right? So what is the point of these values in the viewport? Why would anyone put something other than (0.0, 1.0). The DirectX SDK gives the example: "... to render a heads-up display in a game, you can set both values to 0.0 to force the system to render objects in a scene in the foreground, or you might set them both to 1.0 to render an object that should always be in the background" Unfortunately this example just makes me more confused. It kind of makes it sound like the viewport depth (min, max) is used in z buffer calculation. Is this true?

Share this post


Link to post
Share on other sites
Quote:
But the depth value for a viewport is specified as a float and is usually (0.0,1.0)

Could you tell what (D3DX I assume) function are you talking about?
Because at a low level part of the system, there's no "depth value" in a viewport matrix.

Quote:

The DirectX SDK gives the example: "... to render a heads-up display in a game, you can set both values to 0.0 to force the system to render objects in a scene in the foreground, or you might set them both to 1.0 to render an object that should always be in the background"

Could you tell the link? Quoting out of context just confuses more.

I'm confused at what you're being confused at. Unless you're clearer, it will be difficult to help you.

Cheers
Dark Sylinc

Share this post


Link to post
Share on other sites
Quote:
Could you tell what (D3DX I assume) function are you talking about?
I believe he's referring to the MinZ and MaxZ values of the D3DVIEWPORT9 struct (the OpenGL equivalent would be glDepthRange()).
Quote:
Could you tell the link? Quoting out of context just confuses more.
Here, about halfway down the page. (Another use for the 'depth range' trick, incidentally, is to force debug graphics to the front of the depth buffer. Quake 3, for example, uses this technique for rendering triangle normals and wireframe outlines.)

Share this post


Link to post
Share on other sites
jyk is correct. I apologize for not being more clear. Here is the entire paragraph out of the DXSDK which is the link jyk has given above.

Note: MinZ and MaxZ indicate the depth-ranges into which the scene will be rendered and are not used for clipping. Most applications will set these members to 0.0 and 1.0 to enable the system to render to the entire range of depth values in the depth buffer. In some cases, you can achieve special effects by using other depth ranges. For instance, to render a heads-up display in a game, you can set both values to 0.0 to force the system to render objects in a scene in the foreground, or you might set them both to 1.0 to render an object that should always be in the background.


So I guess my confusion comes how exactly this range (MinZ, MaxZ) affects the input of something being drawn. It says it's not used for clipping. Perhaps it's best described as an example:

Z test : true ( always pass )
Z write: true
Near plane: 1
Far plane: 100
Viewport MinZ : 0.50
Viewport MaxZ : 0.75

How will the following incoming z values (in camera space before projection) get applied with the above settings? Lets assume a linear Z buffer just for this example.

1
25
50
65
75
100


For example, does the minZ & maxZ just compress the input range to the viewport range ie. 1->0.5 & 100->0.75 ? And which value gets written to the depth buffer?

Share this post


Link to post
Share on other sites
I've never used this feature (I just tweak the vertex shader position), but judging from the documentation, and how the matrix is built and that it is applied to each vertex, I can only deduce the values are scaled, just like you've suggested 1->0.5 & 100->0.75 in your example (assuming linear depth)

Whether if values outside the range [0.5; 0.75] are clipped I'm not sure, but I strongly suspect they are.

Quote:
Why would anyone put something other than (0.0, 1.0)

Setting to 1.0, 1.0 puts all rendered objects in the background despite it's Z value. This is veeeeeery useful for rendering skyboxes last, which takes performance advantages of Early Z culling (usually half of the skybox is hidden by the terrain and other objects). Similar optimizations with Early Z culling for Pixel Shader or Fillrate intensive objects apply.

Using (0.0, 0.0) is useful for drawing some particle fxs, debug objects (like already pointed out) and GUIs. Usually games draw GUIs last with depth reading & writing disabled, but if this is not an option or there are special fxs that benefit from having actual depth buffer values (or there's a special interaction between GUIs & 3D objects, which is more complex than just using billboards) it can be useful.

Cheers
Dark Sylinc

Share this post


Link to post
Share on other sites

This topic is 2836 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.

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