Cube maps: Difference between revisions
No edit summary |
mNo edit summary |
||
(24 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
How to create a cube map (also called environmental map) of your environment using the envshot command in | '''Note from peter_spy:''' | ||
''This tutorial is largely outdated and needs substantial revision. E.g. you can add cubemap reflections to many more materials, from marble floors to metals. The shader code used here is also wrong as it doesn't use alpha stage for the cubemap. You will want to control the cubemap strength, typically via texture and alpha multiplier.'' | |||
''written by angua'' | |||
<!-- keywords: cubemap reflective specular --> | |||
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: [https://modwiki.dhewm3.org/Cube_maps Cube Maps] | |||
==Create your room== | ==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: | 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: | ||
[[Image:Cube map empty.jpg|320px|Example room]] | |||
[ | |||
==Create your images== | ==Create your images== | ||
* Set the screen resolution of | * 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] | envshot [prefix] [size] | ||
Line 19: | Line 28: | ||
envshot water_pool 512 | 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. | |||
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 | * You should now see six new images in your /env folder: | ||
water_pool_nx.tga | water_pool_nx.tga | ||
Line 37: | Line 46: | ||
looking like this: | looking like this: | ||
[ | [[Image:Cube map.jpg|320px|Cube map after shot]] | ||
You can of course also move them to a different folder if you want. | |||
==Edit your images== | ==Edit your images== | ||
If you leave the images like this, they will not work ingame. You have to rename them | :''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_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_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. | |||
*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_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. | ||
You should now have six files in your /env folder called | You should now have six files in your /env folder (or wherever you moved them) called | ||
water_pool_back | water_pool_back | ||
water_pool_right | |||
water_pool_down | water_pool_down | ||
water_pool_forward | water_pool_forward | ||
water_pool_left | water_pool_left | ||
water_pool_up | water_pool_up | ||
looking like this: | looking like this: | ||
[ | [[Image:Cube map processed.jpg|320px|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: | |||
textures/env/water_pool | |||
{ | |||
qer_editorimage env/water_pool_up.tga | |||
noFragment | |||
noshadows | |||
noimpact | |||
nooverlays | |||
forceOpaque | |||
nonsolid | |||
{ | |||
forceHighQuality | |||
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== | ==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.) | |||
[[Image:Cubemap1.jpg|300px]] | |||
* 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. | |||
[[Image:Cubemap2.jpg|300px]] | |||
* 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. | |||
[[Image:Cubemap3.jpg|300px]] | |||
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). | |||
[[Image:Cubemap4.jpg|300px]] | |||
Here you can see the same pool textured with true reflective water for comparison: | |||
[[Image:Cubemap5.jpg|300px]] | |||
==Notes== | |||
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. | |||
[[Image:Cubemap6.jpg|300px]] | |||
So it would be more practical to have non-extinguishable lights and no large moveables near the water. | |||
{{tutorial-editing}} | |||
[[Category:Skybox]] | |||
[[Category:Mapping Tutorials]] |
Latest revision as of 23:26, 18 April 2020
Note from peter_spy: This tutorial is largely outdated and needs substantial revision. E.g. you can add cubemap reflections to many more materials, from marble floors to metals. The shader code used here is also wrong as it doesn't use alpha stage for the cubemap. You will want to control the cubemap strength, typically via texture and alpha multiplier.
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: Cube Maps
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:
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:
water_pool_nx.tga water_pool_ny.tga water_pool_nz.tga water_pool_px.tga water_pool_py.tga water_pool_pz.tga
looking like this:
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.
- 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.
You should now have six files in your /env folder (or wherever you moved them) called
water_pool_back water_pool_right water_pool_down water_pool_forward water_pool_left water_pool_up
looking like this:
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:
textures/env/water_pool { qer_editorimage env/water_pool_up.tga noFragment noshadows noimpact nooverlays forceOpaque nonsolid { forceHighQuality 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:
Notes
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.