Advanced HDR: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
 
(87 intermediate revisions by 23 users not shown)
Line 1: Line 1:
== '''Advanced HDR''' ==
== HDR and exposure adjustment ==
This is a tutorial that will take some time to create but will give a better insight of the effects, modes, and different aspects of HDR through the Source Engine. Also this page is meant as a simple guide on orchestrating HDR effects and implementing them in to your map.
As showcased in [[Half-Life 2: Lost Coast|Lost Coast]] - a simple tech demo - '''[[HDR|High Dynamic Range]]''' rendering ('''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 [[Inputs and Outputs|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, with HDR later become a requirement in all games built on {{l4dbranch|4}} or later engine branch, so all new maps should come with HDR-baked lighting. HDR rendering should not be confused with HDR display output.


=== Games with HDR support ===
== Lost Coast example ==
So far these are the only games that support HDR:
[[File:D2 lostcoast0000.jpg|thumb|250px|Before entering the dark area.]]
*Half-Life 2 Episode 1
[[File:D2 lostcoast0001.jpg|thumb|250px|Now that the player is in the dark hall, the outside area appears overly bright due to eye adjustment.]]
*Day of Defeat:Source
[[File:D2 lostcoast0002.jpg|thumb|250px|The player's eyes haven't adjusted yet.]]
*Counter-Strike:Source
[[File:D2 lostcoast0003.jpg|thumb|250px|Now the player's eyes have adjusted.]]
*Lost Coast
*Now mods support HDR due to the new engine update


{{note|Half-Life 2 does not support HDR therefore if you are creating a map and want to run it in [[HDR]] it must run under [[EP1]] or one of the other listed games.}}
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.


=== What is HDR? ===
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:
As showcased in Lost Coast - a simple tech demo, HDR is a new lighting method that allows a monitor to go over its ideal brightness or in other words the games color scale to make lighting appear more realistic. In that sense it's now giving the player "virtual eyes" as it has been put by Valve in the tech demo. Mainly with the aid of an [[env_tonemap_controller]], lighting can be adjusted so when players step into dark non-lit areas, the area will brighten up to allow the player to see better. When the player steps out of that area, he or she walks in to a overly bright light filled area to give the effect that the player's "virtual eyes" pupils are adjusting to the exposure and large amount of light.
 
==== Lost Coast example ====
[[Image:D2 lostcoast0000.jpg|thumb|250px|Before entering the dark area.]]
[[Image:D2 lostcoast0001.jpg|thumb|250px|Now that the player is in the darkened hall the outside area appears overly bright due to eye adjustment]]
[[Image:D2 lostcoast0002.jpg|thumb|250px|Wow that's quite bright isn't it?]]
[[Image:D2 lostcoast0003.jpg|thumb|250px|Well that's better! Now the player's virtual eyes have adjusted.]]
In the first screenshot you can see the player standing outside a dark hallway. Mainly here is where the [[env_tonemap_controller]] comes in! It takes care of the auto exposure, minimum and maximum as well as bloom settings for the over-bright effect that you see in the third screenshot. Right now the tonemap controller has its main autoexposure max set to <code>1</code> and its minimum exposure set to <code>.9</code>, while its bloom scale is set to <code>1</code>.
 
Now when the player walks into the tunnel he triggers a [[trigger_multiple]] Brush based entity. Its outputs are as follows:


* <code>SetAutoExposureMax: 6.0</code>
* <code>SetAutoExposureMax: 6.0</code>
* <code>SetAutoExposureMin: 2.0</code>
* <code>SetAutoExposureMin: 2.0</code>
* <code>SetAutoBloomScale: &nbsp;1.6</code>
* <code>SetBloomScale: &nbsp;1.6</code>


All these settings cause the tonemap controller to change different parameters and cause the suns brightness and mainly the HDR lighting to be more brighter than before, and keeps the settings at that rate for a while till the player leaves the brush based trigger area.
All these settings cause the tonemap controller to adjust different exposure parameters in real time, and if <code>AutoExposureMin</code>, <code>AutoExposureMax</code>, and <code>BloomScale</code>'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 <code>OnStartTouch</code> and <code>OnEndTouch</code>.


The effects are applied in this way with the use of the <code>OnStartTouch</code> and <code>OnEndTouch</code> outputs.
When the player enters the trigger area the new settings of the [[env_tonemap_controller]] are applied by the output <code>OnStartTouch</code>, and then set back to the previous settings
with the <code>OnEndTouch</code> output, when the player exits that area.


When the player enters the trigger area the [[env_tonemap_controller]] is triggered with the new settings by the output <code>OnStartTouch</code> and then set back to the previous settings
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.
with the <code>OnEndTouch</code> output.


In the third screenshot the player walks out of the tunnel and then sees the large amount of light being casted. At this time the players "virtual eyes" are being adjusted, and then finally in the final screenshot return back to normal.
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 <code>env_tonemap_controller</code>, 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 <code>0</code> on all exposure and bloom parameters.


The tonemap controller is mainly commanded by a [[trigger_multiple]] and given its default settings by the [[logic_auto]] entity. When the map begins, outputs can be sent to the tonemap controller and at that time the tonemap controller changes the lighting parameters. Also throughout the Lost Coast map there are other many riggers the player walks through that cause the ideal brightness to change and rearrange all the exposure settings around. However if a map does not contain a <code>env_tonemap_controller</code> then really the HDR effect will be a bit random. Continuously dimming the screen and brightening it up at random times or even when the player steps into a area thats just a tad brighter than the past one. In other words the HDR settings end up acting funny towards the map and HDR is set to its default settings of <code>0</code> 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.)
{{note| With the Release of the Orange Box Engine, Valve has improved tonemapping capabilities for smaller and less dramatic sources of exposure, apart from the skybox. Those sources inlcude sprites, spotlights, and even self-illuminating materials.}}


On a main note though, each map requires different settings even if using the same skybox material. Of course changing the settings and keeping them the same is okay. Mainly though the only reason you might need to change the settings are to really attain or create a certain effect towards the area the player is in currently. Even if it is just for a few seconds. Depending on the amount of over bright effects in your map or even having HDR seem very low still require parameters, so in turn the best idea is really to tinker around with your map till you get just the right setting that fits and once again if the settings don't seem to fit in a certain area you can always create [[trigger_multiple]] volumes around the areas the player needs to travel into that will change the settings and correct any mistakes, or get the lighting just right. The tonemap controller, however does not add more brightness to the area though, those controls still need to be set to the current light entity. In fact it just gives lighting the HDR effect or really a brighter glow but as mentioned does ''not'' add more brightness or lighting towards the area. Each light entity has its own HDR brightness parameter which must be set as the overall HDR brightness.


Here is a little example of the effects of a tone map controller in a different environment:
Here is an example of the effects of a tonemap controller on different environments:
[[Image:Ep1 citadel 000001.jpg|thumb|left|300px|With the tonemap controller settings on.]]
[[File:Ep1 citadel 000001.jpg|thumb|left|250px|With the tonemap controller settings on.]]
[[Image:Ep1 citadel 000002.jpg|thumb|left|300px|With the settings off.]]
[[File:Ep1 citadel 000002.jpg|thumb|left|250px|With the settings off.]]
<br clear="left" />
<br clear="left" />


Valve implemented the <code>env_tonemap_controller</code> to better control the ideal bright effect of the sun so it's not overly bright, i.e. unrealistic. Also, they gave the sun an effect with the existing fog in the map, by changing a few settings and giving a bit of a more-than-normal brightness to appear layered by the fog.
Valve implemented the <code>env_tonemap_controller</code> 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.


One other thing is mainly the inside corridors of the Citadel which also use the [[env_tonemap_controller]] to adjust the sensitivity levels seen in a screenshot below located in Material lighting.
Another use of <code>env_tonemap_controller</code> 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 this process through a step by step guide.
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 HDR map ==
[[Image:Hammer-env_tonemap_controll.gif|thumb|250px| All required entities are placed near the player. Note, fog_controller isn't needed.]]
[[File:hammer_hdrlight_ents.png|thumb|250px| All required entities are placed near the player. Note, [[env_fog_controller]] isn't needed.]]
[[Image:Logic auto.gif|thumb|250px|A logic_auto to control the tonemap_controller.]]
[[File:hammer_tonemap_logic_auto_hdr.png|thumb|250px|A <code>logic_auto</code> to control the [[env_tonemap_controller]].]]
Now as to creating a map with HDR in it isn't too hard yet requires some entity's as well as customization towards the [[env_tonemap_controller]] as noted above with the [[Logic_auto]] entity.
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 things first. Place a [[env_tonemap_controller]] in the map. The entity needs to be in the map but as location does not effect anything. Mainly some mappers as well as some of valves maps tend to have the [[env_tonemap_controller]] at the start of the level near the player included with the main entities for better organization purposes and clarity.
* 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 <code>tonemap_controller</code>
* 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 <code>tonemap_controller</code>
*Next step is creating a [[Logic_auto]]. Once placed open up its properties and go straight to the "Outputs" tab.
* The next step is creating a [[logic_auto]]. Once placed open up its properties and go straight to the "Outputs" tab.
*One of the main things needed for the [[env_tonemap_controller]] to work is outputs sent towards it then received as inputs by the <code>tonemap_controller</code>. 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 require different settings.
* 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 now with the outputs tab open create a new output.
* 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 <code>tonemap_controller</code> about the max auto exposure and here is how it goes. The second output is going to send a message concerning the minimum auto exposure.
The first output is going to send a message to the <code>tonemap_controller</code> about the maximum auto exposure and the second output is going to send a message regarding the minimum auto exposure.


<table>
<table>
<tr>
<tr>
  <th>My Output</th>
  <th>My output named</th>
  <th>Target Entity</th>
  <th>Target entity</th>
  <th>Target Input</th>
  <th>Via this input</th>
  <th>Parameter</th>
  <th>Parameter</th>
  <th>Delay</th>
  <th>Delay</th>
  <th>Only Once</th>
  <th>Only once</th>
</tr>
</tr>
<tr>
<tr>
Line 77: Line 65:
  <td>tonemap_controller &nbsp;</td>
  <td>tonemap_controller &nbsp;</td>
  <td>SetAutoExposureMax &nbsp;</td>
  <td>SetAutoExposureMax &nbsp;</td>
  <td>4 &nbsp;</td>
  <td>2 &nbsp;</td>
  <td>0.00 &nbsp;</td>
  <td>0.00 &nbsp;</td>
  <td>No &nbsp;</td>
  <td>No &nbsp;</td>
Line 84: Line 72:
{{note|In the above example, remember to replace the entity names with your own.}}
{{note|In the above example, remember to replace the entity names with your own.}}


Although not the simplest thing, HDR isn't a very hard technique to work with however it deals a large amount of time to the compile process. In fact, <code>vrad</code> must run twice. Once for LDR and the second time for HDR. The first thing in creating an HDR map is of course a HDR sky texture. See this page [[Sky_List|here]] for a list of sky's in HDR as well as ideal parameters for them.
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, <code>vrad</code> 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 [[Sky_List|this]] page for a list of skyboxes which support HDR as well as the ideal lighting parameters for them.
{{tip|CS:GO, Episode 2 and Black Mesa all have HDR skyboxes, so if you need some good HDR-baked sky textures, you could import the textures from those games into your mod or the custom files directory for the game you're working with. Alternatively, there are a lot of HDR skybox textures in public online modding websites such as GameBanana.}}
 
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.


Once you've picked one out open the map menu located on the top right of Hammer then go to map properties. On the properties panel set the skybox material name to the skybox texture name field. Now click apply.
{{note|CS:GO maps automatically compile with HDR. Do not alter the <code>HDR Brightness</code> 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!)}}


Mainly aside from that HDR maps aren't to hard to create. In fact you need to fill in the HDR brightness field on a light entity's properties panel and that's about it. Mainly 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 <code>100</code> then HDR should be set to <code>50</code>. 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 <code>-final</code> or HDR <code>-final -fast</code>. 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!
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 <code>100</code> then HDR should be set to <code>50</code>. 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 <code>-final</code> or HDR <code>-final -fast</code>. 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!


{{note|Don't forget to adjust the <code>HDR Brightness</code> property of your <code>light_environment</code> entity.}}
{{note|Don't forget to adjust the <code>HDR Brightness</code> property of your <code>light_environment</code> entity.}}


== '''Running a HDR map''' ==
== Running a HDR map ==
Now that the compile process has finished in-game open up your console and type in <code>buildcubemaps</code>. 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 <code>mat_hdr_enable 0</code> in the console to disable HDR and return to LDR. Now simply <code>buildcubemaps</code> again. You're done! The game will return automatically to HDR so theres no more console commands needed. Through the console however you can change around the exposure levels of the <code>env_tonemap_controller</code>.  
Now that the compile process has finished in-game, [[Cubemaps#Before_building|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 you have follow instructions on building cubemaps page and built both LDR & HDR cubemaps, type {{code|disconnect}} to return to menu, then {{code|mat_hdr_level 0}} in the console to disable HDR (back to LDR), or {{code|mat_hdr_level 2}} to enable/re-enable HDR.


The following console commands are currently available for HDR:
The following console commands are currently available for HDR:
<table>
{| class="wikitable"
<tr>
|-
<th>Prefix</th>
! Command !! Description
<th>Location</th>
|-
</tr>
| <code>building_cubemaps 0/1</code>
<tr>
| This command caps the exposure to default value, making it more consistent when enabled, and is often used to building cubemaps in HDR. Without it enabled before building cubemaps, HDR cubemaps will appear overexposed/brighter or underexposed/darker than usual.
<td><code>mat_autoexposure_min</code></td>
|-
<td>Minimum exposure settings.</td>
| <code>mat_autoexposure_min</code>
</tr>
| Minimum exposure settings.
<tr>
|-
<td><code>mat_autoexposure_max</code></td>
| <code>mat_autoexposure_max</code>
<td>Maximum exposure settings.</td>
| Maximum exposure settings.
</tr>
|-
<tr>
| <code>mat_hdr_enable 0/1</code>
<td><code>mat_hdr_enable 0/1</code></td>
| [[Boolean]] command which disables or enable HDR.{{Important|For {{src06|1}}: We recommend you using {{code|mat_hdr_level}} command instead to disable/enable HDR.}}{{ModernDeprecated|Removed in {{src07|4}}. Use {{code|mat_hdr_level}} instead.}}
<td>0 Turns off HDR, 1 turns HDR on.</td>
|-
</tr>
| <code>mat_hdr_enabled</code>
<tr>
| {{since|{{src07|4}}}} Report if HDR is enabled for debugging
<td><code>mat_hdr_level 0/1/2</code></td>
|-
<td>Adjusts the overall bright effect of HDR.</td>
| <code>mat_hdr_level 0/1/2</code>
</tr>
| [[File:Source_HDR_comparison.jpg|320px|right|LDR, LDR with Bloom and HDR comparison.]] Switches between LDR (0), LDR with Bloom (1) or HDR (2).<br>{{Bms|2}} (and early {{src07|1}} games) has a third option, called "'''HDR Expanded'''", which set the {{code|mat_hdr_level}} value to "3". The "HDR Expanded" option can be only selected through the old game UI (VGUI, using {{code|-oldgameui}} [[Launch options|launch option]]) or said console command.</br>{{Sfm|2}} also use {{code|mat_hdr_level 3}} by default.
<tr>
|-
<td><code>mat_hdr_manual_tonemap_rate 0.000000</code></td>
| <code>mat_hdr_manual_tonemap_rate 0.000000</code>
<td>Sets the tonemap rate.</td>
| Sets the tonemap rate.
</tr>
|-
<tr>
| <code>mat_hdr_tonemapscale 0.00000</code>
<td><code>mat_hdr_tonemapscale 0.00000</code></td>
| Sets the tonemap scale
<td>Sets the tonemap scale</td>
|-
</tr>
| <code>mat_hdr_tonemapscaleMax 1-16</code>
<tr>
| Sets the maximum scale
<td><code>mat_hdr_tonemapscaleMax 1-16</code></td>
|-
<td>Sets the maximum scale</td>
| <code>mat_hdr_overbrightrange</code>
</tr>
| Sets an override parameter on HDR level for added adjustment.
<tr>
|-
<td><code>mat_hdr_overbrightrange</code></td>
|}
<td>Sets an override parameter on HDR level for added adjustment.</td>
</tr>
</table>
 
{{note|When building cubemaps in HDR it might take a bit longer due to the HDR lightmaps. Thats completely normal so just be patient!}}


== '''HDR effects''' ==
== 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.
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 ===
=== 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 to well. Now a new method to show light beaming in toward an area is using [[env_sprite]] like this:
[[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.  
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 <code>env_sprite</code> is to simulate the effects of strong amounts of light poring from the outside into a closed in area. This tends to work great with dark areas as well.
Another use for <code>env_sprite</code> 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.


[[Image:C17 city day 020000.jpg|thumb|left|250px|An env_sprite from far away.]]
[[File:C17 city day 020000.jpg|thumb|left|250px|An env_sprite from far away.]]
[[Image:C17 city day 020002.jpg|thumb|left|250px|Used as the light pouring in from outside.]]
[[File:C17 city day 020002.jpg|thumb|left|250px|Used as the light pouring in from outside.]]
[[Image:C17 city day 020001.jpg|thumb|left|250px|The env_sprite up close.]]
[[File:C17 city day 020001.jpg|thumb|left|250px|The env_sprite up close.]]
<br clear="left" />
<br clear="left" />


=== Texture lighting ===
=== 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 <code>lights/white004_nochop</code>. Mainly this texture can give off a nice glow with the aid of HDR. Heres how it looks:
[[File:Ep1 citadel 010003.jpg|thumb|right|250px|Inside the Citadel.]]
 
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 <code>lights/white004_nochop</code>. Mainly this texture can give off a nice glow with the aid of HDR, as seen in the picture.
[[Image:Ep1 citadel 010003.jpg|thumb|left|300px|Inside the Citadel.]]
<br clear="left" />


=== Prop lighting ===
=== Prop lighting ===
A few props now have 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 entity's. Meaning neither <code>env_sprite</code> nor regular [[light]] entities are required anymore.
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 <code>env_sprite</code> nor regular [[light]] entities are required anymore.


== See also ==
== See also ==
* [[HDR Lighting Basics]] - general information on the subject.
* [[HDR Lighting Basics]] - general information on the subject.
* [[Sky List]] - a list of HDR-supported skyboxes, and their values.
* [[Sky List]] - a list of skyboxes (which also includes HDR-supported skyboxes), with their optimal settings.
 
[[Category:Level Design]][[Category:HDR]]

Latest revision as of 07:14, 30 April 2025

HDR and exposure adjustment

As showcased in Lost Coast - a simple tech demo - High Dynamic Range rendering (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, with HDR later become a requirement in all games built on Left 4 Dead engine branch Left 4 Dead engine branch or later engine branch, so all new maps should come with HDR-baked lighting. HDR rendering should not be confused with HDR display output.

Lost Coast example

Before entering the dark area.
Now that the player is in the dark hall, the outside area appears overly bright due to eye adjustment.
The player's eyes haven't adjusted yet.
Now the player's eyes have adjusted.

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.)

Note.pngNote: With the Release of the Orange Box Engine, Valve has improved tonemapping capabilities for smaller and less dramatic sources of exposure, apart from the skybox. Those sources inlcude sprites, spotlights, and even self-illuminating materials.


Here is an example of the effects of a tonemap controller on different environments:

With the tonemap controller settings on.
With the settings off.


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

All required entities are placed near the player. Note, env_fog_controller isn't needed.
A logic_auto to control the env_tonemap_controller.

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  
Note.pngNote:In the above example, remember to replace the entity names with your own.

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.

Tip.pngTip:CS:GO, Episode 2 and Black Mesa all have HDR skyboxes, so if you need some good HDR-baked sky textures, you could import the textures from those games into your mod or the custom files directory for the game you're working with. Alternatively, there are a lot of HDR skybox textures in public online modding websites such as GameBanana.

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.

Note.pngNote:CS:GO maps automatically compile with HDR. Do not alter the 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!

Note.pngNote:Don't forget to adjust the 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 you have follow instructions on building cubemaps page and built both LDR & HDR cubemaps, type disconnect to return to menu, then mat_hdr_level 0 in the console to disable HDR (back to LDR), or mat_hdr_level 2 to enable/re-enable HDR.

The following console commands are currently available for HDR:

Command Description
building_cubemaps 0/1 This command caps the exposure to default value, making it more consistent when enabled, and is often used to building cubemaps in HDR. Without it enabled before building cubemaps, HDR cubemaps will appear overexposed/brighter or underexposed/darker than usual.
mat_autoexposure_min Minimum exposure settings.
mat_autoexposure_max Maximum exposure settings.
mat_hdr_enable 0/1 Boolean command which disables or enable HDR.
Icon-Important.pngImportant:For Source 2006: We recommend you using mat_hdr_level command instead to disable/enable HDR.
Obsolete-notext.pngDeprecated:Removed in Source 2007 Source 2007. Use mat_hdr_level instead.
mat_hdr_enabled (in all games since Source 2007 Source 2007) Report if HDR is enabled for debugging
mat_hdr_level 0/1/2
LDR, LDR with Bloom and HDR comparison.
Switches between LDR (0), LDR with Bloom (1) or HDR (2).
Black Mesa Black Mesa (and early Source 2007 games) 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.
Source Filmmaker Source Filmmaker also use mat_hdr_level 3 by default.
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.

An env_sprite from far away.
Used as the light pouring in from outside.
The env_sprite up close.


Texture lighting

Inside the Citadel.

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.