Jump to content
  • Advertisement
Sign in to follow this  
Anessen

OpenGL Confused: Very large environments

This topic is 3154 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 got an idea for a 3D application, but I'm trying to understand how I'm going to get this to work. The 3D scene created with OpenGL uses 32bit integers. What if the environment that I want to render is bigger than this? I need to use 64bit integers to render a 3D model a certain distance away from the "camera". I've played games like Frontier First Encounters that render huge environments in 3D and I'm trying to understand how this is done without having to jump through many hoops... anyone tried anything like this before?

Share this post


Link to post
Share on other sites
Advertisement
I've never actually done it myself, but the principle is pretty simple, If some thing is close, you should render a high poly version of the model, and if some thing is far away, you should only render a low poly version of the model. THis is called Level of Detail (LOD).

Afaik openGL uses float for distance.. So I really don't see how thats a problem. If it's because of your own map format, you should consider to split your map into regions.

Hope this helps :)

Share this post


Link to post
Share on other sites
If you want to render a truly huge scene, such as a realistic-scale solar system, or worse yet, universe, then you have to use some sort of coordinate hierarchy.

The idea is that you might model the Earth in metres, and attach it to the solar system, which is modeled in kilometres. The solar system in turn is attached to the milky way, which is modeled in light-years, which is connected to the local cluster, measured in millions of lightyears.

When you go to render the scene, you traverse the hierarchy downwards, and at each level, a 32-bit float has plenty of precision.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anessen
The 3D scene created with OpenGL uses 32bit integers. What if the environment that I want to render is bigger than this? I need to use 64bit integers to render a 3D model a certain distance away from the "camera".


Where does it use integers?

Share this post


Link to post
Share on other sites
I've had a similar problem with a game I'm working on right now. You, probably, won't need to go as far as I have to solve the problem. Work out how large your game world (that is, one area of it at a time) and decide your units from there. In case you have ran into an actual problem with why floats are bad (you will want to be using floats, not integers in OpenGL, unless maybe you're on an embedded platform using OpenGL ES), this is my solution:

In my game I've divided the world up into zones - each zone is it's own coordinate system, but it has a 3D integer vector for it's location rather than a 32bit float or matrix transform - that way I get perfect precision for a zone's location. Each zone is 1000x1000x1000 units (-500 to 500), and that's float. Done it like this so I have perfect precision at all times, whilst not having too many zones (solar system...big place). It's all stored in a hash map for quick lookup and so I don't need to have zones exist that don't actually have anything in them. Dynamically create/destroy them as objects pass in and out of them. Rendering far away zones is done with some manual placement and scaling on the model view per zone - precision doesn't matter for rendering far off objects really, not in my case. For very far away zones I can just render them as a star, or not at all. For the record it's an outer space game. I worked out that just travelling earth-moon distance would put me well outside of decent precision, and I'm working in 1 unit is 1km! Sounds overkill, but it works nicely having 1Mmx1Mmx1Mm zones - as I only need good precision down to around 1m.

Share this post


Link to post
Share on other sites
Thanks for your responses!

And yeah I meant float for actually rendering the scene, the world coordinates of the objects are stored as integers. I will need to use LODs for objects otherwise the poly count is going to go just insane for a start.

What I am making a game that would have to model a whole solar system at a time in real scale. What I am having problems understanding is how you can get enough precision to render this scene using float values, because the player's movement must be smooth relative to close objects but at the same time I can see the 3D models of objects that are many thousands of kilometers away (very large planets, stars etc).

I understand that I can model the locations of objects in a very large environment using a coordinate hierarchy, basically subdividing out grid spaces. What I'm having problems with is drawing that. I am quite new to 3D graphics (moving from 2D) so maybe I'm just missing something obvious here.

Share this post


Link to post
Share on other sites
You need to keep track of your objects with 64-bit floating point vectors and matrices to model an entire solar system, yet be able to move the camera to any position and see small details on each planet. I did this in my engine for exactly this reason.

You need to perform one other "trick" to make this work with current GPUs (because they only support 32-bit floating-point numbers). When your camera is near a particular planet, you need to make that object (or the camera) the "zero point", and subtract that position from the position of every object to compute "current pseudo-world coordinates positions". In most cases, it is easier to make the camera position the origin of this coordinate system, though that is a bit problematic if your engine supports multiple cameras (like mine does). Once you convert the positions of other objects into this new coordinate system, you can convert those positions to 32-bit floating-point and let the GPU shaders render as usual.

BTW, you have a choice --- you can simply translate the origin of the world coordinate-system to the camera position, but leave the axes alone, or you can transform the coordinate system so the axes of the camera become the axes of your new coordinate system. I prefer the former, largely because I support multiple cameras.

Share this post


Link to post
Share on other sites
OK, I understand that. But, I just tried to make a very large environment using a 1 unit to 1 metre scale... I drew a very large box (imagine drawing a box around Jupiter, 142984000 metres in each direction) and I had a camera that I could move around and moved forwards and backwards in very large steps too (millions of metres). What I found is that there were a lot of graphical glitches with bits of the box disappearing as I moved the camera around.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anessen
What I found is that there were a lot of graphical glitches with bits of the box disappearing as I moved the camera around.
That is caused by a lack of depth buffer precision, which is the next issue you have to deal with. Sean O'Neil has a post on the subject, which method I am using currently. Ysenaya and a few others had a neater solution using logarithmic depth buffers, which you should be able to find around GameDev.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by Anessen
What I found is that there were a lot of graphical glitches with bits of the box disappearing as I moved the camera around.
That is caused by a lack of depth buffer precision, which is the next issue you have to deal with. Sean O'Neil has a post on the subject, which method I am using currently. Ysenaya and a few others had a neater solution using logarithmic depth buffers, which you should be able to find around GameDev.
Note that recent GPUs and shader-languages support floating-point depth buffers. I believe this is more-or-less equivalent to logarithmic depth buffers, except floating-point depth buffers are now a built-in capability, and therefore requires NO special code in your program or shaders.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!