Archived

This topic is now archived and is closed to further replies.

Infinite view distance?

This topic is 5310 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''m trying to set up rendering a planet, and although I''ve toyed with the far clipping distance, I know there are tie-ins to the z-buffer - I remember reading that the ratio of near-to-far clipping distance should remain as close to 1 as possible(?). Since I control all the data in my vertex buffers pretty tightly, I''m wondering if it''s possible to do without a far clipping plane / set it so far in the distance as to not to clip anything. The frustum culling code was dropped in, so I''m largely unfamiliar with it and just looking for some insight. Any easy answers? The function I''m glaring at is: m_pDevice->SetTransform( D3DTS_PROJECTION, &mat ); where ''mat'' is the projection matrix. What issues might I encounter setting far clipping distance to 25000 instead of 40?

Share this post


Link to post
Share on other sites
I don''t know if there are any really nitty-gritty side-effects from having a really big far clip plane, but if you already employ frustrum culling (which will include the far clip plane, unless you create another one in the culling code) I don''t think you''ll have any problems. As far as I know, the only reason to have a smaller far clip plane is to limit the number of polys that are drawn every frame. The fewer polys in your scene, the more the far clip plane becomes irrelevant.

Ryan Buhr
Reactor Interactive, LLC.
www.reactorinteractive.net

Share this post


Link to post
Share on other sites
You can create PROJECTION-VIEW by use D3DXMatrixPerspectiveFovLH function.

D3DXMATRIX* D3DXMatrixPerspectiveFovLH(
D3DXMATRIX* pOut,
FLOAT fovy,
FLOAT Aspect,
FLOAT zn,
FLOAT zf
);

zn
[in] Z-value of the near view-plane.
zf
[in] Z-value of the far view-plane.

Share this post


Link to post
Share on other sites
There is a significant problem with far clip planes in your projection matrix - z-fighting. As your far clip plane gets urther away those 16/24/32 bits of z-buffer accuracy are stretched and you will find visual artifacts around objects which are close (along the z-plane).

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites
to create the appearance of infinite view, you can set the far clip and near clip to the extents of the object. say you have a bounding radius for culling on all your objects, set the near clip plane to the objects position''s distance from the camera minus the radius, and + the radius for the far clip plane. you can''t rely on the z buffer this way though. the other option is to set the extents to ''zones''. so you could set the view distance to in front of and behind the planet, and things like that.

Share this post


Link to post
Share on other sites
1) The near and far clip plane values in the projection matrix are used to scale Z values into the 0.0 to 1.0 range - this range is what ends up in the Z buffer. The planes also (obviously) define the clip volume. You need near and far clip planes for this scaling to take place (i.e. for the Z buffer to work at all)


2) Because the Z values in the Z buffer are *after* projection, the relationship between Z values in world space and in the Z buffer is non-linear. The average is something like 20:80 (the first 20% of the buffer has 80% of the precision). i.e. stuff near the camera gets the least Z fighting, stuff in the distance gets the most.


3) The greater the distance between near and far, the more that 0 to 1 range gets spread across the precision of the Z buffer. A 16 bit (integer) Z buffer can only only store 65536 discrete values. The more of a spread you have, the more Z fighting you get.
e.g. if you''re trying to spread the range over 100 miles of infinitely viewable stuff, but still wanting to see blades of grass near the viewer, then an object that is say 10miles and 10 metres might have the same values in the Z buffer as one that is 10 miles and 15 metres away [sorry for mixing Imperial & Metric ]


4) The higher (further away from the viewer) you set your near clip plane, the more linear the relationship between world space and projection space Z is. So set your near plane to as high a value as you can bear.


5) An idea.
a. Set your clip planes to what the viewer can see in the near(ish) ground (i.e. nice, Z buffer friendly values with the near plane as far as possible for the near stuff). Say a 1Km range (or whatever is more suitable for your needs).

b. Imagine looking in the direction of the camera in world space, the first 1Km is what''s in the range mentioned above. Past that first 1Km range is another 1Km range, and another, and another etc. Call each 1Km range in the direction of the camera a "zone". Only the first "zone" is currently visible, the rest would be clipped off.

c. Even with an "infinite" view range, you''ll be performing some amount of LOD and object culling (if you''re not, then you''re mad - computers are finite). This is likely to be based on the distance along the view direction.

d. When doing your culling/LOD, batch geometry up into the 1Km "zones" mentioned above, so all the geometry between 4 and 5 Km for example is grouped together.

e. Visit the zones, in order, from the farthest to the nearest and set the projection matrix for that zone with the clip planes defining that zone. i.e. you just add the zone offset to the near and far clip planes.

f. For the really far away zones, disable Z buffer writes and manually Z sort the objects in the zone - they''ll probably just be dots on the screen anyway, and the LOD should have chopped their poly counts down.

g. For the nearer zones that are still >1Km, clear the Z buffer and render the contents of that zone to a texture. Repeat for all nearer zones. The render target textures for the far away zones can get progressively smaller since their detail is less and less noticable.

h. Set the near and far values of the projection to your nearest 1Km, then apply each of the "zone" textures to billboards positioned at the far clip plane that have been suitably scaled to represent the offset of the zone they represent. Finally render the stuff in the nearest zone as normal.


I''ve left out a few details there, and there are other variations - but I''ll leave those as an exercise for the reader


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Here's a good suggestion: Remember that convex objects like a sphere are rendered perfectly correctly without any depth-buffering at all, as long as directional culling (clockwise or counterclockwise) is enabled (which of course I trust it is). This is important to you since you're rendering a planet -- what it means is you can render the very distant parts of the planet as just a flat sphere, no mountains or valleys. Then you can have depth-buffering disabled for that, and only use it for the nearer areas with mountains and other details.

~CGameProgrammer( );



[edited by - CGameProgrammer on June 5, 2003 9:26:15 AM]

Share this post


Link to post
Share on other sites