HDR Skybox Creation: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (updated compatability note)
(partial cleanup)
Line 1: Line 1:
[[Image:Ldrvshdr.jpg|thumb|200px|A Low Dynamic sky, compared to the same sky in High Dynamic.]]
[[Image:Hdrskybox.jpg|170px|right|HDR skybox textures change considerably across exposures.]]


An LDR (Low Dynamic Range) skybox is made up of six 24-bit [[TGA|targa (.tga)]] images (front, left, back, right, up, and down). This format does not contain enough information to look good when adjusted by large exposure values, and will not produce high contrast lightmaps and reflections. An [[HDR]] (High Dynamic Range) skybox is a 32-bit floating-point format, saved out from an application that supports HDR as a .[[PFM]] file. This format contains the multiple exposure information required for exposure adjustments, high contrast lightmaps, and reflections.
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.


{{note|The examples in this document assume you are creating an HDR skybox for Day of Defeat: Source. For other games, substitute the <code>day of defeat source/dod</code> in directory locations for the appropriate game directory of the game you are creating the skybox for. HDR is not supported in [[Half-Life 2]] or [[Half-Life 2: Deathmatch]].}}
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.


You should have a basic understanding of the [[material]] system and creating Source materials to use this information.
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]].


== Understanding the Sky at different exposures ==
== Skies at different exposures ==


[[Image:hdr_sky_reference.jpg|thumb|250px|An example of photos of the sky at various exposures. Click to enlarge.]]
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. The following images are a series of photos taken of the sky at different exposures. As you can see the sun is still bright even at the camera's fastest shutter speed&#8230;1/4000<sup>th</sup> of a second.<br style="clear:both">
[[Image:hdr_sky_reference.jpg|700px|center|Photos of the sky at various exposures.]]


== Create your base skybox ==
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.


First you need to create the base .TGA files that make your skybox cube. This is done using the same method as standard (LDR) skyboxes. See [[Skybox (2D)|Skybox (2D)]] for information on how to create base skybox materials.
== Create a base skybox ==


== Organize the skybox images into a single file ==
First you need to create a basic skybox cube, as you would for an LDR skybox. See [[Skybox (2D)]].


[[Image:hdr_skybox_sides.jpg|thumb|250px|An example skybox with labels for each side of the cube. Click to enlarge.]]
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.


Once you've made the base skybox images, use your image editing software to assemble the separate six .TGA sides into one large single .TGA file, as shown in this sample image. For demonstration purposes, text was inserted into this image to show which piece of the skybox should go into each position. If you add this text yourself, it will show up in-game when the skybox is compiled.
[[Image:hdr_skybox_sides.jpg|center|Recommended skybox layout (labelled)]]


The SDK includes this sample skybox. The .TGA files can be found in: <code>sdk_content\dod\materialsrc\skybox\sdk_sky_example_hdr.tga</code>
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.
<br style="clear:both">


== Edit and Save an HDR skybox ==
== Adding HDR data ==


The following will demonstrate the basic steps for painting a "sun" effect into the different exposures and saving the file as a .PFM. We'll use HDR Shop for this demonstration. The HDR Shop program can be downloaded from [http://gl.ict.usc.edu/HDRShop/ www.hdrshop.com]. After it is installed, launch the application, and then open the above .TGA you created above.
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].


When this window appears leave the default settings and Select '''OK''''.
{{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.}}


[[Image:hdrshop_curvedialog.png]]
HDR Shop works by taking files created by other [[Image Manipulation Programs|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 {{key|+}} and {{key|-}} buttons on your keypad, or from the menu with <code>View > Exposure</code>. The current value is displayed in the lower-right corner of the screen.


[[Image:hdrshop_adjustedsky.jpg|thumb|250px|The skybox after the response curve has been adjusted in HDR Shop. Click to enlarge.]]
When you've reached the exposure you are looking for, choose <code>File -> Edit in image editor</code> 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.


To paint the 'sun' into the skybox you must first choose an exposure to edit. The '+' and '-' keys are used to adjust the image exposure up and down. The lower right hand corner of the screen indicates the exposure level, '+0.00 stops' indicates the base exposure level that was imported into HDR Shop. Adjust the exposure level so it reads '-3.00 stops' Then, go to the menu: File -> Edit in [[image editor]]. The image-editing program you have associated with .BMP format will automatically open up this file as <code>HDRShopTEMP.bmp</code> Now paint the sun into this file.
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 finished save the image and return to HDR Shop.<br style="clear:both">
=== sdk_sky_exampleup ===


After clicking '''OK''' in this dialog, the current exposure level will be updated with the image that was just painted with the image-editing program.
[[Image:Sdk sky exampleup.jpg|right|thumb|128px|sdk_sky_exampleup]]


[[Image:hdrshop_OKdialog.png]]
Let's do this with <code>sourcesdk_content\dod\materialsrc\skybox\sdk_sky_exampleup.tga</code>. Open it up and adjust the exposure to -3 stops, then edit the image externally. Now paint in a sun.


[[Image:hdrshop_saveas.png|right]]
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 in HDR Shop with the '+' and '-' keys and you'll see that the sun is now integrated into the other exposures. 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.


When finished go to the '''File''' menu and choose '''Save as&#8230;''' and Select '''Portable Floatmap (.PFM)''' Save this file into your materialsrc content directory (e.g. <code>sdk_content\dod\materialsrc\skybox</code>).<br style="clear:both">
== Creating the auxiliary skybox files ==


== Creating the auxiliary skybox files ==
{{warning|[[splitskybox]] does not currently function (either ep1 or orangebox). You must save skyboxes faces as individual PFMs instead.}}
'''Note* The method descibed in the next step of this tutorial doesnt work, To achive finishing a HDR skybox for Source you must render out individual skyboxes as .pfm files as the splitskybox.exe does not function.'''


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

Revision as of 09:24, 6 June 2008

HDR skybox textures change considerably across exposures.

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 very large 3D objects which behave very differently across different lighting conditions, making HDR imaging a far more pressing issue than normal.

An HDR (High Dynamic Range) skybox is a 32-bit floating-point format, saved by an application that supports HDR as a Portable Float Map. It contains enough information to allow the resulting texture to change considerably across different exposures.

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

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.pngNote: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.

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.

Creating the auxiliary skybox files

Warning.pngWarning:splitskybox does not currently function (either ep1 or orangebox). You must save skyboxes faces as individual PFMs instead.

The next stage is to create all the auxiliary skybox files: separate .PFM, .TXT, and .VMT files. A new application called splitskybox.exe was created to split the single .PFM skybox into the six separate files needed by the Source Engine. Copy a shortcut of the Splitskybox.bat (located in the sourcesdk\bin\ directory) onto your desktop, then drag the .PFM file onto this shortcut.


Which should give you output similar to this:

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

When finished the content directory (e.g. sdk_content\dod\materialsrc\skybox) 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).

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.

With Notepad or another text editor, create these files:

  • sdk_sky_example_hdrft.txt
  • sdk_sky_example_hdrlf.txt
  • sdk_sky_example_hdrbk.txt
  • sdk_sky_example_hdrrt.txt
  • sdk_sky_example_hdrup.txt
  • sdk_sky_example_hdrdn.txt

With the following text in each file:

"pfm" "1"
"pfmscale" "1"

Then, create six new .vmt files in the Game Directory (e.g. day of defeat source\dod\materials\skybox) and enter the following into each.

Note.pngNote: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 $hdrbasetexture field for HDR. The standard $basetexture field is used for the LDR skybox fallback.
  • sdk_sky_example_hdrft.vmt
"sky"
{
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrft"
    "$nofog" "1"
    "$ignorez" "1"
    "$basetexture" "skybox/sdk_sky_exampleft"
}
  • sdk_sky_example_hdrlf.vmt
"sky"
{
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrlf"
    "$nofog" "1"
    "$ignorez" "1"
    "$basetexture" "skybox/sdk_sky_examplelf"
}
  • sdk_sky_example_hdrbk.vmt
"sky"
{
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrbk"
    "$nofog" "1"
    "$ignorez" "1"
    "$basetexture" "skybox/sdk_sky_examplebk"
}
  • sdk_sky_example_hdrrt.vmt
"sky"
{
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrrt"
    "$nofog" "1"
    "$ignorez" "1"
    "$basetexture" "skybox/sdk_sky_examplert"
}
  • sdk_sky_example_hdrup.vmt
"sky"
{
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrup"
    "$nofog" "1"
    "$ignorez" "1"
    "$basetexture" "skybox/sdk_sky_example_01up"
}
  • sdk_sky_example_hdrdn.vmt
"sky"
{
    "$hdrbaseTexture" "skybox/sdk_sky_example_hdrdn"
    "$nofog" "1"
    "$ignorez" "1"
    "$basetexture" "skybox/sdk_sky_exampledn"
}

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.

Go ahead and save these six files into your content directory (e.g. sdk_content\dod\materialsrc\skybox):

  • sdk_sky_exampleft.tga
  • sdk_sky_examplelf.tga
  • sdk_sky_examplebk.tga
  • sdk_sky_examplert.tga
  • sdk_sky_exampleup.tga
  • sdk_sky_exampledn.tga

Create these text files into the same directory (just like standard LDR skybox materials):

  • sdk_sky_exampleft.txt
  • sdk_sky_examplelf.txt
  • sdk_sky_examplebk.txt
  • sdk_sky_examplert.txt
  • sdk_sky_exampleup.txt
  • sdk_sky_exampledn.txt

With the following text in each file:

"dxt5" "1"
"skybox" "1"

Compiling the skybox

The final stage is to compile all these files so they can be used in the engine. Copy a shortcut of the vtex.exe (from the sourcesdk\bin\ 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_hdrft.pfm
  • sdk_sky_example_hdrlf.pfm
  • sdk_sky_example_hdrbk.pfm
  • sdk_sky_example_hdrrt.pfm
  • sdk_sky_example_hdrup.pfm
  • sdk_sky_example_hdrdn.pfm
  • sdk_sky_exampleft.tga
  • sdk_sky_examplelf.tga
  • sdk_sky_examplebk.tga
  • sdk_sky_examplert.tga
  • sdk_sky_exampleup.tga
  • sdk_sky_exampledn.tga

If all went well, there should be 12 new .VTF files in your Game directory (e.g. day of defeat source\dod\materials\skybox) for a HDR skybox with a LDR fallback.

See also

Environment articles:
Skies and environment maps Source Source: Skybox (2D)Skybox (3D)HDR SkiesSkybox with TerragenSkybox with Terragen - AdvancedList of skies


Source 2 Source 2: Skybox (3D)

Terrain and displacement mapping DisplacementsCreating Holes in DisplacementsDigital Elevation ModelsCreating custom terrain with Worldmachine