Cube maps

From The DarkMod Wiki
Jump to: navigation, search

written by angua

How to create a cube map (also called environmental map) of your environment using the envshot command in TDM.

Cube maps can be used to fake reflections e.g on water and highly reflective tiles, etc. The advantage is that rendering is faster.

You can also find more inflormation on Cube maps in the modwiki: Wayback archive

Create your room

Create the room you want to have your pseudo-reflective water in. Add all the large parts, but you can leave small details (and of course the AI) out. Your room might for example look like this:

Example room

Create your images

  • Set the screen resolution of TDM to 640 x 480. If you don't, parts of your images will be cut off and they will not fit together any more. You will have to restart TDM or use console command vid_restart for the changes to take effect.
  • Open your map in TDM and get to the position of your water (at the center of the water source, about surface level, you can use noclip if you can't get there by walking).
  • In the console, type
envshot [prefix] [size]

[prefix] is how the images are going to be named. The size should be in powers of two. For example, your command could look like this:

envshot water_pool 512

Press enter, and you will see some flickering on the screen while your images are created, and a message in the console will appear saying

Wrote env/water_pool_nz.tga,etc.

You might want to make a few more envshots at slightly different positions, so that you don't have to repeat the whole procedure if your images are not appropriate. The direction at which you are facing during the shots is not important.

  • You should now see six new images in your /env folder:

looking like this:

Cube map after shot

You can of course also move them to a different folder if you want.

Edit your images

This section won't be necessary in TDM 2.04. The images will be named and oriented correctly.

If you leave the images like this, they will not work ingame. You have to rename them and there is also some rotating and flipping required. (Note that this works for me if the reflecting surface is located at the bottom facing upwards, the required procedure might be different if the reflection is located at the walls or the ceiling).

  • Rename water_pool_nx to water_pool_back. Rotate it 90° counter clock wise and flip it horizontally. This is going to be located at the west.
  • Rename water_pool_ny to water_pool_right. Flip it horizontally. This is going to be located at the south.
  • Rename water_pool_nz to water_pool_down. You don't have to manipulate the direction here, since it is located at the bottom and will not be visible anyway.
  • Rename water_pool_px to water_pool_forward. Rotate it 90° clock wise and flip it horizontally. This is going to be located at the east.
  • Rename water_pool_py to water_pool_left. Rotate it 180° and flip it horizontally. This is going to be located at the north.
  • Rename water_pool_pz to water_pool_up. Flip it horizontally and rotate it 90° counter clock wise.

You should now have six files in your /env folder (or wherever you moved them) called


looking like this:

Cube maps processed

You can also add some blurryness if you want. That makes it less obvious that the reflection is faked by a static image.

Write a material shader

Open an already existing material file or create a new one. Add the following shader:

    qer_editorimage env/water_pool_up.tga

	blend add
	cameraCubeMap env/water_pool
	texgen reflect

If you have forceOpaque in your shader, the texture will be opaque and you will not be able to see the ground. If you leave it out, it will be semi-transparent and you can see the ground also. If you moved the images to a different folder, make sure that the correct paths are entered at the qer_editorimage and the cameraCubemap lines. (The path entered in the name of the shader (before the { ) is for the folder the texture will appear in Darkradiant. It can be different from the path the images are in.)

Get your enviromental map ingame

  • Open DarkRadiant (if you already have it open you might have to close and reopen it to be able to see the texture).
  • Draw a brush that is going to be your water. Texture it with common/nodraw.
  • Go to the media browser. You should find your texture in the /env folder. (If you wrote another path in the name of your shader, it will appear there.)


  • Apply it to the top face of the water brush. You should now see the water_pool_up image as editor image (that's what the qer_editorimage line in the shader was for). Scale and position of the texture is not important.


  • Convert the brush to a func_liquid. (You don't want to be able to walk on water, do you? That would happen if you didn't convert your brush.) For more detailed information on water creation, you can also look at the Swimmable Water tutorial.
  • you should now be able to see your water ingame.


It will still look flat, like a mirror, and you will see that it is a static image (the torch is not flickering) so you might want to add a patch slightly above the water textured with, e.g. water_clear (or any other water texture that produces water waves).


Here you can see the same pool textured with true reflective water for comparison:



You have to take into consideration that in contrast to a true reflection, the cube map texture will not react to changes in the environment. So if you for example put the torch out, it will still be lit in the cube map.


So it would be more practical to have non-extinguishable lights and no large moveables near the water.