Cubemaps - What and how

Cameron:D

L6: Sharp Member
Sep 28, 2008
363
145
What are cubemaps?
To make it simple, predefined reflections for surfaces to well…. Reflect.

Why are cubemaps used?
To do real-time reflections the engine needs to take what the player sees, flip it up-side-down, distort it to make it look reflected, and then draw it to the surface. Doing this frame will take way too much processing power to be worth it…. So that is what cubemaps are used for.

How do cubemaps work?
A cubemap is a point entity (env_cubemap) that you place on your map…. They should be placed in the following areas:
  • Near reflective surfaces
    • Windows
    • Water (Should be tied to the water face, so it only applies to that face)
  • Near reflective entities
    Some examples:
    • Cap points
    • Direction signs
  • In areas of high contrast
    • If you have a dark room, you don’t want things reflecting the bright outside or vice-versa

Using cubemaps
Once you have the cubemaps in your map, you compile your map; however, the only things your cubemaps are reflecting are the default ones provided by the skybox, so whether your reflective surface in inside or out, it will be reflecting clouds.

cubemap_example0000.jpg


This is what a map looks like with NO env_cubemap entities… ewww, the black/purple checks are what get displayed then a texture can’t be found… and because there are not cubemaps, it doesn’t know that to reflect.


cubemap_example0002.jpg


But when we toss in some env_cubemap’s… this is what we get…. A little better.


cubemap_example0003.jpg


Notice though, how the water does not reflect the cube (That black mark in the water was me accidently shooting). Why? We haven’t yet done what is known as ‘building our cubemaps’.

Building cubemaps
The process of building your cubemaps is actually quite simple. In fact all it takes is one console command: ‘buildcubemaps’. However, before you do that you first need to set up your map, by typing the following commands into the console.
  1. Compile and load your map.
  2. mat_specular 0
    This turns off reflections.
  3. buildcubemaps
    The game will pause for a second, and lots of little pictures will flash up the top of the screen.
  4. disconnect
    If you are not using HDR, you can step to step 11
  5. mat_hdr_level 0
    Turn off HDR.
  6. map “your_map_name”
    Load the map again
  7. buildcubemaps
  8. disconnect
  9. mat_specular 1
  10. mat_hdr_level 2
  11. map “cp_dustbowl”
    We need to load another map, to clear the caches of your map contents, otherwise it will not reload any of the cubemaps.
  12. Disconnect again, and load up your map. Enjoy!


cubemap_example0004.jpg


Now the water looks much nicer, and if you look close enough, the cap point will reflect the sky.
 
Last edited:

TheDarkerSideofYourShadow

L10: Glamorous Member
Apr 12, 2008
792
286
You know, even after all the time I've spent on these forums, this is the best explanation I have seen of what is going on and what you need to do. Well done sir.
 

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
Very comprehensive. This is of course the #1 mapping mistake.

I'd put it at #2, right after model textures.
No matter how good at mapping you are you can always lose concentration and use a model texture by mistake, but once you know about cubemaps you never forget them before a release
 

Ida

deer
aa
Jan 6, 2008
2,289
1,372
Great guide, explains it all very well.

I'd put it at #2, right after model textures.
No matter how good at mapping you are you can always lose concentration and use a model texture by mistake, but once you know about cubemaps you never forget them before a release

This is officially the second post I've thanked by accident. Enjoy your thanks, I guess?
 

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
You can remove your thanks you know, there is a little button to do so ;)
 

Scotland Tom

L6: Sharp Member
Jan 19, 2008
332
64
Finally! A simple, straightforward explanation of how to implement cubemaps! Thank God!
 

Scruga

L1: Registered
Dec 8, 2008
39
0
Has this anything to do with this situation:
when i place a big prop, which is half in the shadow and half in the light, it's totally dark or totally light. i have no idea how to solve this. any help?
 

TheDarkerSideofYourShadow

L10: Glamorous Member
Apr 12, 2008
792
286
No, that is a different issue. Thats because the origin of the prop (which is where it samples light from) is in a dark spot. However, and before Youme gets on my ass, there are additional compile commands you can use to light things much more evenly. IT is suggested that you only do it during pretty compiles since it adds so much time.

http://forums.tf2maps.net/showthread.php?t=2994
 

Huckle

L3: Member
May 31, 2010
149
101
I think your step #11 could also just be sv_cheats 1 and mat_reloadallmaterials. In theory, that should clear the cache, just like loading another map while being a bit faster than loading the entire other map.
 

ArtistDude88

L1: Registered
Sep 30, 2010
5
0
Excellent guide! I definitely have this bookmarked!
 

Pocket

Half a Lambert is better than one.
aa
Nov 14, 2009
4,699
2,581
It should probably also be moved to the tutorials subforum, which I'm guessing hadn't even been made when this thread was new.
 

Dog.vtf

L1: Registered
Sep 2, 2017
49
12
I'm kind of getting negated outcomes???

When I don't have cubemaps water has real reflections and cap points reflect the sky. But when I put cubemaps in, everything with a reflection is all Black and purple checkers.


WUT?
 

Pocket

Half a Lambert is better than one.
aa
Nov 14, 2009
4,699
2,581
What you're seeing is the "default cubemap". If there are no cubemap entities in the map whatsoever, it uses that. Which means you can probably get away with not using any cubemaps during early test versions. Probably. The default cubemap was based on a daytime skybox, so in dimly-lit indoor rooms with shiny tiled floors it'll probably still look like butt.

The checkerboards are the generic "missing texture" texture. You'll get that when there are cubemap entities, so the engine knows to look for cubemaps, but there are none in the map yet. They're generated when you actually build the cubemaps as per the instructions.