This article's documentation is for anything that uses the Source engine. Click here for more information.

Displacement

From Valve Developer Community
Jump to: navigation, search

English (en)русский (ru)español (es)中文 (zh)
Edit
Note.pngNote:For any discussions about Displacement, please visit this page instead if you want to discuss anything about it. The current discussion page is currently locked.
A simple displacement surface

Displacements are quadrilateral (4-sided) brush surfaces that have been converted to a mesh of triangular polygons which can be freely distorted and sculpted into various shapes. Displacements are primarily used in the Source engine to create terrain such as hills, valleys, trenches, slopes, etc. Displacements are also sometimes used as flat surfaces simply to blend between two or more textures.

Icon-Bug.pngBug:Power of 4 displacements can cause crashes if colliding with physics objects (except in Garry's Mod). Additionally, they may rarely cause physics objects to pass through them at edges, this can be observed in the official de_dust2 map in Counter-Strike: Global Offensive.
Icon-Bug.pngBug:In InsurgencyDay of Infamy, if "Batch displacement rendering" is checked in Hammer's general options, manipulating displacements in any way could cause Hammer to crash without reason.
Icon-Bug.pngBug:Displacements can be badly lightmapped (totally black), there are several reasons for that: the most rare reason is bad landing area in a room which you use for sky_camera, for example you have mix of displacements and brush boxes there, it can cause your main gameplay area with displacements turn to black, select only one type and check it for errors! Other more common error when black are only displacement edges is caused by undeleted faces from back side of your displacement brush, select whole displacement brush and deselect only top one face which is seen to player, then click displacement->destroy. And the last one reason for that is that you compile you map with vrad on fast (not normal or final), it will cause this black edges issue.
Icon-Bug.pngBug:Sometimes complex displacements are flickering no matter what you do, to fix it, you can split them on several parts and remove the one which is outside or deep inside brush geometry. Also there is a working trick: select a glitching one's, use "Move selected to entity" and then "to World" and save of course, it helps, especially when map was built with different hammer versions.

Always check that you sewed them properly and you have no gaps between them, otherwise it can cause flickering too.

Blank image.pngTodo: Check if other games using CSGO's similar branch (such as Portal 2) do not suffer the crashing Bug.

Benefits

  • They are rendered in batches, making it very cheap: per polygon face actually cheaper than standard brush geometry!
  • They can be altered using the Paint Geometry tool to sculpt a wide variety of shapes, well beyond what can be created with brushes.
  • An alpha channel for can be painted per-vertex to blend between two textures on the displacement. This can be used to create transitions between dirt and rock, for example.
  • Can be automatically populated with detail props.

Limitations

  • They must always be four-sided (see below for a messy workaround).
  • They must always be static, and never attached to an entity, meaning you cannot set displacements as brush entities, such as func_breakable, func_detail, or func_brush. Doing so will usually result in an error message from VBSP before halting the compile process.
  • They do not block visibility and do not seal the map from leaks.
  • A single map is limited to a total of 2048 displacements in Source 2013 games. In Insurgency this limit is at 4096. In Garry's Mod this limit is at 16384. In Counter-Strike: Global Offensive this limit is at 32768.
  • The bigger the displacement is, the less you will be able to lower the lightmap under a certain value.
  • Power of 4 displacements are not compressed under the normal compile tools (patched compile tools overcome this)

Other characteristics

  • There are three levels of resolution (higher resolution means more tris), but ultimately the maximum visual detail is determined by the size of the displacement. Cut one up if more detail is needed.
  • Light is not blocked by the invisible backface, except for Counter-Strike: Global Offensive.
  • A single brush can host as many displacements as it has faces (the brush itself is not compiled).

Construction

Displacements are created by using one of the faces on a brush solid as a base face. Once the displacement surface has been created, the brush face used as the base face is discarded when the map is compiled. Additionally, if a brush solid contains any displacement surfaces, all of the non-displacement sides are discarded when the map is compiled and run in the engine. In other words, once you convert a brush solid to include displacements, the brush solid is no longer a solid object and is removed when you run the map.

The following images illustrate this characteristic:

The Base brush face before a displacement is added.
The sides of the brush shown here will not be rendered.

Basic displacement creation

Displacements with different density levels.

How to create and paint a displacement surface:

  1. Create a brush with the Block Tool that will be used as the base for the created displacement surface.
  2. Click the Texture Application tool to bring up the Face Edit dialog, and select the Displacement tab.
  3. In the 3D view, left-click on a brush face to select it. Ctrl-click to add or remove faces from the current selection.
  4. Click Create in the Displacement tab. Enter a value from 2 to 4 for the displacement density and click OK.
    Warning.pngWarning:Power 4 displacements are usually advised against since they might cause errors. Power 4 displacements might work better in newer engine versions.
    Note.pngNote:You can change a displacement's power later in the "attributes" section, but be warned that the higher detail from the displacement being its power is permanently lost when lowering the power.
  5. Select the Paint Geometry tool on the Displacement tab. The Paint Geometry panel will open.
  6. In the 3D View, Left-click on a displacement to raise a section, and right-click to lower it. Use the Radius slider in the Paint Geometry panel to control the size of the painting sphere.

See Paint Geometry for more information on displacement painting.

Displacement options

Brushes can have multiple sides with displacements on them.

Hammer displacementmaskicon.jpg  Use the Displacement Mask button on the Map Operations toolbar to toggle the display and selection of the non-displacement sides of brush.

You can also have more than one displacement surface for each brush, like the image on the left. As long as a brush side has 4 edges, you can make a displacement surface out of it.

See Face Edit, Displacements for a description of all the ways you can paint the geometry on a displacement.

Sewing displacements

The Sew button on the Displacement tab can be used to connect the edges of two or more selected displacement surfaces. To sew two or more displacements, select the displacement faces that should be sewn together and press the Sew button.

You can sew displacement surfaces in any of the following circumstances:

  • Any two displacements whose base face brush surfaces share a common edge with coincident endpoints.
  • A displacement surface to a non-displacement brush face, if the base face of the two share a common edge with coincident endpoints.
  • A displacement surface to another displacement surface where a shared edge is exactly half the width of the other (called a T-junction).

You can sew displacements with different resolution settings — the vertices of the higher resolution displacement will be moved to match the vertices of the lower resolution displacement.

Examples of circumstances where the Sew command can be used:

Adjacent displacements with base faces that share an edge.
Displacements with different resolutions.
Displacement with a base face that shares an edge with a brush.
Displacements that share an edge at the exact midpoint.

Surfaces cannot be sewn together if the base faces of the displacements do not share a common edge:

Surfaces that don't share a common edge cannot be connected.

Surfaces also cannot be sewn together if they don't share a common "Elev"ation attribute, which is found along side the Power and Scale attributes.

Subdividing displacements

The Subdivide button on the Displacement tab can be used to smooth two or more selected displacement surfaces in relation to their position. To subdivide two or more displacements, select the displacement faces that should be subdivided and press the Subdivide button. If the subdivision is not successful, you'll see areas where displacement faces appear Buggy and out of place.

Tip.pngTip:The higher the Power attribute is, the smoother the displacements will be. However higher Power is heavier for game engine and therefore using high Power for small displacements is not recommended.
A series of interconnected brushes ready to be created into displacements.
The tunnel after displacements are created.
What occurs when subdivision occurs among the selected displacements.
A finished product with some touch-ups using the Paint Alpha tool

Other methods of altering displacement geometry

Besides the displacement painting tools, some of the standard brush manipulation tools work on displacement surfaces. It works well to control the contours of the displacement with the paint tools, and do larger manipulations with the following tools.

Transformations

Hammer select.png  Displacements can be freely moved, scaled, rotated and sheared with the Selection Tool, just like standard brushes. The transformation is done to the base brush face, and the displacement follows.

Clipping

Hammer ClippingTool.png  The Clip Tool can also be used to clip displacement surfaces. This can be used to trim off unneeded sections of the displacement surface, or to divide a displacement into two pieces without changing its shape.

Icon-Important.pngImportant:The result of a clip operation must be a quadrilateral (containing exactly four edges) to be a valid displacement.

The following example shows how the Clip Tool can be used to trim a displacement surface:

Displacement surface before clipping operation.
Using the clip tool to draw a clip line in the 2D view previews the result.
The result of the clip operation.

Vertex manipulation (Technique)

Hammer VertexTool.png  The Vertex Tool can also be used to clip displacement surfaces. Vertex editing works well to shift the corners of the displacement to meet important edges, or to raise whole section of terrain without having to paint it by hand when creating hills or elevated surfaces.

There are some important restrictions when vertex editing displacements:

  • Vertex editing is done on the base face, not the displacement itself.
  • Collapsing or adding vertices is not allowed, and will destroy displacements attached to the base faces; the end result must be a quadrilateral.
  • The end result of the vertex editing must be a planar surface. Making a non-planar surface will destroy attached displacements.

The following example shows how the Vertex Tool can be used to raise a section of displacements:

A set of four displacement surfaces, selected to do a vertex editing.
Entering Vertex Edit mode shows the vertices of the base brush faces.
Selecting a set of end vertices and raising them together.
The result of the vertex editing operation.

Creating holes in displacements

Sometimes you need to create a hole or gap in displacement surfaces for various reasons. See Creating Holes in Displacements for information on how to create holes in displacement geometry.

Blended displacement materials (vertex alpha painting)

The green box is the center of the Paint Alpha paint brush.

The Paint Alpha tools allow you to blend between two different textures on a displacement surface by painting the alpha values of each vertex. The alpha value dictates data about the transparency of the two textures assigned to the surface. This can be used to create transitions in the texturing, like grass to dirt, sand to rock, etc. To do vertex alpha material blending, special blend materials are made specifically for this purpose that contain the necessary shader. Only these materials can be used for blending. If one of the standard (non-blended) materials are used, the Paint Alpha tools will have no visible effect.

To add a blended material to a displacement surface and paint the vertex alpha data to blend the textures:

  1. Choose the Texture Application Tool to open the Face Edit dialog box.
  2. Left-Click in the 3D View to select a displacement face you wish to add a blend material to.
  3. Click the Browse button on the Material tab of the Face Edit dialog box.
  4. When the Texture Browser appears, type blend into the filter field at the bottom of the Texture Browser.
  5. Double-left-click to select one of the blended materials and close the Texture Browser.
  6. Click the Apply button on the Face Edit dialog to apply the material to the displacement surface.
  7. Click the Displacement tab on the Face Edit dialog.
  8. Click the Paint Alpha button on the Displacement tab to open the Paint Alpha tools.
  9. Click the Value slider field, and type a value between 30-100 as a starting point. Make sure that Raise/Lower is selected under Effect. Lower numbers in the Value field paint the vertex alpha data at a slower pace, higher numbers paint the data faster.
  10. Left-click on one of the vertices of the displacement in the 3D View to add vertex alpha data. Right-click on the displacement to remove data.

See Paint Alpha for more information on the alpha painting tools.

Triangular displacements

A messy solution for a messy situation.

Sometimes it is necessary to have a displacement surface which has only three sides. Since displacements can only be created from quads, this requires creating a triangle out of three separate quads, as displayed to the right.

Icon-Important.pngImportant:Use sparingly! It can be possible, in many situations, to get away with a fourth vertex on the "hypotenuse" that is just barely jutted out enough for the displacement face to be 4-sided with no coplanar sides.
Tip.pngTip:Since the triangular displacement surface is made out of three displacement meshes instead of one, it has a higher vertex density; consider using power-of-two displacements in this situation.

Displacement editing shortcuts

Alt+right click
When the axis in paint geometry is set to face normal, will set the axis to the direction perpendicular to the face you clicked on.
Shift
Ignores the distance setting, allowing sections to be dragged freely.
Right click
Reverses the direction of the paint geometry tool.

See also

External links

Environment articles:
Skies and environment maps Skybox (2D)Skybox (3D)HDR SkiesSkybox with TerragenSkybox with Terragen - AdvancedList of skies
Terrain and displacement mapping DisplacementsCreating Holes in DisplacementsDigital Elevation ModelsCreating custom terrain with Worldmachine


A simple displacement surface

Displacement geometry are brush surfaces that have been converted to a mesh of triangular polygons which can be freely distorted and sculpted into various shapes. Displacements are primarily used in the Source engine to create terrain such as hills, valleys, trenches, slopes, etc. Displacements are also sometimes used as flat surfaces simply to blend between two or more textures.

Icon-Bug.pngBug:Displacements with a power of 4 can cause crashes if colliding with physics objects (except in Garry's Mod). Additionally, they may rarely cause physics objects to pass through them at edges, this can be observed in the official de_dust2 map in Counter-Strike: Global Offensive.
Icon-Bug.pngBug:In InsurgencyDay of Infamy, if "Batch displacement rendering" is checked in Hammer's general options, manipulating displacements in any way could cause Hammer to crash without reason.
Icon-Bug.pngBug:Displacements can be badly lightmapped (totally black), there are several reasons for that: the most rare reason is bad landing area in a room which you use for sky_camera, for example you have mix of displacements and brush boxes there, it can cause your main gameplay area with displacements turn to black, select only one type and check it for errors! Other more common error when black are only displacement edges is caused by undeleted faces from back side of your displacement brush, select whole displacement brush and deselect only top one face which is seen to player, then click displacement->destroy. And the last one reason for that is that you compile you map with vrad on fast (not normal or final), it will cause this black edges issue.
Icon-Bug.pngBug:Sometimes complex displacements are flickering no matter what you do, to fix it, you can split them on several parts and remove the one which is outside or deep inside brush geometry. Also there is a working trick: select a glitching one's, use "Move selected to entity" and then "to World" and save of course, it helps, especially when map was built with different hammer versions.

Always check that you sewed them properly and you have no gaps between them, otherwise it can cause flickering too.

Blank image.pngTodo: Check if other games using CSGO's similar branch (such as Portal 2) do not suffer the crashing bug.

Benefits

  • They are rendered in batches, making it very cheap: per polygon face actually cheaper than standard brush geometry!
  • They can be altered using the Paint Geometry tool to sculpt a wide variety of shapes, well beyond what can be created with brushes.
  • An alpha channel for can be painted per-vertex to blend between two textures on the displacement. This can be used to create transitions between dirt and rock, for example.
  • Can be automatically populated with detail props.

Limitations

  • They must always be four-sided.
  • They must always be static, and never attached to an entity, meaning you cannot set displacements as brush entities, such as func_breakable, func_detail, and func_brush. Doing so will usually result in an error message from VBSP before halting the compile process.
  • They do not block visibility and do not seal the map from leaks.
  • A single level is limited to a total of 2048 displacements in Source 2013 games. In Insurgency this limit is at 4096. In Counter-Strike: Global Offensive this limit is at 32768. In Garry's Mod this limit is at 16384.
  • The bigger the displacement is, the less you will be able to lower the lightmap under a certain value.
  • Power of 4 displacements are not compressed under the normal compile tools (patched compile tools overcome this)

Other characteristics

  • There are three levels of resolution (higher resolution means more tris), but ultimately the maximum visual detail is determined by the size of the displacement. Cut one up if more detail is needed.
  • Light is not blocked by the invisible backface, except for Counter-Strike: Global Offensive.
  • A single brush can host as many displacements as it has faces (the brush itself is not compiled).

Construction

Displacements are created by using one of the faces on a brush solid as a base face. Once the displacement surface has been created, the brush face used as the base face is discarded when the map is compiled. Additionally, if a brush solid contains any displacement surfaces, all of the non-displacement sides are discarded when the map is compiled and run in the engine. In other words, once you convert a brush solid to include displacements, the brush solid is no longer a solid object and is removed when you run the map.

The following images illustrate this characteristic:

The Base brush face before a displacement is added.
The sides of the brush shown here will not be rendered.

Basic displacement creation

Displacements with different density levels.

How to create and paint a displacement surface:

  1. Create a brush with the Block Tool that will be used as the base for the created displacement surface.
  2. Click the Texture Application tool to bring up the Face Edit dialog, and select the Displacement tab.
  3. In the 3D view, left-click on a brush face to select it. Ctrl-click to add or remove faces from the current selection.
  4. Click Create in the Displacement tab. Enter a value from 2 to 4 for the displacement density and click OK.
    Warning.pngWarning:Power 4 displacements are usually advised against since they might cause errors. Power 4 displacements might work better in newer engine versions.
    Note.pngNote:You can change a displacement's power later in the "attributes" section, but be warned that the higher detail from the displacement being its power is permanently lost when lowering the power.
  5. Select the Paint Geometry tool on the Displacement tab. The Paint Geometry panel will open.
  6. In the 3D View, Left-click on a displacement to raise a section, and right-click to lower it. Use the Radius slider in the Paint Geometry panel to control the size of the painting sphere.
See Paint Geometry for more information on displacement painting.

Displacement options

Brushes can have multiple sides with displacements on them.

Hammer displacementmaskicon.jpg  Use the Displacement Mask button on the Map Operations toolbar to toggle the display and selection of the non-displacement sides of brush.

You can also have more than one displacement surface for each brush, like the image on the left. As long as a brush side has 4 edges, you can make a displacement surface out of it.

See Face Edit, Displacements for a description of all the ways you can paint the geometry on a displacement.

Sewing displacements

The Sew button on the Displacement tab can be used to connect the edges of two or more selected displacement surfaces. To sew two or more displacements, select the displacement faces that should be sewn together and press the Sew button.

You can sew displacement surfaces in any of the following circumstances:

  • Any two displacements whose base face brush surfaces share a common edge with coincident endpoints.
  • A displacement surface to a non-displacement brush face, if the base face of the two share a common edge with coincident endpoints.
  • A displacement surface to another displacement surface where a shared edge is exactly half the width of the other (called a T-junction).

You can sew displacements with different resolution settings — the vertices of the higher resolution displacement will be moved to match the vertices of the lower resolution displacement.

Examples of circumstances where the Sew command can be used:

Adjacent displacements with base faces that share an edge.
Displacements with different resolutions.
Displacement with a base face that shares an edge with a brush.
Displacements that share an edge at the exact midpoint.

Surfaces cannot be sewn together if the base faces of the displacements do not share a common edge:

Surfaces that don't share a common edge cannot be connected.

Surfaces also cannot be sewn together if they don't share a common "Elev"ation attribute, which is found along side the Power and Scale attributes.

Subdividing displacements

The Subdivide button on the Displacement tab can be used to smooth two or more selected displacement surfaces in relation to their position. To subdivide two or more displacements, select the displacement faces that should be subdivided and press the Subdivide button. If the subdivision is not successful, you'll see areas where displacement faces appear buggy and out of place.

Tip.pngTip:The higher the Power attribute is, the smoother the displacements will be. However higher Power is heavier for game engine and therefore using high Power for small displacements is not recommended.
A series of interconnected brushes ready to be created into displacements.
The tunnel after displacements are created.
What occurs when subdivision occurs among the selected displacements.
A finished product with some touch-ups using the Paint Alpha tool

Other methods of altering displacement geometry

Besides the displacement painting tools, some of the standard brush manipulation tools work on displacement surfaces. It works well to control the contours of the displacement with the paint tools, and do larger manipulations with the following tools.

Transformations

Hammer select.png  Displacements can be freely moved, scaled, rotated and sheared with the Selection Tool, just like standard brushes. The transformation is done to the base brush face, and the displacement follows.

Clipping

Hammer ClippingTool.png  The Clip Tool can also be used to clip displacement surfaces. This can be used to trim off unneeded sections of the displacement surface, or to divide a displacement into two pieces without changing its shape.

Note.pngNote:The result of a clip operation must be a four-sided shape to be a valid displacement.

The following example shows how the Clip Tool can be used to trim a displacement surface:

Displacement surface before clipping operation.
Using the clip tool to draw a clip line in the 2D view previews the result.
The result of the clip operation.

Vertex manipulation (Technique)

Hammer VertexTool.png  The Vertex Tool can also be used to clip displacement surfaces. Vertex editing works well to shift the corners of the displacement to meet important edges, or to raise whole section of terrain without having to paint it by hand when creating hills or elevated surfaces.

There are some important restrictions when vertex editing displacements:

  • Vertex editing is done on the base face, not the displacement itself.
  • Collapsing or adding vertices is not allowed, and will destroy displacements attached to the base faces.
  • The end result of the vertex editing must be a planar surface. Making a non-planar surface will destroy attached displacements.

The following example shows how the Vertex Tool can be used to raise a section of displacements:

A set of four displacement surfaces, selected to do a vertex editing.
Entering Vertex Edit mode shows the vertices of the base brush faces.

Selecting a set of end vertices and raising them together.
The result of the vertex editing operation.

Creating holes in displacements

Sometimes you need to create a hole or gap in displacement surfaces for various reasons. See Creating Holes in Displacements for information on how to create holes in displacement geometry.

Blended displacement materials (alpha channel painting)

The green box is the center of the Paint Alpha paint brush.

The Paint Alpha tools allow you to blend between two different textures on a displacement surface by painting the alpha channel. The alpha channel contains data about the transparency of the two textures assigned to the surface. This can be used to create transitions in the texturing, like grass to dirt, sand to rock, etc. To do alpha channel material blending, special blend materials are made specifically for this purpose that contain the necessary shader. Only these materials can be used for blending. If one of the standard (non-blended) materials are used, the Paint Alpha tools will have no visible effect.

To add a blended material to a displacement surface and paint the alpha channel data to blend the textures:

  1. Choose the Texture Application Tool to open the Face Edit dialog box.
  2. Left-Click in the 3D View to select a displacement face you wish to add a blend material to.
  3. Click the Browse button on the Material tab of the Face Edit dialog box.
  4. When the Texture Browser appears, type blend into the filter field at the bottom of the Texture Browser.
  5. Double-left-click to select one of the blended materials and close the Texture Browser.
  6. Click the Apply button on the Face Edit dialog to apply the material to the displacement surface.
  7. Click the Displacement tab on the Face Edit dialog.
  8. Click the Paint Alpha button on the Displacement tab to open the Paint Alpha tools.
  9. Click the Value slider field, and type a value between 30-100 as a starting point. Make sure that Raise/Lower is selected under Effect. Lower numbers in the Value field paint the alpha channel data at a slower pace, higher numbers paint the data faster.
  10. Left-click on one of the vertices of the displacement in the 3D View to add alpha channel data. Right-click on the displacement to remove data.
See Paint Alpha for more information on the alpha painting tools.

Displacement editing shortcuts

Alt+right click
When the axis in paint geometry is set to face normal, will set the axis to the direction perpendicular to the face you clicked on.
Shift
Ignores the distance setting, allowing sections to be dragged freely.
Right click
Reverses the direction of the paint geometry tool.

See also

External links

Environment articles:
Skies and environment maps Skybox (2D)Skybox (3D)HDR SkiesSkybox with TerragenSkybox with Terragen - AdvancedList of skies
Terrain and displacement mapping DisplacementsCreating Holes in DisplacementsDigital Elevation ModelsCreating custom terrain with Worldmachine