Skybox

Back

The Goal

This page describes how to create a mod that adds a skybox to the game. This is possible as of version 1.02.01. Note that creating a skybox defeats the purpose the engine has of rendering objects far in the distance.

The Mod

You can download the mod here. Install the mod to the Input/Packages folder.

The File game_skybox.lua

The key script is game_skybox.lua which is located in the Game folder of the mod. It has a function called p.__render_before_level. This is called by the engine right before rendering every level. Actually, it is called in between the rendering of the infertile chunks of the level and the fertile chunks (the infertile chunks are rendered first). The function is passed the level that is being rendered as well as a bool which specifies whether the depth buffer was just cleared. The reason why this bool is passed is so that function does not need to clear the depth buffer again if it does not need to. Here is the code of game_skybox.lua:
--File: game_skybox.lua

function p.__render_before_level(level, cleared_depth_buffer)
    --We only render the skybox if we are on level viewer_level-2.
    local viewer_level = ga_get_viewer_level()
    if( level ~= viewer_level-2 ) then return end
    --
    --Clearing the depth buffer, if it has not just been cleared.
    if( not cleared_depth_buffer ) then
        ga_render_clear_depth_buffer()
    end
    --
    --Rendering an inverted cube.
    local meshname = "mesh_skybox"
    local tex = ga_mesh_get_tex(meshname)
    ga_render_color( std.vec(1.0, 1.0, 1.0) )
    ga_render_mesh_with_tex_no_lighting(meshname, tex)
    -- ga_render_mesh("mesh_skybox") --This would have lighting.
    --
    --Clearing the depth buffer again.
    ga_render_clear_depth_buffer()
end

The Skybox Mesh

The mesh mesh_skybox is different from most meshes. Because of backface culling, the triangles need to be oriented in the opposite order. Here is the file Meshes/mesh_names.txt:
mesh_skybox              MonsterWolf          huge_box_inverted.obj
The texture MonsterWolf can be replaced with any texture. The file huge_box_inverted.obj is the following:
v -50 -50 -50
v  50 -50 -50
v -50  50 -50
v  50  50 -50
v -50 -50  50
v  50 -50  50
v -50  50  50
v  50  50  50
vt 0.0 0.0
vt 1.0 0.0
vt 1.0 1.0
vt 0.0 1.0
f 1/2 5/3 6/4 2/1
f 5/1 7/2 8/3 6/4
f 4/2 8/3 7/4 3/1
f 1/1 3/2 7/3 5/4
f 6/3 8/4 4/1 2/2
f 1/1 2/2 4/3 3/4

Having 6 Textures For The Sides of the Skybox

In our example, each of the 6 sides of the skybox have the same texture. You can modify this to have 6 meshes instead of 1, one for each side. This way you can assign 6 different textures to the sides.