Table of Contents

Class MaterialParameters

Namespace
Stride.CommunityToolkit.Rendering
Assembly
Stride.CommunityToolkit.dll

Changes a compiled material at runtime through its parameters, the way the engine's own gizmo materials do: no rebuild, the value is picked up by the next draw.

public static class MaterialParameters
Inheritance
MaterialParameters

Remarks

Once Material.New has run, the features are gone; what remains is a shader and the constants the features registered. A number in a slot registers under the slot's key (GlossinessValue, EmissiveIntensity); a colour or texture node can carry a key of your own (new ComputeColor(Color.White) { Key = MaterialParameters.ColorKey("MyGame.Tint") }), which is how a value is animated without touching the shader. Every texture node also registers its scale and offset, so a texture scrolls through SetTextureOffset(Material, Vector2, int) with no recompile.

Two things the generator did at compile time have to be repeated for a colour set at runtime, or the two disagree: it converted the colour from sRGB to linear and premultiplied it by its alpha. SetColor(Material, ValueParameterKey<Color4>, Color4, bool) does both. And a material may have several passes (clear coat two, hair three, thin glass two or four), each with its own parameters, so every setter here writes to all of them.

Methods

ColorKey(string)

A colour key of your own for a ComputeColor node, named so it reads in a debugger.

public static ValueParameterKey<Color4> ColorKey(string name)

Parameters

name string

A unique name, such as "MyGame.Tint".

Returns

ValueParameterKey<Color4>

FloatKey(string)

A number key of your own for a ComputeFloat node.

public static ValueParameterKey<float> FloatKey(string name)

Parameters

name string

A unique name, such as "MyGame.Wear".

Returns

ValueParameterKey<float>

SetColor(Material, ValueParameterKey<Color4>, Color, bool)

Sets a colour parameter on every pass, from a byte colour, converted like the generator would.

public static void SetColor(this Material material, ValueParameterKey<Color4> key, Color colour, bool premultiply = true)

Parameters

material Material
key ValueParameterKey<Color4>
colour Color
premultiply bool

SetColor(Material, ValueParameterKey<Color4>, Color4, bool)

Sets a colour parameter on every pass, converted the way the generator converted the node's initial value: to linear, and premultiplied by its alpha unless premultiply is off.

public static void SetColor(this Material material, ValueParameterKey<Color4> key, Color4 colour, bool premultiply = true)

Parameters

material Material

The material.

key ValueParameterKey<Color4>

The colour's key: one of MaterialKeys, or the key the node was given.

colour Color4

The colour, in sRGB, as you would write it.

premultiply bool

Whether to premultiply by alpha; the node's default is to.

SetTextureOffset(Material, Vector2, int)

Sets the offset of a texture node on every pass, in UV units: raise it every frame and the texture scrolls, with no recompile.

public static void SetTextureOffset(this Material material, Vector2 offset, int textureIndex = 0)

Parameters

material Material

The material.

offset Vector2

The offset, in UV units.

textureIndex int

Which texture node, 0 for the first.

SetTextureScale(Material, Vector2, int)

Sets the tiling of a texture node on every pass: how many times it repeats across the UV range. The diffuse texture is the material's first, the others follow in the order the generator visited the slots.

public static void SetTextureScale(this Material material, Vector2 scale, int textureIndex = 0)

Parameters

material Material

The material.

scale Vector2

The tiling; the node's default is one.

textureIndex int

Which texture node, 0 for the first.

Set<T>(Material, ObjectParameterKey<T>, T)

Sets an object parameter - a texture, a sampler - on every pass of the material.

public static void Set<T>(this Material material, ObjectParameterKey<T> key, T value) where T : class

Parameters

material Material
key ObjectParameterKey<T>
value T

Type Parameters

T

Set<T>(Material, ValueParameterKey<T>, T)

Sets a value parameter on every pass of the material.

public static void Set<T>(this Material material, ValueParameterKey<T> key, T value) where T : struct

Parameters

material Material
key ValueParameterKey<T>
value T

Type Parameters

T

TextureKey(string)

A texture key of your own for a ComputeTextureColor or ComputeTextureScalar node.

public static ObjectParameterKey<Texture> TextureKey(string name)

Parameters

name string

A unique name, such as "MyGame.Screen".

Returns

ObjectParameterKey<Texture>

TextureKeyAt(ValueParameterKey<Vector2>, int)

The key a texture node's scale or offset registered under: the base key for the first texture, then the base key composed with i1, i2 and so on, which is how the generator names a key's later uses.

public static ValueParameterKey<Vector2> TextureKeyAt(ValueParameterKey<Vector2> key, int textureIndex)

Parameters

key ValueParameterKey<Vector2>

TextureScale or TextureOffset.

textureIndex int

Which texture node, 0 for the first.

Returns

ValueParameterKey<Vector2>

ToMaterialValue(Color4, bool)

What a ComputeColor node's value becomes in the material's constants: linear, and premultiplied by its alpha. Setting the raw sRGB colour instead makes the runtime value brighter than the one compiled in.

public static Color4 ToMaterialValue(Color4 colour, bool premultiply = true)

Parameters

colour Color4

The colour, in sRGB.

premultiply bool

Whether to premultiply by alpha.

Returns

Color4