Sign in to follow this  
iso8859-1

Frontier: First Encounter - How to do a similar graphic?

Recommended Posts

iso8859-1    120
Hello I wondered how to do the graphics for a game like FFE. For those who don't know that game, it's a space game with simulated star systems. You fly physically correct. The parameters: Objects can have sizes from 100 m (space ship), several thousand km diameter (Earth approx. 6400 km diameter) or like the sun, 1.392.000 km radius. For those from the US: 1000 m are 1 km. The distances are up to 50 or 100 AU. 1 AU is the distance from Earth to Sun (149.600.000 km (1 AU)). From all this, i conclude the granularity of the depth-buffer is not enough to render this. My main question is: how do I create a scene with for example 10 space ships, 2 space stations in our solar system. Any ideas? My first impulse is to draw the sun, then the planets and then the space ships/stations. But what about the Z-Buffer and his lack of precision?

Share this post


Link to post
Share on other sites
benryves    1999
If the depth buffer is really the problem then I guess you could easily build up a list of each object, coupled with its depth. Before drawing anything, perform a simple transformation of the centre of the model then add the object to this list with a corresponding depth (use the calculated centre). Then sort the list by depth, read off each object and draw as usual.
However, I'm sure there's a more fundamental issue here... if the scale really is the issue, then scale everything down, and if it's a problem of relative scales, then you can always use tricks like halving the total size of the sun and drawing it half the distance away.

Share this post


Link to post
Share on other sites
benryves    1999
I think so, and a quick sketch on paper with similar triangles seems to work. Calculate a vector from the camera to the object, find a point half way along it and put the object there. It should work... But it does seem too easy. I hope I'm not missing anything here. [grin]

Share this post


Link to post
Share on other sites
Eelco    301
Quote:
Original post by benryves
I think so, and a quick sketch on paper with similar triangles seems to work. Calculate a vector from the camera to the object, find a point half way along it and put the object there. It should work... But it does seem too easy. I hope I'm not missing anything here. [grin]

yes you are: youre messing with the very thing a z-buffer tries to ensure: correct ordering.

i believe the most commonly used method to solve this is by chopping up rendering in different passes, with different near/far planes.

Share this post


Link to post
Share on other sites
Ysaneya    1383
First of all, if you are going to work in real dimensions, you'll need to switch all your code to use doubles instead of floats (and even there you might suffer from internal precision issues at the edge of the solar system).

For the ZBuffer issue i would advise to implement frustum culling in a first step (you'll have to do it anyway for any less-than-basic engine). Then fixing the problem should be easy. Split your original frustum in 2 or 3 smaller frustums, by changing the near/far planes each time. You might have to overlap the near/far values in each frustum in order to get a good precision everywhere. Rendering is then just a matter of intersecting the scene with each frustum, and for each set of objects, set the frustum parameters and render the objects (Note: with that method you might render some objects multiple times, so you might have to use some stencil buffer tricks).

You can also do it the "smart" way, since space is mostly empty, by determining znear/zfar so that no object (like a planet) intersects two frustums at the same time.

For planets, as they are displayed as sphere, i found that disabling the ZBuffer reads/writes, enabling backface culling, sorting the planets and rendering them from back to front works well too.

Y.

Share this post


Link to post
Share on other sites
iso8859-1    120
As there aren't many objects, a general sorting by distance shouldn't pose any problems.

What is the mentioned frustrum culling?

You mention using several frustrum with different near/far-planes. Doesn't this distord the rendered picture (since the picture is rendered with the screen being the near plane?)?

Share this post


Link to post
Share on other sites
benryves    1999
Quote:
Original post by iso8859-1
What is the mentioned frustrum culling?


Picture a frustum, which is a rectangular based pyramid with the top pointy end cut off. This can be used to represent all the viewable space on your screen, bounded by the edges of the screen and the near/far clipping planes. Frustum culling throws away any objects that are outside this frustum.

Basically - set the far plane to be very far away, and the near plane to be also very far away, but still closer than the far one. Draw. Bring both in so that the far plane is just in front of where the near plane was. Draw again. Repeat a couple of times, so that you cover the entire range. (I think that's what Ysaneya was describing?)

Share this post


Link to post
Share on other sites

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