Materials for developers
Advanced Programmer
This diagram shows the Material interfaces and implementation classes:
- The interface IMaterialDescriptor is the root interface for a material description.
- The IMaterialShaderGenerator is the main interface used to generate a material shader of the material.
- Each attribute and layer implements this interface to modify the final material shader.
- The MaterialDescriptor is the editor-time description of the material before being compiled into a material shader.
- The Material class is the runtime material shader generated from the MaterialDescriptor
Modifying parameters at runtime
The file 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
And you want to clone that material, but change its color to red at runtime.
Searching through the different keys contained in MaterialKeys you would find MaterialKeys.DiffuseValue
and use it as the key to set the new color value you want:
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: