Jump to content
  • Advertisement
Sign in to follow this  
ruben tan

Correct Approach for a 2.5D game engine?

This topic is 3044 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 am going for a 2.5D engine where I use 2d tiles and sprites for background and environment and use for 3D for characters. The main reason why I didn't go full 3D was because I don't have the resources for that, and the reason why I didn't go full 2D was because I didn't wanted to render thousands of sprites just to add a new armor piece of weapon.

The engine's view would be isometric, and the main feature of it would be per-pixel lighting (using normal maps and height maps) as well as soft shadows, both rendered in real-time.

Since the lighting needs to work for both the 3d models and the 2d sprites and tiles, I'm in a little dilemma here: How do I integrate 3d models into the scene given a specific z-ordering algorithm that works for 2D but doesn't necessarily work for 3D?

Logically, if I were to use a 3D engine, here's how I would have done it:

Quote:

Each background tile will be drawn onto individual quads, which will be tiled by the 3d engine on the same Z position. The camera will use an ortho projection, and pointed straight at the Z axis.

On top of the background tile would lie a user-interface overlay at Z + 1px (1 pixel in front of the background tile), where I can use as a debug layer for collision management and so on.

For environmental sprites (walls, trees, etc), they will be drawn on Z + 2px (2 pixels in front of the background tile), and will come with their own normal and height maps. Isometric draw order will be done by rendering sprites according to their Y-axis value, with higher Y value drawn later.


So my question is, how do I draw the 3d models with the correct z-order?

I've rolled a full 3D engine before in college (7 years ago) where I did per-pixel lighting and stencil shadows in real-time, but that was in full 3D and with loads of help from online tutorials, which was easy to understand. In this setup however, I don't even know where to start.

I got a clue that I could use normal maps generated by the 2D models to calculate the per-pixel lighting and shadows, and even seen a few examples online and in youtube, but I just can't wrap my head around how it actually works. I'm sorry, but after 6 years of developing web applications and non-graphic applications, I've kind of forgotten all about graphics programming already.

Do my question make sense? I would appreciate all help from people here.

Share this post


Link to post
Share on other sites
Advertisement
Never did 2.5d before but from my experiences of 2d with per-pixel lighting like you want to do it, I'd try not to separate between 3d and 2d. Just set up an orthographic projection matrix which you can use for poth your 3d models and 2d tiles and specify 3d coordinates for everything. I think it should be possible to specify an orthographic projection matrix to produce an isometric view out of regular rectangular texture tiles. As everything will be 3d internally, you can regularily use the z buffer and dont have to write lighting hacks for the 2d part of it.

Share this post


Link to post
Share on other sites
This is one way of doing it. I use OpenGL, so my examples lean that way.

The first thing to consider is Depth. If you are operating in a true 2D world where you have no ability to change that 3rd dimension, then skip this part. Otherwise, you need to make sure that objects are positioned at the proper depth. Even in a 2D world, a difference in depth of like 0.0001 should do the trick. I set up constants like this and assign the appropriate depth to each object.


Z_PLAYER = -0.0001
Z_MONSTER = -0.0002
Z_GRAND_PIANO = -0.0003
Z_BACKGROUND = -0.0009



Another important thing to consider is the order in which you draw your objects. I use an object tree and recursively render down that tree. I place a few group nodes just below the top node in the exact order I want them rendered. Then, I add entities to the appropriate group node.


World
---- BackgroundNode
---------- BackgroundObject1
---------- BackgroundObject2
---------- BackgroundObjectX
---- GrandPianoNode
---------- GrandPiano1
---------- GrandPiano2
---------- GrandPianoX
---- MonsterNode
---------- Monster1
---------- Monster2
---------- MonsterX
---- PlayerNode
---------- Player



Finally, you can set things up so that the group nodes will trigger the enabling/disabling of special features as you render, such as lighting or whatever. Reach a group node, enable its feature, recursively render its child objects, disable the feature, then move to the next group node.

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!