2
\$\begingroup\$

I've implemented basic 3D functionality and made little "2.5D" demo in orthographic projection using OpenGL ES 2 and Box2D.

Now I want to make completely two-dimensional game (using sprites) and consider 2 variants:

  1. Implement 2D graphics separately from 3D in separate layer, leave 3D stuff in background, draw 2D using various simplified algorithms (disable depth testing, simplified culling etc.)
  2. Leave everything as is and use billboards for sprites

Currently I use hierarchical system of entities with matrix transformations. I know about computational complexity of 3D and 2D graphics and believe first method should result in faster code, though it's my first engine and my google-fu fails me this time, so I'm not sure about it.

Engine is Desktop/Mobile.

What method would you recommend? Does implementing first method worth it (in performance aspect)?

\$\endgroup\$
1
  • \$\begingroup\$ Just as a side note, usually 2D is draw to screen coordinates (x and y) so there is no real need for depth testing. You would just draw your sprites in the same way as you create a game menu in a 3D game. \$\endgroup\$ May 30, 2013 at 16:37

1 Answer 1

0
\$\begingroup\$

Implementing 2D as 3D objects can have benefits when you want to mix the two (a 2D interface floating in 3D space, like Dead Space for example).

In the approach I would recommend you will have a 3D object that is the root of a 2D hierarchy. Use traditional 2D rendering to an off-screen buffer for all objects below that root, then use that as a texture for the 3D object (billboarded or not). You can have as many roots as you want (usually just 1 in a pure 2D game).

The problem is that 2D rendering typically works pretty differently to 3D in non-trivial cases. Render order becomes more important and trying to sort polygons in traditional ways for 3D games tends to not work super well for lots of 2D billboards. Using explicit depth layers is faster, easier, and will be more correct in the general case. The "faster" bit is probably not as important for you as you seem to think, though it'll become relevant at truly large numbers of sprites.

So far as engines, most do it your first way as they use an entirely separate library like Scaleform for all of their 2D rendering. Others, like Unity, have libraries to "optimize" some forms of 2D by rendering them separately (and doing various bits of geometry batching and depth ordering) though by default usually just uses the 3D pipeline straight up with a specialized orthographic camera setup.

In short, I would recommend to have both scene types, but make sure you can render either view to a texture so it can be rendered into the other scene type.

\$\endgroup\$
1
  • \$\begingroup\$ Yes, exactly what I need. Why didn't I thought about that solution. Thank you :) \$\endgroup\$
    – zhur
    Jun 1, 2013 at 7:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .