2
\$\begingroup\$

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

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

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 ?

\$\endgroup\$
  • 1
    \$\begingroup\$ Google 3d billboards ;) \$\endgroup\$ – Gustavo Maciel Jun 10 '14 at 18:41
3
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.