ArcaneEnforcer
ArcaneEnforcer

Reputation: 124

OpenGL Frames of Reference

Recently I have been attempting to render large scenes, such as planets, solar systems, and galaxies, and have run into the famous issues of float precision and z-buffer precision. I mitigated the z-buffer issues using a logarithmic depth buffer as described here; however, I haven't yet figured out how to fix float precision limitations over large distances.

One common method that I have found is to use different frames of reference for different distances, for example 1 unit = 1 megameter for solar systems and 1 unit = 1 lightyear for galactic scale as described here and here. In the latter link, one person specifically suggests

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.

My question is how do I go about actually implementing this method. Do I scale each object when I transition from different unit measurements? How do I maintain relative size and distance between objects rendered with different coordinate systems?

Upvotes: 1

Views: 603

Answers (1)

datenwolf
datenwolf

Reputation: 162297

Okay this is an interesting question and the answer may be a little bit surprising. The key insight is realizing that space is really big, and mostly empty. Which means that different objects in space are not touching and all you have to get right is the appearance of their relative positions as seen in the sky… and then cheat!

So what you do is, that you first sort all the objects by distance, and then draw everything within the same numerical range of units i.e. a whole star system is drawn with the same range of numbers as the terrain of the planet surface the point of view is located on.

Without cheating the whole thing would look like if you have some kind of small scale model of the star system, the galaxy, all this stuff superimposed in a single art installation. Everything would overlap and look weird.

This is where the "cheating" comes into place. You render each magnitude of scale/distance into a separate layer, and then you combine them, just like layers in Photoshop in a so called "composition" process. The main problem with this approach is getting the transistion between frames of reference right, so that it doesn't pop out.

A technique that follows the same scheme are 3D Skyboxes, essentially you're rendering several layers of 3D Skybox in just a particular direction and composite it.

Upvotes: 2

Related Questions