Cubemaps

Tutorial collection, comprehensive listings on main site.

Cubemaps

Postby Tutorial on Wed Mar 16, 2005 12:34 am

category
General Half-Life 2/Entities

description
One of the most essential parts of the Source engine, made easy for you here.

keywords
cubemap, cube, map, env_cubemap.

What are Cubemaps?

Cubemaps are what the Source Engine uses to calculate shininess on any face or model that supports it. To render the reflectivity properly would involve the engine drawing each scene twice and slow things down considerably. The DX9 water shader uses this effect and obviously if over-used you will get slow-down.

When Cubemaps are placed in to the map and the buildcubemaps command is used it takes 6 low-res screenshots (64x64 by default) at each cubemap point (left, right, north, south, up & down) and applies these to the textures/models closest to it. This way you get a shiny effect (although a little crude) on the textures or models. These "shots" are then sorted into the .bsp when the map is restarted. Only static images are taken so you will not see any moving objects etc but it's enough to give the effect.

Models and textures will automatically use the nearest cubemap to them, and if you turn on cheats and use the impulse 81 command you will six globes that will show you what cubemap is being used at that time.

When should they be used?

Cubemaps should be used in almost all areas of your map, if you have a room with some windows at one end and a light in the centre you would want a cubemap in the room to apply the main light to all the surfaces, having a cubemap next to each window will also allow the reflection to be made accurately. You will also need them in dark areas as well, if you were to leave one cubemap in a light area and then move into a dark area with no cubemaps the cubemap in the light would still be applied, so your gun models & textures would look odd as it will be using light shiny effects in a dark area.

In a small, evenly lit room one cubemap in the middle should suffice as it will apply the effect to all surrounding walls, as the rooms get bigger and the light contrasts more you will probably need more to effectively render the cubemaps onto the world and models.

How do I apply them to my map?

Firstly, place an env_cubemap in the desired area and ensure it is 16 units away from all brushes, around head height is preferred so that the snap shots taken are relative to the player.

When opening the map it should look like either of the two screenshots:

Image Image

Now you will need to open the console and use the command buildcubemaps. You will it take six shots at each cubemap so allow it to finish and then when it has completed you will need to restart the map for it to be applied correctly. If you do not it will use 6 images from the default skymap and apply those to the models, and this will very odd. As you can see below:

Image Image

You will need to run this everytime you do a compile of the map.

Quick Example

In a corridor (shown in previous images) I placed one light source at each end. Then placed a cubemap under each light. In the centre is a dark area, which I left without a cubemap. Upon running the map and buildcubemaps I moved from the light area into the dark. My weapon looked like the below:

Image

It is still using the nearest cubemap, and this is located in the lit area, so my gun model looks incorrect as I am in pitch-blackness but with a nice shiny bright gun.

The correct thing to do is to also place a cubemap in the dark area as well:

Image

As you can see it is nice and black, and matching the surrounding area.

Cubemaps take a while to get used to and all I can advise is you experiment with them as much as you can. If your models or textures are lit incorrectly then think through your cubemap placement in relation to the lighting in the level.

Blink
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Postby mad_ferrit on Thu Mar 17, 2005 12:31 am

That's great man, thanks a lot!! Been looking for a simplified explaination of cubemaps for a while now and you've done it! :D

So is there any hinderence in performance with too many cubemaps? Can I put one under every single light and next to every single window and every single shaded area for instance? Or is that the whole idea?
User avatar
mad_ferrit
Regular
Regular
 
Joined: Thu Jan 06, 2005 11:02 am

Postby Blink on Thu Mar 17, 2005 12:42 am

You can't go to over board with them, but judging by the Valve maps you can have a fair few. I'm not 100% on limits, but I had over 50 in my last map with no trouble and I'm sure Valve have added more.
User avatar
Blink
Cool 'n that
Cool 'n that
 
Joined: Fri Oct 08, 2004 4:16 pm
Location: UK

Postby Jest@ on Thu Mar 17, 2005 1:17 am

For every cubemap it stores 6 mini screenshots inside the BSP. That's gotta add considerably to filesize when you start using hundreds. I guess there's no set limit, just use them when ever they're necessary, but no more than that.
Highlight to read:
It was earth all along
User avatar
Jest@
Veteran
Veteran
 
Joined: Mon Nov 22, 2004 1:50 am
Location: London UK

Postby zombie@computer on Thu Mar 17, 2005 10:24 am

yes, the real slowdown in cubemaps is the amount of reflecting surfaces (and their size), the amount of cubemaps really only add to filesize and a small bit of recourses
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby Ranheim on Mon Mar 21, 2005 2:18 pm

How many surfaces can you apply to a cubemap?
User avatar
Ranheim
Member
Member
 
Joined: Sat Jan 01, 2005 3:15 pm
Location: Norway

Postby TheMiede on Sun May 08, 2005 5:17 am

You will it take six shots at each cubemap

What do you mean by shots? Screenshots? Gun Shots?

This is my first time trying to use cubemaps.
TheMiede
1337 p0st3r
1337 p0st3r
 
Joined: Wed Apr 20, 2005 4:11 am

Postby Serever on Sun May 08, 2005 6:49 am

screenshots
"Hey Scott. It's Dougal. Can I have my hair from the 1980's back?"
User avatar
Serever
Senior Member
Senior Member
 
Joined: Tue Nov 23, 2004 9:23 pm
Location: NSW, Australia

Postby zombie@computer on Sun May 08, 2005 7:20 am

btw, theres a max of 1024 cubemaps
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby TheMiede on Wed May 11, 2005 11:18 pm

I think i miss read one part where it says
You will it take six shots at each cubemap

Does that mean IT will take six screenshots or do YOU have to take screenshots.
TheMiede
1337 p0st3r
1337 p0st3r
 
Joined: Wed Apr 20, 2005 4:11 am

Postby Yoshi on Thu May 12, 2005 1:59 pm

now seriously, what do you think? :smt012
User avatar
Yoshi
Pheropod
Pheropod
 
Joined: Mon Apr 11, 2005 3:01 pm

Postby tarrryan on Thu May 12, 2005 5:10 pm

the 6 pictures are taken from the cubemaps prospecktive, (in side the cubemap)
above, below, left, right, front and back
стоя или умирам - Stand Or Die
tarrryan
Been Here A While
Been Here A While
 
Joined: Tue Apr 12, 2005 6:24 pm

Postby -|Dizmas|- on Sun May 22, 2005 5:14 pm

Thanks for the great tutorial. One question though...


After I did the buildcubemaps in the consol, it worked great, but then if I exit the game completely, then restart the game and load the map again, the cubemaps go back to the default by using the skybox. Do you have an idea of what I can do to prevent this?
-|Dizmas|-
Regular
Regular
 
Joined: Sun May 15, 2005 5:04 pm

Postby zombie@computer on Sun May 22, 2005 6:39 pm

the cubemapping is stored in the bsp. as long as you dont rename it or modify it the data shouls still be there
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby -|Dizmas|- on Sun May 22, 2005 6:50 pm

Ok... I didn't rename it. I'll try to figure it out.

thanks
-|Dizmas|-
Regular
Regular
 
Joined: Sun May 15, 2005 5:04 pm
Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users