HDR Skybox Creation:ru

From Valve Developer Community
Revision as of 07:05, 14 August 2012 by Sodiet (talk | contribs) (Перевожу)
Jump to: navigation, search

Выгода HDR-Skybox (слева) в том, что они позволяют использовать более широкий диапазон яркости.

В отличие от большинства текстур в игре, Skybox представляет собой коллекцию больших и ярких объектов. Это делает HDR более актуальным.

VTF:ru текстуры используются HDR-Skybox для хранения цветов либо в слегка сжатых 16-битных значения с плавающей точкой с плавающей точкой (RGBA16161616f), либо в сильно сжатых 8-битных integer:ru (BGRA8888). В любом случае, они будут созданы VTEX:ru из несжатых 32-битных с плавающей точкой Portable Float Map (.pfm) файлов.

Tip.png Tip: Несжатые HDR VTF могут быть декомпилированы в PFM с помощью vtf2tga:ru. Не обращайте внимания на название программы.

Создание PFM

Tip.png Tip: 
Половина всего изображения
Поскольку нижнюю половину Skybox практически не видно, разумно отрезать "ненужную" часть. Для этого скомпилируйте стороны VTF с особой командой:
clamps 1
clampt 1

И добавьте её в материалы:

$basetexturetransform "center 0 0 scale 1 2 rotate 0 translate 0 0"

Поподробнее об использовании команд можно прочитать ниже, в подпункте "Создание материалов".

Небо с различной экспозицией

Перед созданием HDR-Skybox Вы должны запомнить, что небо выглядит в разных экспозициях:

Фотографии неба с различной экспозицией.

Как вы видите, захваченные изображения меняются в зависимости от экспозиции. 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):ru.

With your images ready, arrange them in one large file as seen below. This step is required only if you are using the splitskybox:ru 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.png 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.



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.png Note: splitskybox:ru Ep1 does not currently function. However, the OB version will work with either version of the engine.
Note.png Note: Left 4 Dead 2:ru Splitskybox is not a required step. And in fact will not work without lots of retyping of suffixes of multiple files. Left 4 Dead 2's iteration of VTEX:ru is able to take your "T" image array (both tga into LDR and pfm into HDR) and process it directly into the proper <name_bk>vtf format. In order to do this, create your "T" array as above. Recommended simply for the sake of sanity to get proper orientation for the top (and bottom if needed) images in your custom skybox. Create your txt file as normal and drag it onto Left 4 Dead 2's Vtex. Create materials and use in game as normal. A caveat here is, although the vtf files are compiled properly for LDR, if you are opting out of an HDR skybox and plan to use a LDR skybox only, the supplied LDR material template in the skybox_(2D):ru tutorial does not work. You will get the checkerboard pattern. I am still working on this problem. If you are trying to import an HDR skybox (meaning, if you rendered out a set of skybox textures in your external software, and then used HDRShop to create the hdr data) of a night sky, you will experience extreme banding in the darker areas which resemble dx compression. This banding is actually a result of the way HDRShop handles color information and can be observed directly in HDRShop if you adjust down the exposure and inspect your image. I am currently experimenting with solutions and will keep you posted.

Creating the materials

At this stage you should have six files:

  • <skyname>_hdrft.pfm
  • <skyname>_hdrlf.pfm
  • <skyname>_hdrbk.pfm
  • <skyname>_hdrrt.pfm
  • <skyname>_hdrup.pfm
  • <skyname>_hdrdn.pfm

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

pfm 1 // Flag as HDR texture
pfmscale 1 // brightness multiplier
nonice 1 // prevent seams appearing at low texture detail
nocompress 1 // optional; removing halves filesize, but causes color banding under close inspection

Drag these text files onto VTEX and it will compile them (unfortunately VTFEdit:ru 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 named <skyname>_hdr<face>.vmt. These should read:

	// 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"

Creating LDR fallbacks

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

nonice 1
dxt5 1 // or nocompress

These are ordinary textures, so you can use VTFEdit:ru if you prefer. There is no need to create new materials for LDR users; they will load the _hdr ones.


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 ModelsCreating custom terrain with Worldmachine