Advanced HDR
Contents
HDR and exposure adjustment
As showcased in Lost Coast - a simple tech demo - High Dynamic Range (HDR) is a lighting feature which allows for a broader than normal contrast range between darkness and brightness. The exposure value changes in real time depending on the player's position and camera angles. When the player is in a dark area of the map, the sky seen through a window/opening of that area will appear brighter than usual. When the player goes towards a more well-lit area of the map, brightness will return to normal levels again, fading from over brightened to normal at a specified rate. The properties of HDR can be adjusted with the aid of an env_tonemap_controller. Exposure levels can be changed manually via the Input-Output system, so the level designer can touch a bit further on the automatic tonemapping. HDR offers maps a higher visual standard with minimal performance drop. It is also easy to implement and it is supported by all Source Engine games at this point, and HDR was later required since Left 4 Dead engine branch and later engine branch, so all new maps should come with HDR-baked lighting.
Lost Coast example
The purpose of an env_tonemap_controller entity is to help with changes between overly bright areas, and extremely dark areas. It smooths out the exposure transition, and aims to imitate the real world, when the human eye adjusts to extreme brightness changes over a relatively small amount of time.
In the characteristic example of Lost Coast, when the player walks into the tunnel they trigger a trigger_multiple brush entity. Its outputs are as follows:
SetAutoExposureMax: 6.0
SetAutoExposureMin: 2.0
SetBloomScale: 1.6
All these settings cause the tonemap controller to adjust different exposure parameters in real time, and if AutoExposureMin
, AutoExposureMax
, and BloomScale
's values are increased, then the sky and any other light sources appear brighter than before. In this specific example, the tonemap controller keeps the settings like this for a while, until the player leaves the trigger area. The tonemap gets directions on how to modify exposure and bloom via inputs, namely OnStartTouch
and OnEndTouch
.
When the player enters the trigger area the new settings of the env_tonemap_controller are applied by the output OnStartTouch
, and then set back to the previous settings
with the OnEndTouch
output, when the player exits that area.
In the third screenshot the player walks out of the tunnel and then experiences brighter light than there actually is. Consequently, exposure values drop, to return brightness to normal. At this time the player's "virtual eyes" are adjusting, and then finally in the last screenshot they have adjusted completely.
The tonemap controller is mainly commanded by a trigger_multiple, and assigned its default settings by a logic_auto entity. When the map begins, outputs can be fired to the tonemap controller, and it is then that the tonemap controller changes the lighting parameters. Throughout the Lost Coast map there are many other triggers the player walks through, which cause the exposure levels to change. However, if a map does not contain an env_tonemap_controller
, then the HDR effect will really be a bit random: continuously dimming the screen and brightening it up at random times, or even when the player steps into a area that's just a tad brighter than the previous one. In other words, the HDR settings will end up acting unrealistic in that case and HDR will be set to its default settings of 0
on all exposure and bloom parameters.
On a main note though, each map requires different settings even if using the same skybox material. A good reason you might need to change the settings is to really attain or create a certain effect towards the area the player is currently in, even if it's just for a few seconds. If you leave the default settings there is a good chance that some areas in the map will have abnormally sharp or strange exposure changes, so in the end the best idea is to tinker around with your map until you achieve the look that you think is right. And if the auto tonemapping adjustments don't seem to fit in a certain area you can always create trigger_multiple volumes around that specific area, just like Valve did in Lost Coast. That will change the settings manually and correct any mistakes, helping to get the lighting just right, even in the most difficult of lighting scenarios. It should be noted, however, that the tonemap controller does not add any more "real" brightness to the area - it only increases and decreases exposure on top of the actual lighting information the map has. Brightness still needs to be adjusted at the options of the light entity used to cast light. Also, each light entity has its own HDR brightness parameter which should be set the same as the overall HDR brightness. (in most cases it should be left at the default, and so should the light_environment HDR brightness parameter as well.)
Here is an example of the effects of a tonemap controller on different environments:
Valve implemented the env_tonemap_controller
entity to better control the ideal brightness of the sun so it's not overly bright and unrealistic. Also, they gave the sun a layered light effect which uses the existing fog in the map, by changing a few light settings and increasing the exposure a bit more than usual.
Another use of env_tonemap_controller
by Valve is the inside corridors of the Citadel which also use the entity to adjust the sensitivity levels, so the metal wall textures look a bit nicer.
If you are a bit foggy on the I/O system, the following section covers the process of implementing HDR through a step-by-step guide.
Creating a HDR map
Creating a map with HDR support isn't too hard, though it still requires a few entities as well as some I/O work regarding the env_tonemap_controller. As noted above, the initial I/O logic on map spawn will be achieved with the logic_auto entity.
- First, place a env_tonemap_controller in the map. The entity needs to be in the map but as location does not effect anything. Some community maps, as well as some of Valve's maps tend to have the env_tonemap_controller at the start of the level near the player included with other global entities for better organization purposes and clarity.
- Now at this point the best thing to do is give the the env_tonemap_controller a name. It does not really matter what the name is but for the example map shown above it was named
tonemap_controller
- The next step is creating a logic_auto. Once placed open up its properties and go straight to the "Outputs" tab.
- Take a look at the picture to the right with the logic_auto selected in it. These are the settings that were set as outputs, however for your map you might choose different settings.
- With the logic_auto placed in you map, and with the outputs tab open, create a new output.
The first output is going to send a message to the tonemap_controller
about the maximum auto exposure and the second output is going to send a message regarding the minimum auto exposure.
My output named | Target entity | Via this input | Parameter | Delay | Only once |
---|---|---|---|---|---|
OnMapSpawn | tonemap_controller | SetAutoExposureMax | 2 | 0.00 | No |
Although not the simplest thing, HDR isn't too hard to work with. However it adds a large amount of time to the compile process. In fact, vrad
must run twice. Once for LDR and a second time for HDR. The first thing in creating an HDR map is of course an HDR-supported sky texture. See this page for a list of skyboxes which support HDR as well as the ideal lighting parameters for them.
Once you've picked one open the map menu located on the top right of Hammer, and then go to map properties. On the properties panel set the skybox material field to whatever the skybox texture you picked is called. Then click apply.
HDR Brightness
properties of your light entities or light_environment, and compile your maps using the HDR Full Compile preset, found in expert settings. For the final compile with HDR you should use Full Compile -both -final (Slow!)Because HDR is brighter and adds a glow to the world its wise to set the brightness value a bit lower the the regular LDR brightness. In example if LDR brightness is 100
then HDR should be set to 50
. Mainly it really depends though on the lights source and effect that your going for. Mainly though never have both the same. You have to take in to consideration players who don't have HDR capable video cards. Therefore the brightness must be equivalent to that in-game of LDR. Once you're done setting up the values click apply on the properties panel and well that's it. Now go ahead and run your map. Make sure you have HDR checked in the compile window checked. If you're compiling under the advanced window then simply set the compile type to HDR -final
or HDR -final -fast
. If you're just testing then fast might be a good idea to run and create a quick build version of lighting in your map. When you complete your map fully then go for the final compile but note, it takes quite a long time depending on the size, number of lights, and complexity of lightmaps used in your map!
HDR Brightness
property of your light_environment
entity.Running a HDR map
Now that the compile process has finished in-game, follow the instruction here on how to build cubemaps. In order to really get the lighting right you need to build cubemaps twice. Once for LDR and once for HDR. Once building the cubemaps have finished type in disconnect
to return to menu, then mat_hdr_enable 0
in the console to disable HDR and return to LDR. Now simply buildcubemaps
again. You're done! The game will return automatically to HDR so theres no more console commands needed, but if the game did not return to HDR automatically, you can type this console command: mat_hdr_level 2
(or by going to Options > Videos > Advanced... and set HDR to Full) to force HDR to be enabled. Through the console however you can change around the exposure levels of the env_tonemap_controller
.
The following console commands are currently available for HDR:
Command | Action |
---|---|
mat_autoexposure_min |
Minimum exposure settings. |
mat_autoexposure_max |
Maximum exposure settings. |
mat_hdr_enable 0/1 |
0 Turns off HDR, 1 turns HDR on. Deprecated:Deprecated since Source 2007. Use mat_hdr_level instead. |
mat_hdr_enabled |
(in all games since Source 2007) Report if HDR is enabled for debugging |
mat_hdr_level 0/1/2 |
Adjusts the overall bright effect of HDR (0 = Off (LDR), 1 = LDR with Bloom, 2 = Enable HDR). This is also used to turn on/off HDR. Black Mesa has a third option, called "HDR Expanded", which set the mat_hdr_level value to "3". The "HDR Expanded" option can be only selected through the old game UI (VGUI, using -oldgameui launch option) or said console command. |
mat_hdr_manual_tonemap_rate 0.000000 |
Sets the tonemap rate. |
mat_hdr_tonemapscale 0.00000 |
Sets the tonemap scale |
mat_hdr_tonemapscaleMax 1-16 |
Sets the maximum scale |
mat_hdr_overbrightrange |
Sets an override parameter on HDR level for added adjustment. |
HDR effects
Seen not only in stock but also custom maps, some of these effects are used to trick the player or add even more detail toward an area.
Sprite glow
Env_sprite used to be for just lights. Really its main purpose was to add a small glow effect toward lights. Also, the old method of getting a glow was using env_glow which didn't work all too well. Now a new method to show light beaming in toward an area is using env_sprite like this:
Here it is used to multiply the amount of light preceding out of the lamp without having the main Light entity have a high brightness setting.
Another use for env_sprite
is to simulate the effects of strong amounts of light pouring from the outside into a closed in area. This tends to work great with dark areas as well.
Texture lighting
Another one of a HDR tech is mainly using textures that support or give off ambient light. This was used quite a lot in Episode 1 within the Citadel and acts as Bright white lighting within the citadel. Mainly the texture is lights/white004_nochop
. Mainly this texture can give off a nice glow with the aid of HDR, as seen in the picture.
Prop lighting
A few props have now been able to reflect and even cast light for an added effect. Many of them now don't even require lights any more to give off an effect that they are on. Now using HDR the light models glow and require less light entities. Meaning neither env_sprite
nor regular light entities are required anymore.
See also
- HDR Lighting Basics - general information on the subject.
- Sky List - a list of skyboxes (which also includes HDR-supported skyboxes), with their optimal settings.