# How to mimic the same fixed-size horizon as in this racing game?

I am trying to replicate the same horizon (buildings and sky) as in the image below:

As you can see, the player has advanced in a straight line, yet the horizon has still the same size:

This is my attempt using 3D, while it's okay when the player is on the start line:

It's not so great when the player advanced as much as in the image no. 2:

This is an overview of where the horizon buildings and sky are located:

Obviously this won't achieve such effect when one is close to it, so I've tried to scale up the horizon on all axes but the problem is that the buildings are too small depending where you look at them from.

How can one mimic such rendering ?

• Google 3d billboards ;) – Gustavo Maciel Jun 10 '14 at 18:41

The two easiest ways I can think to do this are to either maintain a fixed distance between the camera and the horizon geometry, or draw the horizon as a 2D sprite, with the latter most likely being easier.

I believe that the game you are mimicking was able to achieve this because it was not actually a 3D game, but a 2D game that simulated movement through a 3D space; a 2.5D game, if you will. For that reason, drawing the horizon at a perceived fixed 3D distance is easy, because the 2D asset always needs to be rendered to the same portion of the screen.

To render it as a 2D asset, the simplest way I can think of is to first separate out objects into three categories: objects that will never extend visually into the sky (the road, and ground), objects that will (tall cacti, the player maybe), and the horizon/sky. The drawing algorithm then becomes:

1. Draw anything that won't overlap the horizon.
2. Clear the depth buffer.
3. Draw the horizon to the top half of the screen.
4. Draw everything else.


There are definitely other ways to do it. If you can guarantee that the ground will not draw above the horizon line, you can skip the depth buffer clear.

In short, trying to get what you want using exclusively 3D objects is possible, but would probably overcomplicate things. Try rendering it in 2D first.

You need to cancel translation from camera transform when rendering skybox, then just draw box at 0, 0, 0.

When you set effect.View you need to use modified camera.View where: newView._41 = 0 newView._42 = 0 newView._43 = 0

• Okay I've finally figured out what you mean, I'll give it a try; thanks ! – Aybe Jun 11 '14 at 6:38