Vector Expressions

ActorPositionWS

ActorPositionWS outputs Vector3 (RGB) data representing the location of the object with this material on it in world-space.

ActorPositionColors.png ActorPositionNetwork.png

In this example, you can see that ActorPositionWS is being fed directly into the Base Color of the material. As a result, each of the spheres with the material applied to them show a different color as they are moved to different locations in 3D space. Note that the result of the ActorPositionWS node is being divided by 1600 to create a nice blend-in color, rather than a pop.

CameraPositionWS

The CameraWorldPosition expression outputs a three-channel vector value representing the camera's position in world space.

The preview sphere changes color as the camera rotates.

CameraPositionWSExample.png CameraPositionWSNetwork.png

CameraVectorWS

The CameraVector expression outputs a three-channel vector value representing the direction of the camera with respect to the surface, in other words, the direction from the pixel to the camera.

Example Usage: CameraVector is often used to fake environment maps by connecting the CameraVector to a ComponentMask and use the x and y channels of the CameraVector as texture coordinates.

CameraVectorWSExample.png

Constant2Vector

The Constant2Vector expression outputs a two-channel vector value, in other words, two constant numbers.

Item Description

Properties

R Specifies the float value of the red (first) channel of the vector the expression outputs.
G Specifies the float value of the green (second) channel of the vector the expression outputs.

Examples: (0.4, 0.6), (1.05, -0.3)

Example Usage: The Constant2Vector is useful for modifying texture coordinates, as they are two-channel values as well.

Constant2Example.png

You can quickly create a Constant2Vector node by holding the 2 key and Left Mouse Click in the graph area of the Material Editor.

Constant3Vector

The Constant3Vector expression outputs a three-channel vector value, in other words, three constants numbers. An RGB color can be thought of as a Constant3Vector, where each channel is assigned to a color (red, green, blue).

Item Description

Properties

R Specifies the float value of the red (first) channel of the vector the expression outputs.
G Specifies the float value of the green (second) channel of the vector the expression outputs.
B Specifies the float value of the blue (third) channel of the vector the expression outputs.

Examples: (0.4, 0.6, 0.0), (1.05, -0.3, 0.3)

Constant3Example.png

You can quickly create a Constant3Vector node by holding the 3 key and Left Mouse Click in the graph area of the Material Editor.

Constant4Vector

The Constant4Vector expression outputs a four-channel vector value, in other words, four constants numbers. An RGBA color can be thought of as a Constant4Vector, where each channel is assigned to a color (red, green, blue, alpha).

Item Description

Properties

R Specifies the float value of the red (first) channel of the vector the expression outputs.
G Specifies the float value of the green (second) channel of the vector the expression outputs.
B Specifies the float value of the blue (third) channel of the vector the expression outputs.
A Specifies the float value of the alpha (fourth) channel of the vector the expression outputs.

Examples: (0.4, 0.6, 0.0, 1.0), (1.05, -0.3, 0.3, 0.5)

Constant4Example.png

You can quickly create a Constant4Vector node by holding the 4 key and Left Mouse Click in the graph area of the Material Editor.

LightVector

This expression is deprecated in Unreal Engine 4 as lighting calculations are now deferred.

Object Bounds

The Object Bounds expression outputs the size of the object in each axis. If used as color, the X, Y, and Z axes correspond to R, G, and B, respectively.

ObjectBoundsScene.png ObjectBoundsNetwork.png

In the example above, you can see that the colors of the objects correspond to the longest axis of the object.

ObjectOrientation

The ObjectOrientation expression outputs the world-space up vector of the object. In other words, the object's local positive z-axis is pointing in this direction.

ObjectOrientationExample.png

ObjectPositionWS

The ObjectPositionWS expression outputs the world-space center position of the object's bounds. For example, this is useful for creating spherical lighting for foliage.

WorldPositionWSScene.png WorldPositionNetwork.png

ParticlePositionWS

The ParticlePositionWS expression outputs Vector3 (RGB) data representing each individual particle's position in world space.

ParticlePositionWS.png

In this image, ParticlePositionWS is being fed into emissive color to visualize the data. The particle system has been scaled up to show how the color is changing based on position.

PixelNormalWS

The PixelNormalWS expression outputs vector data representing the direction that pixels are facing based on the current normal.

PixelNormalWSExample.png

In this example, PixelNormalWS is fed into Base Color. Notice how the normal map is used to give the per-pixel result.

ReflectionVectorWS

The ReflectionVectorWS expression is similar in spirit to CameraVectorWS , but it outputs a three-channel vector value representing the camera direction reflected across the surface normal.

Example Usage: ReflectionVector is commonly used in environment maps, where the x/y components of the reflection vector are used as UVs into a cubemap texture.

ReflectionVectorWSExample.png

VertexNormalWS

The VertexNormalWS expression outputs the world-space vertex normal. It can only be used in material inputs that are executed in the vertex shader, like WorldPositionOffset. This is useful for making a mesh grow or shrink. Note that offsetting position along the normal will cause the geometry to split apart along UV seams.

VertexNormalWSExample.png

In the example above, the preview sphere would seem to scale up and down with sinusoidal motion, as each of the vertices moved in their own normal directions.

Vector Noise

Vector_Noise_Example.png

The Vector Noise Material expression adds several more 3D or 4D vector noise results to use in your Materials. Due to the run-time expense of these functions, it is recommended that once a look is developed with them, all or part of the computation be baked into a Texture using the Draw Material to Render Target Blueprint feature introduced in Unreal Engine 4.13 and later. These Material graph Expressions allow procedural looks to be developed in engine on final assets, providing an alternative to creating procedurally generated Textures with an external tool to apply to assets in UE4. Inside of the Vector Noise Material Expression, you will find the following Vector Noise types.

Image Item Description
Cellnoise.png Cellnoise Returns a random color for each cell in a 3D grid (i.e. from the mathematical floor operation applied to the node input). The results are always consistent for a given position, so can provide a reliable way to add randomness to a Material. This Vector Noise function is extremely cheap to compute, so it is not necessary to bake it into a Texture for performance.
VectorNoise.png Perlin 3D Noise Returns a random color for each cell in a 3D grid (i.e. from the mathematical floor operation applied to the node input). The results are always consistent for a given position, so can provide a reliable way to add randomness to a Material. This Vector Noise function is extremely cheap to compute, so it is not necessary to bake it into a Texture for performance.
GradientNoise.png Perlin Gradient Computes the analytical 3D gradient of a scalar Perlin Simplex Noise. The output is four channels, where the first three (RGB) are the gradient, and the fourth (A) is the scalar noise. This noise type is useful for bumps on a surface or for flow maps.
CurlNoise.png Perlin Gradient Computes the analytical 3D curl of a vector Perlin Simplex Noise (aka Curl Noise). The output is a 3D signed curl vector and is useful for fluid or particle flow.
VoronoiNoise.png Voronoi Computes the same Voronoi noise as the scalar Noise material node. The scalar Voronoi noise scatters seed points in 3D space and returns the distance to the closest one. The Vector Noise version returns the location of the closest seed point in RGB, and the distance to it in A. Especially coupled with Cellnoise, this can allow some randomized behavior per Voronoi cell.

Below is a simple stone bed material using the distance component of the Vector Noise / Voronoi to modulate some surface bumps and blend in moss in the cracks, and the seed position together with Vector Noise / Cellnoise to change the color and bump height per rock.

Stone_Example.png

The derivative-based operations Perlin Curl and Perlin Gradient can be added together in octaves, just as regular Perlin noise can. For derivatives of more complex expressions, it is necessary to compute the gradient of the result of the expression. To help with this, place the expression to compute into a Material Function and use it with the following helper nodes.

Item Description
Prepare3DDeriv Uses positions offset in a tetrahedral pattern to compute 3D derivatives. Evaluate the same 3D function at each offset position produced by this function, then feed the resulting values into Compute3DDeriv.
Compute3DDeriv Uses positions offset in a tetrahedral pattern to compute 3D derivatives. Use with Prepare3DDeriv.
GradFrom3DDeriv Computes 3D gradient vector from result of Prepare3DDeriv/Compute3DDeriv.
CurlFrom3DDeriv Computes curl of at 3D vector field from result of Prepare3DDeriv/Compute3DDeriv.

These helper Material Functions use four evaluations of the base expression spaced in a tetrahedral pattern to approximate these derivative-based operations.

Below you will find descriptions for the various noise functions you will find in the Vector Noise Material Expression.

Item Description

Properties

Function
Function Description
Cellnoise Random color for each integer grid cell in 3D space. About 10 instructions.
Perlin 3D Noise Computational Perlin noise with 3D output, each channel output ranges from -1 to 1. About 83 instructions if only the red channel is used, 125 instructions if all three channels are used
Perlin Gradient Computes the gradient of a Perlin noise function. RGB output contains the gradient vector, A is the scalar noise. About 106 instructions.
Perlin Curl Computes a 3D curl noise. Output is the mathematical curl of Perlin 3D Noise. About 162 instructions.
Voronoi The same algorithm and instruction counts as the Voronoi function in the Noise expression, but RGB is the location of the closest seed point in each Voronoi cell, and A is the distance to that seed point.
Quality A look/performance setting. Lower values are faster but may look worse, higher values are slower but may look better.
Tiling For noise functions that support it, allows noise to tile. This is more expensive, but useful when baking noise into a seamless wrapping texture.
Tile Size When tiling, how often should the noise repeat. For Perlin noise variants, the Tile Size must be a multiple of three.

Inputs

Position Allows the texture size to be adjusted via a 3D vector.
  • Cell Noise Material Example:

    Click for full image.

  • Perlin Gradient Material Example:

    Click for full image.

  • Voronoi Material Example:

    Click for full image.

Tags