Big problem with materials


If I send the same material to different models, when I change a shader of the material this affect to all models.
I just want change the material of a specifiq model.

I tested clone, addManualResource, but not work.

Is possible to make different materials with the same resource?

Thank you.

If you want per-object material changes, Clone() the material and make the changes to the clone. Note that in this case optimizations such as instancing can’t be applied, instead each model using a unique material will be its own draw call.

There was a recent bug related to Clone() and shader parameter changes not working as expected, so I recommend to pull the latest master.

Shader is specified in technique / pass, so in this case you would also need to make a copy of the technique and make sure the original is not changed. Currently Technique doesn’t have a Clone() function so I’d recommend pre-authoring the needed techniques with different shaders as actual files.

This could be helpful: … _per_model

Now also Technique::Clone() is implemented in the master branch, using that you can change the shader. However be aware of all the passes you need to change (e.g. forward lighting base pass, and per-pixel light pass, and optimized first light base pass)

I’ve been using GetTempResource() for this. Is that dangerous or inefficient? Seems more direct in some cases.
I guess you may have a pointer lying around somewhere and then Clone() would be more convenient.

GetTempResource() is not dangerous, but causes a reload from disk each time it’s called, while Clone() would work in memory.

Check, thanks for clearing that up.