Skip to content

Commit 56097ad

Browse files
authored
Merge pull request #398 from Eideren/material_prop
feat: Modifying material parameters at runtime
2 parents 813aaf7 + 762f906 commit 56097ad

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

en/manual/graphics/materials/materials-for-developers.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,28 @@ This diagram shows the Material interfaces and implementation classes:
1313
- The @'Stride.Rendering.Materials.MaterialDescriptor' is the editor-time description of the material before being compiled into a material shader.
1414
- The @'Stride.Rendering.Material' class is the runtime material shader generated from the @'Stride.Rendering.Materials.MaterialDescriptor'
1515

16+
# Modifying parameters at runtime
17+
18+
The file @'Stride.Rendering.Materials.MaterialKeys' contains most material keys you might need to use, have a look through it to figure out which one you might need to get to modify the parameter you are interested in.
19+
20+
Let's say you have this fairly simple material
21+
![media/runtime-param-modif-ex.png](media/runtime-param-modif-ex.png)
22+
23+
And you want to clone that material, but change its color to red at runtime.
24+
Searching through the different keys contained in @'Stride.Rendering.Materials.MaterialKeys' you would find `MaterialKeys.DiffuseValue` and use it as the key to set the new color value you want:
25+
```csharp
26+
var clone = SerializerExtensions.Clone(MyMaterial);
27+
clone.Passes[0].Parameters.Set(MaterialKeys.DiffuseValue, new Color4(1, 0, 0));
28+
```
29+
30+
If you aren't too sure which parameter keys your material uses, the best way to figure it out would be to inspect the material's variables with a debugger.
31+
Here's an example of that through Rider's *Threads & Variables* window:
32+
33+
![media/runtime-param-modif-locals.png](media/runtime-param-modif-locals.png)
34+
1635
## See also
1736

1837
- [Material maps](material-maps.md)
1938
- [Material attributes](material-attributes.md)
2039
- [Material layers](material-layers.md)
21-
* [Material slots](material-slots.md)
40+
- [Material slots](material-slots.md)
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)