Browse Source

feat: Modifying material parameters at runtime

Eideren 8 months ago
parent
commit
762f906d5a

+ 20 - 1
en/manual/graphics/materials/materials-for-developers.md

@@ -13,9 +13,28 @@ This diagram shows the Material interfaces and implementation classes:
 - The @'Stride.Rendering.Materials.MaterialDescriptor' is the editor-time description of the material before being compiled into a material shader.
 - The @'Stride.Rendering.Material' class is the runtime material shader generated from the @'Stride.Rendering.Materials.MaterialDescriptor'
 
+# Modifying parameters at runtime
+
+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.
+
+Let's say you have this fairly simple material
+![media/runtime-param-modif-ex.png](media/runtime-param-modif-ex.png)
+
+And you want to clone that material, but change its color to red at runtime.
+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:
+```csharp
+var clone = SerializerExtensions.Clone(MyMaterial);
+clone.Passes[0].Parameters.Set(MaterialKeys.DiffuseValue, new Color4(1, 0, 0));
+```
+
+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. 
+Here's an example of that through Rider's *Threads & Variables* window:
+
+![media/runtime-param-modif-locals.png](media/runtime-param-modif-locals.png)
+
 ## See also
 
 - [Material maps](material-maps.md)
 - [Material attributes](material-attributes.md)
 - [Material layers](material-layers.md)
-* [Material slots](material-slots.md)
+- [Material slots](material-slots.md)

+ 3 - 0
en/manual/graphics/materials/media/runtime-param-modif-ex.png

@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bf507484386e59077fe3ce5158558b30f638edadf20401da2d571d7f8279346b
+size 19221

+ 3 - 0
en/manual/graphics/materials/media/runtime-param-modif-locals.png

@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a92fa951002c8cceae555a212d0c167e1bad4e99720b96408588593d2064512f
+size 97890