Hi, I am looking for a way to during runtime change values of a shader graph shader, specifically enabling emission (or same effect could be achieved by changing value of a mix or color node?) My idea is to
but I’d like to do more than just change a specific material, it’d be nice to get a method that could be used with multiple objects in game without making specific materials for each.
this code swaps the material between startColor and hoverColor depending on how close the player is to the object. What I am looking for is a way to have just one shader, and enable/disable the emission node section somehow.
The property name used by SetColor when using Shader Graph is a property’s reference string, which you can set by expanding a property in the blackboard. By default Shader Graph generates a random string of gobbledygook for the reference, which you can use, or you can rename it to something sane. Then it’s just a matter of using material.SetColor("_MyPropertyReferenceName", myColor); to override the material’s color.
A better way of modifying material properties per-renderer is to use a MaterialPropertyBlock. Using that with Renderer.SetPropertyBlock() will let you temporarily override a material’s properties without generating a new material. You can set it back to the original settings by clearing the block and calling SetPropertyBlock() again with the cleared block, or just call rend.SetPropertyBlock(null).
Maybe a bit late, but I changed values of a shader at runtime through
a) exposed property in shader graph
b) through a script and changed the value (with or without instantiation of the material)
Any way to add properties to a shader graph at runtime? I want to add vec3s for positions for the shader to react to and need to have the number of them extensible.