Skybox implemented

posted in BitHack
Published September 13, 2019
Advertisement

doom2.png.a9f10677a6be49871f32608f51dccffd.png

Doom levels make good use of both indoor and outdoor spaces.  To support these outdoor spaces, I spent this evening adding support for skyboxes to my raycasting engine.  After all, they are really just the same old indoor spaces with a ceiling that looks magically like the sky.

The obvious approach in 3D would be to use a cube map, however in 2.5D we can get away with something much more simple.  Since the player cant look up or down, we can create an wide image strip that wraps around the player for the entire 360 degrees.  As the player turns around we just have to figure out which part of the strip to show them.

skybox_texture-1024x768.jpg.ffcc25dc93082808bf6afaa6082af7ac.jpg

To begin with I found a simple cube map online and began making a few modifications.  For starters, I could dispense with the top and bottom segments leaving me just with the strip that can wrap around the player and secondly I tweaked the hue to give it a more hellish red colour.  Lastly I scaled it to a more software friendly 512x128 pixels to be more cache friendly and also give it a more grungy doom look.  I'm software rendering so my textures cant be too big.

My idea was simple, if we ever try to render a ceiling tile with an invalid texture index, we will instead jump to the skybox rendering code for the pixels covered by the tile.  Since the skybox texture is drawn based only on the players direction, those invalid ceiling tiles will appear to be magic windows through to the sky, and it will look like they never even existed.

To map a screen column to a column in the skybox, I generate a direction vector from the camera origin to our column on the camera plane and using the atan2 function on the components we can use the result to index the skybox (after some slightly magic scaling and wrapping code).

Since the ray-casting engine renders to the screen in columns, it is more cache friendly to rotate the skybox by 90 degrees, so I can first find the row in the skybox texture for my column of pixels on the screen, and then simply march along the x axis in the texture as I walk along the y axis of the screen.  This replaces a multiply in the loop with an add and keeps the entire skybox row in the cache while we need it.  Simple.

sky.jpg.566258236bb59acbe0e4f70df60a3677.jpg

Have a look at the skybox in action:

 

Previous Entry Player weapon
6 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Hit Scanning!

2893 views

Level editor

2834 views

Skybox implemented

6825 views

Player weapon

2093 views

Sprite Lighting

1862 views

Arrival on Mars

1836 views
Advertisement