 # Constant Material Expressions

## Material Expressions whose outputs generally do not change once set in the editor or when play begins.

Related Courses

Material Expressions whose outputs generally do not change once set in the editor or when play begins.

## Constant

The Constant expression outputs a single float value. It is one of the most commonly used expressions and can be connected to any input, regardless of the number of channels the input expects. For instance, if you connect a Constant to an input expecting a 3 Vector, the constant value will be used for all 3 elements. When supplying a single number, it can be useful to collapse the node using the small triangle icon in the description area.

Item

Description

Properties

R

Specifies the float value the expression outputs.

Examples: 0.7, -0.24, 1.1

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

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

The DistanceCullFade expression outputs a scalar value that fades from black to white and can be used to fade an object in once it comes within the cull distance. It should be noted that it does not fade the object out.

This network will cause the object to fade in (instead of "popping") once the camera comes within the cull distance.

## ParticleColor

The ParticleColor expression ties into the current color of a given particle based on any per-particle color data defined within Cascade. This must be plugged into the appropriate channel (Emissive Color).

Item

Description

Outputs

RGB

Outputs the combined RGB vector data.

R

Outputs the red channel data.

G

Outputs the green channel data.

B

Outputs the blue channel data.

A

Outputs the alpha channel data.

In this example, you can see where the ParticleColor expression is providing color to the particles as defined within the particle system.

## ParticleDirection

The ParticleDirection expression outputs Vector3 (RGB) data on a per-particle basis, representing the direction a given particle is currently traveling.

You can see in this image how the color of the particles is changing based on the current direction each particle is traveling.

The ParticleMotionBlurFade expression outputs a value representing the amount of fade on a particle as a result of motion blur. A value of 1 represents no blur, black represents complete blur.

The ParticleRadius expression outputs the radius in Unreal units of each particle individually. This allows, for example, for changes to be made to a material once the radius has reached a certain point.

In this image, the particles are shifting from green to red as their radius exceeds 7 units.

## ParticleRelativeTime

The ParticleRelativeTime expression outputs a number between 0 and 1 representing a particle's age, with 0 being the moment of birth and 1 being the moment of death.

In this example, you can see the particle relative time fed into the emissive color, resulting in particles that are fading from black at the moment of birth to white as they approach death.

## ParticleSize

The Particle Size expression outputs the X and Y size of a particle sprite. This can then be used to drive some aspect of a Material.

Click image for full view.

In the example above, Particle Size is being multiplied into Particle Color. Notice that we are masking the output so that we only use the Green channel, which corresponds to the Y-Axis, or the length of the particles. This means that as the particles stretch out, they become brighter in color. As they shrink, they will become dimmer.

## ParticleSpeed

ParticleSpeed outputs the current speed each particle is traveling, measured in Unreal units per second.

In this example, particle speed is feeding the color of the particles, which is then divided by 10 provide more meaningful results. The particles become black as they slow down.

The PerInstanceFadeAmount expression outputs a float value associated with the amount of fade applied to an instanced Static Mesh, such as foliage. It is constant, but can be a different number for each individual instance of a mesh.

This only works when applied to an InstancedStaticMesh Actor or other Actor which utilizes InstancedStaticMeshComponents.

## PerInstanceRandom

The PerInstanceRandom expression outputs a different random float value per Static Mesh instance to which the material is applied. InstancedStaticMeshComponent sets a random float for instance, which is exposed so that it can be used for whatever is desired (e.g. random light level behind a window). It is constant, but different, for each instance of the mesh.

The output value will be a whole number between 0 and RAND_MAX for the target platform.

This only works when applied to an InstancedStaticMesh Actor or other Actor which utilizes InstancedStaticMeshComponents.

## Time

The Time node is used to add the passage of time to a material, such as a Panner, Cosine, or other time-dependent operation.

Item

Description

Properties

Ignore Pause

If true, time will continue to march on even if the game is paused.

Period

If true, this will be the amount at which to wrap around time. On Mobile Materials, this will perform the Period computation on the CPU at full-precision, whereas on the GPU it will run at half precision (potentially having issues on periods longer than a minute).

The network described in the image above would create a Material that would change over time, constantly exhibiting a sinusoidal transition between white and black. If you enable period, setting period to 0 will effectively stop the transition and 1 will be as if period was false. Setting the number closer to 0 will make the material change at a more rapid pace.

## TwoSidedSign

The TwoSidedSign expression is useful for flipping the normal on backfaces of two sided custom lighting materials to match the functionality of Phong. +1 for frontfaces, -1 for backfaces of a twosided material.

## VertexColor

The VertexColor expression is the access point for the material to the outputs of color modules affecting sprite particles emitters.

Item

Description

Outputs

RGB

Outputs the three-channel RGB vector value of the color.

R

Outputs the red channel of the color.

G

Outputs the green channel of the color.

B

Outputs the blue channel of the color.

A

Outputs the alpha channel of the color.

The network above would utilize color and alpha data directly from a Particle System. Such networks are ideal for special effects such as sparks.

## View Property

The ViewProperty expression outputs a view dependant constant property such as the field of view or the render target size. The view property to be accessed can be configured, and the type of the output depends on the configured accessed property.

Here is the example with a field of view of 50 degrees.

Here is the same example with a field of view of 90 degrees.