using two diff. camera near distances

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
snowblind
Gnoblar
Posts: 14
Joined: Tue Jan 25, 2005 5:51 am

using two diff. camera near distances

Post by snowblind »

In a space scene there are objects you wish to draw that are far, far away.

If I have 1 game unit = 1 meter, for example, and then draw the Earth at it's actual scale, it makes worrying about in game scale easy--things are just equivalent to their real world counterparts.

Now where this causes trouble is with the z-buffer. Suppose there's a space dogfight a couple dozen miles up off the earth. With a near clip distance of 1 and an infinite far plane, there is obvious z-fighting out in the distance on the Earth--I understand this is because of how floating point values are stored internally--the greater your "range," the less precision you have.

This is validated by a little experiment. If I set the near clip distance to something like 100, the Earth-sphere is drawn perfectly at any visible distance. Perfect! Well, not quite. This means I can't see things up close!

The solutions to this problem, as I can see it:

Find a way to divide the scene into "close" objects and "far" objects. Set the camera's near distance to be 1 and then draw the close objects. Then set the camera's near distance to be a bigger value (100) and draw the far objects--planets, suns, nebulas. This has the advantage of a regular coordinate system without any kind of transforming nonsense.

The only issue would be detecting if the player has gotten close enough to an object for it suddenly to be considered "close." Also, I have no idea how I would go about doing this in Ogre, since I'm not sure how to draw chunks of the scene, set a camera value, then draw the rest of it. Does anyone have any suggestions?
Captain Nemo
Greenskin
Posts: 134
Joined: Sun May 02, 2004 5:06 pm
Location: Kassel, Germany

Post by Captain Nemo »

One thing I can think of is to modify the projection matrix in a vertex shader, depending on the distance to the camera. But I haven't tried this.
iq
Greenskin
Posts: 125
Joined: Mon Oct 20, 2003 8:25 pm

Post by iq »

you can use render queues and switch near planes/clear z-Buffer in a render queue listener. Implementation should be pretty straightforward as overlap, intersections etc should be minimal in a space scene.
But be aware that the z-Buffer is not your only problem if you draw scenes that large.

I would strongly rethink that approach. Do you really want to be close enough to earth that a seamless transition is possible/neccessary. Otherwise use a billboard and reuse the location calculation for the sun and other planets (I hope you don't want use 'real' values for those too)