Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large, slowly rotating planet graphics for game

Tags:

graphics

3d

For a computer game I'm developing, I'd like to draw very large (~500 px) graphics of planets slowly rotating. These graphics are meant to impress. What's the best way of doing this?

  • I could pre-render each frame, but at 500px and a rotation period of 10 seconds, that's a ludicrous amount of data per planet.
  • I could use a 3D engine and map the planet's texture onto a mesh approaching a sphere, but at 500px, I fear the polygon count would have to be huge to make it look good.
  • I could write a kind of custom 3D engine that does nothing but efficiently render a textured sphere, by converting the x/y coordinate of each view pixel into the coordinate space of the sphere's texture - but this is involved, and couldn't benefit from graphics acceleration.
  • Something else I haven't thought of?

Here's an example animated GIF of what I mean. (At 100x100 px and 60 frames, it's already pretty huge, sorry.) Imagine this much, much bigger, rotating much slower, and animated more smoothly:

alt text

But if this were 500x500 px and 10 x 25 = 250 frames, we'd be talking about hundreds of MB of data, so this straightforward approach doesn't work.

like image 902
Zarkonnen Avatar asked Dec 17 '10 17:12

Zarkonnen


2 Answers

Fracplanet can save out "spheremap" texture maps (and bump maps); see the images towards the bottom of the gallery. These are intended to be subsequently read into an app and mapped onto relatively low resolution sphere geometry to achieve the very effect I think you're looking for. This approach will use less memory than the pre-rendered animation approach or using the original full resolution polygon model.

Yes this is basically your second bullet point but I wouldn't be so quick to rule that approach out and I think you'll find you can get away with a lower resolution sphere than you anticipate; the eye notices the fine detail in the texture far more than it notices the low resolution of the geometry it's draped over. Modern tessellation hardware means you can probably get the GPU to easily generate and render a ridiculous number of polygons for a sphere for you anyway.

Alternative idea: render a single square quad polygon sufficiently large to cover the planet. For each pixel within that, execute a pixel-shader which computes the screen-ray-sphere intersection point (if any). Look up the colour from the planet texture (taking time and planet rotation into account). Avoids the need for a lot of polygons and gets you an exact sphere.

like image 69
timday Avatar answered Sep 23 '22 07:09

timday


If you want graphics acceleration, then polygons are cheap -- a fairly large number of polygons is not a problem.

I recommend a cube map texture, and a corresponding cube-like triangle grid: start with a vertex grid in the shape of (the surface of) a cube about the origin, and normalize each 3D coordinate to unit radius. This will make computing your texture coordinates easy.

Keep in mind that you need to choose the right projection for your texture: in the above case, you will want a tangent projection for each cube face, to match your grid.

like image 42
comingstorm Avatar answered Sep 23 '22 07:09

comingstorm