Could depth value be greater than 1?
In D3D HLSL, we could output the depth value into depth register in Pixel Shader directly. But it request the value should be between 0 and 1.
If I want to set depth to 开发者_如何学Gobe greater than 1 how can I do that?
24 bits for storing the depth value is too limited for my very large scene graph.
You can output a value outside of [0,1], but it will be clamped to the [0,1] range before being used in the depth test (if enabled) and before being written to the depth target. This is true for both Z16/Z24 formats (which can't even represent values outside [0,1]) and for the Z32F format.
Why is 24 bits too limited -- do you need a larger range or do you need more precision?
Your question suggests that you need a larger range than [0,1], but your scene graph can use any range you want as long as the vertex shader maps that range to [0,1] (this range mapping usually happens in the model/view/projection transforms).
If you need more precision, you can't get that natively: the 32-bit floats used throughout the API and hardware only have 23 mantissa bits, and the implicit leading 1 effectively gives you 24 bits of precision. To deal with this, the typical solution is to chop the world up into segments (e.g. a grid), and store object positions relative to the segment they're in. When an object moves from one segment to another, you translate its position to be relative to the new segment. When rendering use the segment containing the camera as (0,0,0) and map the segments that fall within the view frustum to the [0,1] depth range.
精彩评论