Parallax mapping: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Soyka moved page Parallax mapping to Parallax mapping/en: MultiPage)
(Formatting update)
Line 1: Line 1:
{{Language subpage}}
[[Image:parallax_mapping.jpg|thumb|400px|Example of parallax mapping.]]
[[Image:parallax_mapping.jpg|thumb|400px|Example of parallax mapping.]]
{{warning|Parallax maps are disabled in every Valve game, although since {{as}} an (unfinished) shader exists named [[ParallaxTest]], which can be used as an alternative.}}
{{warning|Parallax maps are disabled in every Valve game, although since {{as}} an (unfinished) shader exists named {{Shader_Name|ParallaxTest}}, which can be used as an alternative.}}
{{note|This '''downloadable''' shader only works in the Episode 1 (2006) engine.}}
{{note|This '''downloadable''' shader only works in the {{ep1}} {{src06|4}} engine.}}
{{note|Thexa4's PBR shader works in {{src13|4}}.}}
{{note|Thexa4's PBR shader works in {{src13|4}}.}}


'''Parallax mapping''' (also known as '''offset mapping''' or '''virtual displacement mapping''') is a shading technique that displaces the individual pixel height of a surface, so that when you look at it at an angle, the high points will obscure the low points behind them, making it look three-dimensional. The height data for each pixel comes from a [[$parallaxmap]] texture, which needs to be created for each parallax mapped material.
'''Parallax mapping''' (also known as '''offset mapping''' or '''virtual displacement mapping''') is a shading technique that displaces the individual pixel height of a surface, so that when you look at it at an angle, the high points will obscure the low points behind them, making it look three-dimensional. The height data for each pixel comes from a {{Shader_Name|type=param|$parallaxmap}} texture, which needs to be created for each parallax mapped material.


Parallax mapping is an enhancement of the [[bump mapping]] technique. It is only worthwhile for textures that have a depth of at least a few centimeters, like deep-set bricks or stone.
Parallax mapping is an enhancement of the [[bump mapping]] technique. It is only worthwhile for textures that have a depth of at least a few centimeters, like deep-set bricks or stone.
Line 20: Line 21:
Add these two lines to your [[VMT|Valve Material (.vmt)]] file:
Add these two lines to your [[VMT|Valve Material (.vmt)]] file:


<code>"$parallaxmap" "''texture name''"</code><br/>
{{Shader_Name|type=param|$parallaxmap|texture}}
<code>"$parallaxmapscale" ''<scale value>''</code>
 
{{Shader_Name|type=param|$parallaxmapscale|float}}
 


Fill in the path and name of your heightmap on the first line, and a number between 0 and 1 on the second line. This number affects how deep the texture will look. <code>0.05</code> is an appropriate value for bricks.
Fill in the path and name of your heightmap on the first line, and a number between 0 and 1 on the second line. This number affects how deep the texture will look. <code>0.05</code> is an appropriate value for bricks.
Line 28: Line 31:
Example VMT:
Example VMT:


<pre>
{{CodeBlock|<nowiki>"LightmappedGeneric"
<nowiki>
"LightmappedGeneric"
{
{
     "$basetexture" "walls/brickwall"
     "$basetexture" "walls/brickwall"
Line 37: Line 38:
     "$parallaxmap" "walls/brickwall_height"
     "$parallaxmap" "walls/brickwall_height"
     "$parallaxmapscale" 0.05
     "$parallaxmapscale" 0.05
}
}</nowiki>}}
</nowiki>
 
</pre>
===Adding a parallax map with the Parallax Occlusion Shader mod===
===Adding a parallax map with the Parallax Occlusion Shader mod===
{{note|This mod is obsolete, and does not work properly with [[HDR]]. There is [http://www.hl2world.com/bbs/1-vt46068.html a reincarnation of the Parallax Occlusion Shader mod] by the same author but that only works with models. A brush version is in the works. In the meantime, Parallax Occlusion Shader still works with HDR off.}}
{{note|This mod is obsolete, and does not work properly with [[HDR]]. There is [http://www.hl2world.com/bbs/1-vt46068.html a reincarnation of the Parallax Occlusion Shader mod] by the same author but that only works with models. A brush version is in the works. In the meantime, Parallax Occlusion Shader still works with HDR off.}}
Line 64: Line 64:
Example VMT:
Example VMT:


<pre>
{{CodeBlock|<nowiki>"MN_PrlxLightmappedGeneric"
<nowiki>
"MN_PrlxLightmappedGeneric"
{
{
     "$basetexture" "walls/brickwall"
     "$basetexture" "walls/brickwall"
Line 72: Line 70:
     "$bumpmap" "walls/brickwall_normal"
     "$bumpmap" "walls/brickwall_normal"
     "$heightmap" "walls/brickwall_height"
     "$heightmap" "walls/brickwall_height"
}
}</nowiki>}}
</nowiki>
 
</pre>
===Adding parallax map with Thexa4's PBR shader mod===
===Adding parallax map with Thexa4's PBR shader mod===
[[File:Thexa4 pbr parallax 1.png|thumb|300px|right|Parallax enabled.]]
[[File:Thexa4 pbr parallax 1.png|thumb|300px|right|Parallax enabled.]]
Line 82: Line 79:
To make the effect work you will need to have these 3 parameters in your [[VMT]]:
To make the effect work you will need to have these 3 parameters in your [[VMT]]:


Enables/Disables parallax mapping.  
{{Shader_Name|type=param|$parallax |bool}} - Enables/Disables parallax mapping.  


<code>$parallax <[[bool]]> </code>
{{Shader_Name|type=param|$parallaxdepth |float}} - Controls the intensity of the parallax effect.


Controls the intensity of the parallax effect.
{{Shader_Name|type=param|$parallaxcenter|float}} - Center depth of the Parallax Map.


<code>$parallaxdepth <[[float]]> </code>
Center depth of the Parallax Map.
<code> $parallaxcenter <[[float]]></code>


To make the parallax mapping work you will need to put your [[Heightmap]] into the [[Bump_map]]'s alpha channel!!
To make the parallax mapping work you will need to put your [[Heightmap]] into the [[Bump_map]]'s alpha channel!!
Line 98: Line 90:
Example VMT:
Example VMT:


<pre>
{{CodeBlock|<nowiki>"PBR"
<nowiki>
"PBR"
{
{
         "$basetexture"      "pbr/rock_color"
         "$basetexture"      "pbr/rock_color"
Line 113: Line 103:
"$parallaxdepth" "0.030"
"$parallaxdepth" "0.030"
"$parallaxcenter" "0.5"
"$parallaxcenter" "0.5"
}
}</nowiki>}}
</nowiki>
 
</pre>
==See also==
==See also==
* [[Material Creation]]
* [[Material Creation]]

Revision as of 16:32, 25 July 2023

English (en)Translate (Translate)
Example of parallax mapping.
Warning.pngWarning:Parallax maps are disabled in every Valve game, although since Alien Swarm an (unfinished) shader exists named Shader-ball.png ParallaxTest, which can be used as an alternative.
Note.pngNote:This downloadable shader only works in the Half-Life 2: Episode One Source 2006 Source 2006 engine.
Note.pngNote:Thexa4's PBR shader works in Source 2013 Source 2013.

Parallax mapping (also known as offset mapping or virtual displacement mapping) is a shading technique that displaces the individual pixel height of a surface, so that when you look at it at an angle, the high points will obscure the low points behind them, making it look three-dimensional. The height data for each pixel comes from a Shader-ball-settings.png $parallaxmap texture, which needs to be created for each parallax mapped material.

Parallax mapping is an enhancement of the bump mapping technique. It is only worthwhile for textures that have a depth of at least a few centimeters, like deep-set bricks or stone.


Creating a parallax mapped material

Creating a heightmap

Regardless of the way you are going to render them, creating parallax mapped materials always starts with creating a heightmap.

Adding a parallax map with the built-in support for parallax maps

Add these two lines to your Valve Material (.vmt) file:

Shader-ball-settings.png $parallaxmaptexture

Shader-ball-settings.png $parallaxmapscalefloat


Fill in the path and name of your heightmap on the first line, and a number between 0 and 1 on the second line. This number affects how deep the texture will look. 0.05 is an appropriate value for bricks.


Example VMT:

"LightmappedGeneric" { "$basetexture" "walls/brickwall" "$surfaceprop" "brick" "$bumpmap" "walls/brickwall_normal" "$parallaxmap" "walls/brickwall_height" "$parallaxmapscale" 0.05 }

Adding a parallax map with the Parallax Occlusion Shader mod

Note.pngNote:This mod is obsolete, and does not work properly with HDR. There is a reincarnation of the Parallax Occlusion Shader mod by the same author but that only works with models. A brush version is in the works. In the meantime, Parallax Occlusion Shader still works with HDR off.

First, in the Valve Material (.vmt) file, after the line

"LightmappedGeneric"

add this line:

//"MN_PrlxLightmappedGeneric"

When playing a map with your parallax mapped material, comment out the first line. When compiling a map with your parallax mapped material in Hammer, comment out the last line. This (according to the author of the mod) is a workaround to a glitch in Source SDK.

Finally, add this line to your VMT file:

"$heightmap" "texture name"

Other parameters you may need:

"$heightscale", defines the "depth" of the effect, takes values 0.0—1.0, default=0.4
"$heightmapsample", default=16

Example VMT:

"MN_PrlxLightmappedGeneric" { "$basetexture" "walls/brickwall" "$surfaceprop" "brick" "$bumpmap" "walls/brickwall_normal" "$heightmap" "walls/brickwall_height" }

Adding parallax map with Thexa4's PBR shader mod

Parallax enabled.
Note.pngNote: Follow the tutorial Adding PBR to Your Mod to implement the shader into your source sdk project! This shader is compatible with HDR and with Source 2013 Source 2013.
Warning.pngWarning: This shader drastically modifies how your materials look compared to lightmappedgeneric!!
Parallax Disabled.

To make the effect work you will need to have these 3 parameters in your VMT:

Shader-ball-settings.png $parallax bool - Enables/Disables parallax mapping.

Shader-ball-settings.png $parallaxdepth float - Controls the intensity of the parallax effect.

Shader-ball-settings.png $parallaxcenterfloat - Center depth of the Parallax Map.


To make the parallax mapping work you will need to put your Heightmap into the Bump_map's alpha channel!!

Example VMT:

"PBR" { "$basetexture" "pbr/rock_color" "$bumpmap" "pbr/rock_bump" //important you need to put your heightmap into the bumpmaps alpha channel "$mraotexture" "pbr/rock_mrao" "$envmap" "env_cubemap" "$surfaceprop" "Default" "$model" "0" "$parallax" "1" "$parallaxdepth" "0.030" "$parallaxcenter" "0.5" }

See also

External links