Global/common/programmable shader materials

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gmaps

I added a basic fog of war to my game, texture 512*512 and I would like all objects to be shaded based on that texture. For a single object I have to convert the material from spatial to shader material, copy the shading function which checks whether the object is in fog and does bilinear interpolation, and feed the texture to the shader. I have to do this flow for all the materials. Is there an option to do it programmatically, so I don’t have to do it manually for each material? Or at least share/import function in material shaders so if I want to update the function, I don’t have to update it in million materials?

Have you looked at running code in the editor? For one of my projects, I had to iterate through a bunch of mesh objects and change the SpaitalMaterial for each object. I used a script with the tool keyword to achieve that.

Ertain | 2019-08-27 08:34

Yes, I was thinking in that direction, but unless I can call “convert spatial material to shader” in code, it doesn’t help me.

gmaps | 2019-08-27 11:15