Difference between revisions of "Sky (shader)"

From Valve Developer Community
Jump to: navigation, search
(Update to include information on $hdrbasetexture and more code examples)
Line 1: Line 1:
'''Sky''' is a shader for materials in [[Source]] meant for [[Skybox_(2D)|2D skyboxes]]. The old method of making skyboxes before [[Source 2007]] involved using the [[UnlitGeneric]] shader with <code>[[$ignorez]] 1</code>. This shader expands the amount of usable parameters and also allows for HDR skyboxes.
+
'''Sky''' is a shader for materials in [[Source]] meant for [[Skybox_(2D)|2D skyboxes]]. The old method of making skyboxes before [[Source 2007]] involved using the [[UnlitGeneric]] shader with <code>[[$ignorez|$ignorez 1]]</code>. This shader expands the amount of usable parameters and also allows for [[HDR]] skyboxes.
 +
 
 +
=== With an HDR Compressed Skybox Texture ===
  
 
Most of the time, VMTs should only exist for [[High Dynamic Range|HDR]] skyboxes that have an LDR fallback. An example of an HDR skybox with a fallback will look like this:
 
Most of the time, VMTs should only exist for [[High Dynamic Range|HDR]] skyboxes that have an LDR fallback. An example of an HDR skybox with a fallback will look like this:
  
 
<source lang=vmt>
 
<source lang=vmt>
"sky"
+
sky
 +
{
 +
$basetexture skybox/sky_wasteland_00up // Sky texture to use for LDR
 +
$hdrcompressedtexture skybox/sky_wasteland_00_hdrup // HDR-compressed Sky texture to use for HDR-enabled maps
 +
$nofog 1
 +
$ignorez 1
 +
$nomip 1
 +
}
 +
</source>
 +
 
 +
=== Without an HDR Compressed Skybox Texture ===
 +
 
 +
When an HDR skybox is needed for a texture that has '''''not''''' been compiled for HDR, an alternative command is used instead of [[$hdrcompressedtexture]]: [[$hdrbasetexture|*$hdrbasetexture*]].
 +
 
 +
<source lang=vmt>
 +
sky
 
{
 
{
"$hdrcompressedTexture" "skybox/sky_wasteland_00_hdrup"
+
$basetexture skybox/sky_wasteland_00up // Sky texture to use for LDR
"$nofog" "1"
+
$hdrbasetexture skybox/sky_wasteland_00up // Sky texture to use for HDR, if the texture has NOT been specifically compiled for HDR
"$ignorez" "1"
+
$nofog 1
"$basetexture" "skybox/sky_wasteland_00up"          // VMT will load this VTF instead if not running in HDR.
+
$ignorez 1
"$basetexturetransform" "center 0 0 scale 1 2 rotate 0 translate 0 0"          // For cutting off the bottom halves of the skybox
+
$nomip 1
 
}
 
}
 
</source>
 
</source>
 +
 +
=== Issues ===
 +
 +
You might find that skyboxes sometimes fit the entire projection area of a level. To re-scale the material to fit, use [[$basetexturetransform]] or add the following line:
 +
<source lang=vmt>
 +
$basetexturetransform "center 0 0 scale 1 2 rotate 0 translate 0 0" // For cutting off the bottom halves of the skybox
 +
</source>
 +
 +
The <code>scale 1 2</code> segment will maintain the fill-sizing of the X-axis, while locking the texture to the center line of the Y-axis (i.e. the absolute horizon line).
 +
 
[[Category:Shaders]]
 
[[Category:Shaders]]

Revision as of 06:01, 17 December 2019

Sky is a shader for materials in Source meant for 2D skyboxes. The old method of making skyboxes before Source 2007 involved using the UnlitGeneric shader with $ignorez 1. This shader expands the amount of usable parameters and also allows for HDR skyboxes.

With an HDR Compressed Skybox Texture

Most of the time, VMTs should only exist for HDR skyboxes that have an LDR fallback. An example of an HDR skybox with a fallback will look like this:

sky
{
	$basetexture skybox/sky_wasteland_00up // Sky texture to use for LDR
	$hdrcompressedtexture skybox/sky_wasteland_00_hdrup // HDR-compressed Sky texture to use for HDR-enabled maps
	$nofog 1
	$ignorez 1
	$nomip 1
}

Without an HDR Compressed Skybox Texture

When an HDR skybox is needed for a texture that has not been compiled for HDR, an alternative command is used instead of $hdrcompressedtexture: *$hdrbasetexture*.

sky
{
	$basetexture skybox/sky_wasteland_00up // Sky texture to use for LDR
	$hdrbasetexture skybox/sky_wasteland_00up // Sky texture to use for HDR, if the texture has NOT been specifically compiled for HDR
	$nofog 1
	$ignorez 1
	$nomip 1
}

Issues

You might find that skyboxes sometimes fit the entire projection area of a level. To re-scale the material to fit, use $basetexturetransform or add the following line:

	$basetexturetransform "center 0 0 scale 1 2 rotate 0 translate 0 0" // For cutting off the bottom halves of the skybox

The scale 1 2 segment will maintain the fill-sizing of the X-axis, while locking the texture to the center line of the Y-axis (i.e. the absolute horizon line).