 # Vector Expressions

## Expressions that output a vector value, such as a position or normal.

Related Courses

In this page, you'll find the available Vector Expressions that output vector values mapped to RGBA. These can be used for a myriad of different effects for creating your Materials for things like getting an object's position in world space so that the Material can react or transitioning colors on a character when they enter a specific area. There are many others that enable you to control spacial local style material effects that you can look the examples below learn more about.

## ActorPositionWS

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

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.

## 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.

## 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.

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)

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)

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 has been 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.

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.

## 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.

## ParticlePositionWS

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

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.

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

## Pre-Skinned Local Normal

The Pre-Skinned Local Normals Vector Expression outputs a three-channel vector value representing the local surface normal for Skeletal and Static Meshes. This enables you to achieve locally-aligned tri-planar materials and mesh aligned effects in your materials.

In this example, the material is using a tri-planar texture aligned to the mesh's local surface normal.

Click image for larger size.

Tri-Planar Pre-Skinned Local Normal Vector Expression

Tri-Planar Material

## Pre-Skinned Local Position

The Pre-Skinned Local Position Vector Expression outputs a three-channel vector value that gives access to a Skeletal Mesh's default pose position data for use in per-vertex outputs. This enables you to have localized effects on an animated character. This vector expression can also be used with Static Meshes, which will return the standard local position.

Click image for larger size.

In this example, the Skeletal Mesh's default pose is used for mapping versus the default UV mapping on the right.

Pre-Skinned Local Position Vector Expression

Skeletal Mesh's Default UV Layout

## 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.

## 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.

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

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 the 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

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.

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.

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.

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.

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.

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.

Computes 3D gradient vector from result of Prepare3DDeriv/Compute3DDeriv.

CurlFrom3DDeriv

Computes curl of a 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 of 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

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. The 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 this 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.

Click for full image.

• Voronoi Material Example:

Click for full image.

Tags

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.