Parallax mapping: Difference between revisions
m (Nesciuse moved page Parallax mapping/en to Parallax mapping without leaving a redirect: Move en subpage to basepage) |
m (Formatting) |
||
Line 2: | Line 2: | ||
[[File:parallax_mapping.jpg|thumb|400px|Example of parallax mapping.]] | [[File:parallax_mapping.jpg|thumb|400px|Example of parallax mapping.]] | ||
{{warning|Parallax maps are disabled in every Valve game, although since {{asbranch|4}} and later, an (unfinished) shader exists named {{ | {{warning|Parallax maps are disabled in every Valve game, although since {{asbranch|4}} and later, an (unfinished) shader exists named {{code|[[ParallaxTest]]}}, which can be used as an alternative.}} | ||
'''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 {{code|[[$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 {{ | |||
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. | ||
==Creating a parallax mapped material== | ==Creating a parallax mapped material== | ||
Line 18: | Line 15: | ||
===Adding a parallax map with the built-in support for parallax maps=== | ===Adding a parallax map with the built-in support for parallax maps=== | ||
{{warning|No official version of {{src|4.1}} has proper support for parallax mapping as it was removed during {{hl2|4.1}}'s development | {{warning|No official version of {{src|4.1}} has proper support for parallax mapping as it was removed during {{hl2|4.1}}'s development for unknown reasons (probably performance as hardware at the time are not powerful enough). Consider implementing other shaders listed on this page, if you want parallax mapping in your source engine project!}} | ||
Add these two lines to your [[VMT|Valve Material (.vmt)]] file: | Add these two lines to your [[VMT|Valve Material (.vmt)]] file: | ||
{{ | {{code|[[$parallaxmap]]}} <nowiki><texture></nowiki> | ||
{{ | {{code|[[$parallaxmapscale]]}} <nowiki><float></nowiki> | ||
Line 76: | Line 73: | ||
===Adding parallax map with the PBR shader=== | ===Adding parallax map with the PBR shader=== | ||
[[File:Thexa4 pbr parallax 1.png|thumb|300px|right|Parallax enabled.]] | [[File:Thexa4 pbr parallax 1.png|thumb|300px|right|Parallax enabled.]] | ||
Games running on {{strata|4}} or with Thexa4's PBR shader installed can use parallax mapping already. | Games running on {{strata|4}} or with Thexa4's PBR shader installed can use parallax mapping already. All '''Strata Source''' games use a similar method. | ||
{{note| Follow the tutorial [[Adding PBR_to_Your_Mod|Adding PBR to Your Mod]] to implement the shader into your source sdk project. This shader is compatible with [[HDR]] and with {{src13|4}}.}} | {{note| Follow the tutorial [[Adding PBR_to_Your_Mod|Adding PBR to Your Mod]] to implement the shader into your source sdk project. This shader is compatible with [[HDR]] and with {{src13|4}}.}} | ||
{{warning|An [[$mraotexture]] is needed to use the PBR features.}} | {{warning|An [[$mraotexture]] is needed to use the PBR features.}} | ||
[[File:Thexa4 pbr parallax 0.png|300px|thumb|right|Parallax Disabled.]] | [[File:Thexa4 pbr parallax 0.png|300px|thumb|right|Parallax Disabled.]] | ||
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]]: | ||
{{ | {{code|[[$parallax]]}} <nowiki><bool></nowiki> - Enables/Disables parallax mapping. | ||
{{ | {{code|[[$parallaxdepth]]}} <nowiki><float></nowiki> - Controls the intensity of the parallax effect. | ||
{{code|[[$parallaxcenter]]}} <nowiki><float></nowiki> - 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. See [[Creating PBR materials#Embedding the Heightmap|Creating PBR materials]] for a tutorial on how to do this. | To make the parallax mapping work you will need to put your [[Heightmap]] into the [[Bump map]]'s alpha channel. See [[Creating PBR materials#Embedding the Heightmap|Creating PBR materials]] for a tutorial on how to do this. | ||
Example VMT: | Example VMT: | ||
Line 112: | Line 106: | ||
===Parallax occlusion mapping in {{bms|4}}=== | ===Parallax occlusion mapping in {{bms|4}}=== | ||
'''Black Mesa''' has its own way of rendering parallax mapping, which was not used in the original campaign, but was used in {{bmsbs|4}} for brick walls and the likes. This material shader parameter can be used for {{code|[[LightmappedGeneric]]}} and {{code|[[VertexLitGeneric]]}}. | |||
{{warning|Parallax occlusion mapping is an expensive pixel shader, meaning it has higher performance costs based on its sample count and occupying screen percentage, and should thus be used smartly.}} | {{warning|Parallax occlusion mapping is an expensive pixel shader, meaning it has higher performance costs based on its sample count and occupying screen percentage, and should thus be used smartly.}} | ||
{{Note|[[Bumpmap]] shadows are not affected by parallax with newlights and will appear to hover above the surface. Using [[$translucent]] in conjunction disables the floating shadows.}} | {{Note|[[Bumpmap]] shadows are not affected by parallax with newlights and will appear to hover above the surface. Using [[$translucent]] in conjunction disables the floating shadows.}} | ||
Line 120: | Line 114: | ||
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]]: | ||
{{ | {{code|$pomscale}} <nowiki><float></nowiki> - Scale of parallax mapping. | ||
<div style=overflow:auto> | <div style=overflow:auto> | ||
{{expand|title=Examples|1= | {{expand|title=Examples|1= | ||
Line 129: | Line 123: | ||
</gallery> | </gallery> | ||
}}</div> | }}</div> | ||
{{ | {{code|$pomminsamples}} <nowiki><float></nowiki> - Min amount of depth samples. The minimum is used at steep glancing angles and far distances. | ||
{{Note|Higher values have less height stepping far away, but an increased performance cost. Reasonable values are around 0.}} | {{Note|Higher values have less height stepping far away, but an increased performance cost. Reasonable values are around 0.}} | ||
<div style=overflow:auto> | <div style=overflow:auto> | ||
Line 140: | Line 134: | ||
}}</div> | }}</div> | ||
{{ | {{code|$pommaxsamples}} <nowiki><float></nowiki> - Max amount of depth samples. The maximum is used at shallow glancing angles and close distances. | ||
{{Note|Higher values have less height stepping upclose, but an increased performance cost. Reasonable values are < 100}} | {{Note|Higher values have less height stepping upclose, but an increased performance cost. Reasonable values are < 100}} | ||
<div style=overflow:auto> | <div style=overflow:auto> | ||
Line 152: | Line 146: | ||
To make the parallax mapping work you'll need [[Heightmap]]. This is not embedded in the Bumpmap, but is instead kept separate in it's own [[VTF]] image. | To make the parallax mapping work you'll need [[Heightmap]]. This is not embedded in the Bumpmap, but is instead kept separate in it's own [[VTF]] image. | ||
Example VMT: | Example VMT: |
Revision as of 02:18, 23 July 2024




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 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:
$parallaxmap <texture>
$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. 0.05
is an appropriate value for bricks.
Example VMT:
Adding a parallax map with the Parallax Occlusion Shader mod



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:
Adding parallax map with the PBR shader
Games running on Strata Source or with Thexa4's PBR shader installed can use parallax mapping already. All Strata Source games use a similar method.



To make the effect work you will need to have these 3 parameters in your VMT:
$parallax <bool> - Enables/Disables parallax mapping.
$parallaxdepth <float> - Controls the intensity of the parallax effect.
$parallaxcenter <float> - 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. See Creating PBR materials for a tutorial on how to do this.
Example VMT:
Parallax occlusion mapping in
Black Mesa
Black Mesa has its own way of rendering parallax mapping, which was not used in the original campaign, but was used in Black Mesa: Blue Shift for brick walls and the likes. This material shader parameter can be used for LightmappedGeneric and VertexLitGeneric.


To make the effect work you will need to have these 3 parameters in your VMT:
$pomscale <float> - Scale of parallax mapping.
$pomminsamples <float> - Min amount of depth samples. The minimum is used at steep glancing angles and far distances.

|
$pommaxsamples <float> - Max amount of depth samples. The maximum is used at shallow glancing angles and close distances.

|
To make the parallax mapping work you'll need Heightmap. This is not embedded in the Bumpmap, but is instead kept separate in it's own VTF image.
Example VMT:
See also
- Adding PBR to Your Mod
- Creating PBR materials
- Material Creation
- $parallax
- Normal Map Creation
- Wikipedia:Parallax mapping