Difference between revisions of "HDR Skybox Creation"

From Valve Developer Community
Jump to: navigation, search
(PFMs require a nocompress line in order to pass correctly through VTEX.)
(cleanup, explain $hdrbasetexture vs $hdrcompressedtexture)
Line 1: Line 1:
[[Image:Hdrskybox.jpg|170px|right|HDR skybox textures change considerably across exposures.]]
+
[[File:Skybox ldr hdr.jpg|thumb|HDR skyboxes (left) benefit from a range of brightness values.]]
  
An LDR (Low Dynamic Range) skybox is made up of six 24-bit images (front, left, back, right, up, and down). This data format is perfectly acceptable in LDR, but does not provide enough information to look good across a wide array of exposures, which is likely to happen when it is used in a [[HDR]]-lit environment.
+
Unlike most textures in a game, a [[skybox]] typically represents a collection of very large and very bright objects. '''This makes the need for [[high dynamic range]] imaging far more pressing.'''
  
Unlike most textures in a game a skybox typically represents very large 3D objects which behave very differently across different lighting conditions, making HDR imaging a far more pressing issue than normal.
+
HDR skyboxes are made with special [[VTF]]s containing 32-bit [[Float|floating point]] colour values (as opposed to the usual 8-bit [[int]]egers). These are created from Portable Float Map (.pfm) files by [[VTEX]].
  
An [[HDR]] (High Dynamic Range) skybox is a 32-bit floating-point format, saved by an application that supports HDR as a [[Wikipedia:Portable Float Map|Portable Float Map]]. It contains enough information to allow the resulting texture to change considerably across different [[Wikipedia:Exposure (photography)|exposures]].
+
== Creating PFMs ==
  
== Skies at different exposures ==
+
{{tip|VTFs can be decompiled to PFMs by [[vtf2tga]] (despite the name).}}
 +
 
 +
=== Skies at different exposures ===
  
 
Before creating a HDR skybox we need to know what the sky looks like at different exposures:
 
Before creating a HDR skybox we need to know what the sky looks like at different exposures:
Line 13: Line 15:
 
[[Image:hdr_sky_reference.jpg|700px|center|Photos of the sky at various exposures.]]
 
[[Image:hdr_sky_reference.jpg|700px|center|Photos of the sky at various exposures.]]
  
As you can see, the captured image changes as the exposure is altered. A single 24-bit image could never be used to create those effects: at 24-bit white is white, and the sun would only stand out if it was literally a different colour from the rest of the sky.
+
As you can see, the captured image changes as the exposure is altered. A single 8-bit image could never be used to create those effects: at 8-bit white is white, and the sun would only stand out if it was literally a different colour from the rest of the sky.
  
== Create a base skybox ==
+
=== Create a base skybox ===
  
 
First you need to create a basic skybox cube, as you would for an LDR skybox. See [[Skybox (2D)]].  
 
First you need to create a basic skybox cube, as you would for an LDR skybox. See [[Skybox (2D)]].  
Line 25: Line 27:
 
Save this assembled image as a TGA file. If you are prompted, do ''not'' use RLE compression and ''do'' place the origin at the bottom left.
 
Save this assembled image as a TGA file. If you are prompted, do ''not'' use RLE compression and ''do'' place the origin at the bottom left.
  
== Adding HDR data ==
+
=== Adding HDR data ===
  
 
We will now paint a sun into our skybox, which will behave in the same way as the 'exposures' photographs above. A good tool to use for this step is [http://gl.ict.usc.edu/HDRShop/download/HDRShop_92884/HDRShop.exe HDR Shop].
 
We will now paint a sun into our skybox, which will behave in the same way as the 'exposures' photographs above. A good tool to use for this step is [http://gl.ict.usc.edu/HDRShop/download/HDRShop_92884/HDRShop.exe HDR Shop].
Line 39: Line 41:
 
When you are finished, OK away the HDR Shop's dialogue and choose <code>File -> Save as...</code> and select the 'Portable Floatmap' format. Name and save this PFM file as you would a 2D skybox source image.
 
When you are finished, OK away the HDR Shop's dialogue and choose <code>File -> Save as...</code> and select the 'Portable Floatmap' format. Name and save this PFM file as you would a 2D skybox source image.
  
=== sdk_sky_exampleup ===
+
==== sdk_sky_exampleup ====
  
 
[[Image:Sdk sky exampleup.jpg|right|thumb|128px|sdk_sky_exampleup]]
 
[[Image:Sdk sky exampleup.jpg|right|thumb|128px|sdk_sky_exampleup]]
Line 49: Line 51:
 
Try adjusting the exposure up and down and you'll see that the sun is now integrated into the other exposures as well. Continue editing the different exposures until the desired result is achieved. It will be a good idea to spend some time emulating the blown-out effects around the sun and the highlights on the clouds as seen in the photographic reference.
 
Try adjusting the exposure up and down and you'll see that the sun is now integrated into the other exposures as well. Continue editing the different exposures until the desired result is achieved. It will be a good idea to spend some time emulating the blown-out effects around the sun and the highlights on the clouds as seen in the photographic reference.
  
== Creating the auxiliary skybox files ==
+
=== Split the skybox ===
 
 
{{warning|[[splitskybox]] Ep1 does not currently function. However, the OB version will work with either version of the engine.}}
 
 
 
The next stage is to create all the auxiliary skybox files: separate .PFM, .TXT, and .VMT files. A new application called <code>splitskybox.exe</code> was created to split the single .PFM skybox into the six separate files needed by the Source Engine. Copy a shortcut of the <code>Splitskybox.bat</code> (located in the <code>sourcesdk\bin\</code> directory) onto your desktop, then drag the .PFM file onto this shortcut.
 
 
 
  
Which should give you output similar to this:
+
If you created your skyboxes in a single file as in the above image, you will need to use <code>splitskybox.exe</code> to split it into six. Just drag the PFM onto it.
  
<pre>
+
{{note|[[splitskybox]] Ep1 does not currently function. However, the OB version will work with either version of the engine.}}
splitskybox.exe "C:\Program Files\Steam\SteamApps\username\sourcesdk_content\dod\materialsrc\skybox\sdk_sky_example_hdr.pfm"
 
  
filename: C:\Program Files\Steam\SteamApps\username\sourcesdk_content\dod\materialsrc\skybox\sdk_sky_example_hdrft.pfm
+
== Creating the materials ==
filename: C:\Program Files\Steam\SteamApps\username\sourcesdk_content\dod\materialsrc\skybox\sdk_sky_example_hdrlf.pfm
 
filename: C:\Program Files\Steam\SteamApps\username\sourcesdk_content\dod\materialsrc\skybox\sdk_sky_example_hdrbk.pfm
 
filename: C:\Program Files\Steam\SteamApps\username\sourcesdk_content\dod\materialsrc\skybox\sdk_sky_example_hdrrt.pfm
 
filename: C:\Program Files\Steam\SteamApps\username\sourcesdk_content\dod\materialsrc\skybox\sdk_sky_example_hdrup.pfm
 
filename: C:\Program Files\Steam\SteamApps\username\sourcesdk_content\dod\materialsrc\skybox\sdk_sky_example_hdrdn.pfm
 
Press any key to continue . . .
 
</pre>
 
  
When finished the content directory (e.g. <code>sdk_content\dod\materialsrc\skybox</code>) will include six new files based one the same name but appended with (ft, lf, bk, rt, up, and dn) this designates the different directions of the skybox (front, left, back, right, up, and down).
+
At this stage you should have six files:
  
Next, create six new .TXT files based on the new file names in the same directory. These .TXT files tell the Source Engine that the skybox is a .PFM file for compression reasons, and that the base exposure level matches '+0.00' in HDR Shop. If needed you can adjust the "pfmscale" so the base level is either higher or lower, but it is recommended to author skybox textures for a scale of 1.
+
*<code><skyname>'''ft'''.pfm</code>
 +
*<code><skyname>'''lf'''.pfm</code>
 +
*<code><skyname>'''bk'''.pfm</code>
 +
*<code><skyname>'''rt'''.pfm</code>
 +
*<code><skyname>'''up'''.pfm</code>
 +
*<code><skyname>'''dn'''.pfm</code>
  
With Notepad or another [[text editor]], create these files:
+
Make sure they are under <code>your_mod\materialsrc\skybox\</code>. You now need to create '''six corresponding TXT files''' (e.g. <code>MySkyft.txt</code>) alongside them, in order to compile to VTF. Each must contain:
* sdk_sky_example_hdr'''ft'''.txt
 
* sdk_sky_example_hdr'''lf'''.txt
 
* sdk_sky_example_hdr'''bk'''.txt
 
* sdk_sky_example_hdr'''rt'''.txt
 
* sdk_sky_example_hdr'''up'''.txt
 
* sdk_sky_example_hdr'''dn'''.txt
 
  
With the following text in each file:
+
<source lang=cpp>
<pre>
+
pfm 1 // Flag as HDR texture
"pfm" "1"
+
pfmscale 1 // Scales baseline brightness; lower is duller
"pfmscale" "1"
+
nocompress 1 // optional; halves filesize, in most cases without much loss
"nocompress" "1"
+
</source>
</pre>
 
  
Then, create six new .vmt files in the Game Directory (e.g. <code>day&nbsp;of&nbsp;defeat&nbsp;source\dod\materials\skybox</code>) and enter the following into each.
+
Drag these text files onto VTEX and it will compile them to VTF. (Unfortunately, [[VTFEdit]] doesn't import PFMs.)
  
{{note|The file names should all match depending upon the skybox side. These .VMT files are the same from standard, non-HDR Source skyboxes except that there is now a <code>$hdrbasetexture</code> field for HDR. The standard <code>$basetexture</code> field is used for the LDR skybox fallback.}}
+
The VTFs will appear in the corresponding materials subfolder (e.g. <code>your_mod\materials\skybox\</code>). Now you just need to create six VMTs there. These should contain:
  
* sdk_sky_example_hdr'''ft'''.vmt
+
<source lang=php>
<pre>
+
Sky
"sky"
 
 
{
 
{
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrft"
+
// if you compiled with nocompress:
    "$nofog" "1"
+
$hdrbasetexture "skybox/sdk_sky_example_hdrft"
    "$ignorez" "1"
 
    "$basetexture" "skybox/sdk_sky_exampleft"
 
}
 
</pre>
 
  
* sdk_sky_example_hdr'''lf'''.vmt
+
// if you didn't:
<pre>
+
$hdrcompressedtexture "skybox/sdk_sky_example_hdrft"
"sky"
 
{
 
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrlf"
 
    "$nofog" "1"
 
    "$ignorez" "1"
 
    "$basetexture" "skybox/sdk_sky_examplelf"
 
}
 
</pre>
 
  
* sdk_sky_example_hdr'''bk'''.vmt
+
$basetexture "skybox/sdk_sky_exampleft"
<pre>
+
$nofog 1
"sky"
+
$ignorez 1
{
 
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrbk"
 
    "$nofog" "1"
 
    "$ignorez" "1"
 
    "$basetexture" "skybox/sdk_sky_examplebk"
 
 
}
 
}
</pre>
+
</source>
  
* sdk_sky_example_hdr'''rt'''.vmt
+
=== Creating LDR fallbacks ===
<pre>
 
"sky"
 
{
 
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrrt"
 
    "$nofog" "1"
 
    "$ignorez" "1"
 
    "$basetexture" "skybox/sdk_sky_examplert"
 
}
 
</pre>
 
 
 
* sdk_sky_example_hdr'''up'''.vmt
 
<pre>
 
"sky"
 
{
 
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrup"
 
    "$nofog" "1"
 
    "$ignorez" "1"
 
    "$basetexture" "skybox/sdk_sky_example_01up"
 
}
 
</pre>
 
 
 
* sdk_sky_example_hdr'''dn'''.vmt
 
<pre>
 
"sky"
 
{
 
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrdn"
 
    "$nofog" "1"
 
    "$ignorez" "1"
 
    "$basetexture" "skybox/sdk_sky_exampledn"
 
}
 
</pre>
 
 
 
== Creating LDR fallbacks ==
 
  
The LDR fallback for the skybox will be based on the original six .TGA files that were used to create the HDR version.
+
You must also create standard low dynamic range VTFs for users who do not play in HDR. Compile with these settings:
  
Go ahead and save these six files into your content directory (e.g. <code>sdk_content\dod\materialsrc\skybox</code>):
+
<pre>dxt5 1
* sdk_sky_example'''ft'''.tga
+
skybox 1
* sdk_sky_example'''lf'''.tga
 
* sdk_sky_example'''bk'''.tga
 
* sdk_sky_example'''rt'''.tga
 
* sdk_sky_example'''up'''.tga
 
* sdk_sky_example'''dn'''.tga
 
 
 
Create these text files into the same directory (just like standard LDR skybox [[Material Creation|materials]]):
 
* sdk_sky_example'''ft'''.txt
 
* sdk_sky_example'''lf'''.txt
 
* sdk_sky_example'''bk'''.txt
 
* sdk_sky_example'''rt'''.txt
 
* sdk_sky_example'''up'''.txt
 
* sdk_sky_example'''dn'''.txt
 
 
 
With the following text in each file:
 
<pre>
 
"dxt5" "1"
 
"skybox" "1"
 
 
</pre>
 
</pre>
  
== Compiling the skybox ==
+
These are ordinary textures, so you can use [[VTFEdit]] if you prefer.
 
 
The final stage is to compile all these files so they can be used in the engine. Copy a shortcut of the <code>[[Vtex|vtex.exe]]</code> (from the <code>sourcesdk\bin\</code> directory) onto your desktop, then drag the following .TGA and .PFM files onto this shortcut. For a full description of how to compile textures, see [[Vtex]].
 
 
 
* sdk_sky_example_hdr'''ft'''.pfm
 
* sdk_sky_example_hdr'''lf'''.pfm
 
* sdk_sky_example_hdr'''bk'''.pfm
 
* sdk_sky_example_hdr'''rt'''.pfm
 
* sdk_sky_example_hdr'''up'''.pfm
 
* sdk_sky_example_hdr'''dn'''.pfm
 
  
* sdk_sky_example'''ft'''.tga
+
== Usage ==
* sdk_sky_example'''lf'''.tga
 
* sdk_sky_example'''bk'''.tga
 
* sdk_sky_example'''rt'''.tga
 
* sdk_sky_example'''up'''.tga
 
* sdk_sky_example'''dn'''.tga
 
  
If all went well, there should be 12 new .VTF files in your Game directory (e.g. <code>day&nbsp;of&nbsp;defeat&nbsp;source\dod\materials\skybox</code>) for a HDR skybox with a LDR fallback.
+
In Hammer, go to ''Main Menu > Map > Map Properties > Skybox Texture Name'' and type the name of your skybox, relative to <code>materials\skybox\</code> and without any of the face suffixes. (e.g. just <code>MySky</code>.)
  
 
== See also ==
 
== See also ==
  
 +
* <code>[[Sky (shader)|Sky]]</code>
 
* [[HDR Lighting Basics]] - How to add basic HDR lighting effects.
 
* [[HDR Lighting Basics]] - How to add basic HDR lighting effects.
 
* [[HDR Lighting Settings]] - Information on customizing HDR lighting settings.
 
* [[HDR Lighting Settings]] - Information on customizing HDR lighting settings.

Revision as of 22:32, 31 October 2010

HDR skyboxes (left) benefit from a range of brightness values.

Unlike most textures in a game, a skybox typically represents a collection of very large and very bright objects. This makes the need for high dynamic range imaging far more pressing.

HDR skyboxes are made with special VTFs containing 32-bit floating point colour values (as opposed to the usual 8-bit integers). These are created from Portable Float Map (.pfm) files by VTEX.

Creating PFMs

Tip:VTFs can be decompiled to PFMs by vtf2tga (despite the name).

Skies at different exposures

Before creating a HDR skybox we need to know what the sky looks like at different exposures:

Photos of the sky at various exposures.

As you can see, the captured image changes as the exposure is altered. A single 8-bit image could never be used to create those effects: at 8-bit white is white, and the sun would only stand out if it was literally a different colour from the rest of the sky.

Create a base skybox

First you need to create a basic skybox cube, as you would for an LDR skybox. See Skybox (2D).

With your images ready, arrange them in one large file as seen below. This step is required only if you are using the splitskybox tool. If you aren't then you are quite free to handle each texture separately.

Recommended skybox layout (labelled)

Save this assembled image as a TGA file. If you are prompted, do not use RLE compression and do place the origin at the bottom left.

Adding HDR data

We will now paint a sun into our skybox, which will behave in the same way as the 'exposures' photographs above. A good tool to use for this step is HDR Shop.

Note:When you open your TGA in HDR Shop you'll see a dialogue with a slider. Feel free to fiddle with it, but you'll probably want to leave things at their defaults.

HDR Shop works by taking files created by other image editors for different exposures and merging them together at 32-bit floating point. You can adjust the exposure you are working on with the + and - buttons on your keypad, or from the menu with View > Exposure. The current value is displayed in the lower-right corner of the screen.

When you've reached the exposure you are looking for, choose File -> Edit in image editor and you will get an image to edit. HDR Shop will open the image in your default BMP editor at this point, but you can use whatever tool you want so long as you're saving the right file.

There is a more detailed tutorial available on HDR Shop's website.

When you are finished, OK away the HDR Shop's dialogue and choose File -> Save as... and select the 'Portable Floatmap' format. Name and save this PFM file as you would a 2D skybox source image.

sdk_sky_exampleup

sdk_sky_exampleup

Let's do this with sourcesdk_content\dod\materialsrc\skybox\sdk_sky_exampleup.tga. Open it up and adjust the exposure to -3 stops, then edit the image externally. Now paint in a sun.

After returning to HDR Shop and OKing the dialogue, the current exposure level will be updated with the image that you just painted.

Try adjusting the exposure up and down and you'll see that the sun is now integrated into the other exposures as well. Continue editing the different exposures until the desired result is achieved. It will be a good idea to spend some time emulating the blown-out effects around the sun and the highlights on the clouds as seen in the photographic reference.

Split the skybox

If you created your skyboxes in a single file as in the above image, you will need to use splitskybox.exe to split it into six. Just drag the PFM onto it.

Note:splitskybox Ep1 does not currently function. However, the OB version will work with either version of the engine.

Creating the materials

At this stage you should have six files:

  • <skyname>ft.pfm
  • <skyname>lf.pfm
  • <skyname>bk.pfm
  • <skyname>rt.pfm
  • <skyname>up.pfm
  • <skyname>dn.pfm

Make sure they are under your_mod\materialsrc\skybox\. You now need to create six corresponding TXT files (e.g. MySkyft.txt) alongside them, in order to compile to VTF. Each must contain:

pfm 1 // Flag as HDR texture
pfmscale 1 // Scales baseline brightness; lower is duller
nocompress 1 // optional; halves filesize, in most cases without much loss

Drag these text files onto VTEX and it will compile them to VTF. (Unfortunately, VTFEdit doesn't import PFMs.)

The VTFs will appear in the corresponding materials subfolder (e.g. your_mod\materials\skybox\). Now you just need to create six VMTs there. These should contain:

Sky
{
	// if you compiled with nocompress:
	$hdrbasetexture		"skybox/sdk_sky_example_hdrft"

	// if you didn't:
	$hdrcompressedtexture	"skybox/sdk_sky_example_hdrft"

	$basetexture		"skybox/sdk_sky_exampleft"
	$nofog		1
	$ignorez	1
}

Creating LDR fallbacks

You must also create standard low dynamic range VTFs for users who do not play in HDR. Compile with these settings:

dxt5 1
skybox 1

These are ordinary textures, so you can use VTFEdit if you prefer.

Usage

In Hammer, go to Main Menu > Map > Map Properties > Skybox Texture Name and type the name of your skybox, relative to materials\skybox\ and without any of the face suffixes. (e.g. just MySky.)

See also

Environment articles:
Skies and environment maps Skybox (2D)Skybox (3D)HDR SkiesSkybox with TerragenSkybox with Terragen - AdvancedList of skies
Terrain and displacement mapping DisplacementsHoles in displacementsDigital Elevation Models