0
Completed
Chase Pettit ✌ 7 months ago • updated by chrispark7 2 months ago 7

It would be nice to have an easy way to mark properties with the PerRendererData attribute in ShaderForge so that no manual editing of the shader code is required to effectively use MaterialPropertyBlock.

Answer

Answer
Completed

It appears to only for textures (https://docs.unity3d.com/Manual/SL-Properties.html), which SF already supports. Do correct me if I'm wrong though!


In case you just need it for textures, you can right-click on texture assets and texture 2D nodes to tag them with PerRendererData

Answer
Completed

It appears to only for textures (https://docs.unity3d.com/Manual/SL-Properties.html), which SF already supports. Do correct me if I'm wrong though!


In case you just need it for textures, you can right-click on texture assets and texture 2D nodes to tag them with PerRendererData

I was under the impression that any shader property that's intended to be set through a MaterialPropertyBlock (https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html) should be given the PerRendererData attribute.


Unity will generally allow you to set any shader attribute through a MaterialPropertyBlock regardless of whether or not it has the PerRendererData attribute, but in the cases where it doesn't, I believe it will create a new material instance, essentially eliminating the benefit of using MaterialPropertyBlock. I may need to do some testing to verify that is in fact the case though.

OK. After some testing, it looks like I there's a lot of inaccurate info about MaterialPropertyBlock floating around the internet, including about how the PerRendererData attribute should be used.


Apologies for the distraction.

Was just looking for this option in Shader Forge myself. I was also under the impression (based on probably the same internet information I came across) that the PerRendererData tag was required for not generating the extra instance of the material. Just curious what you discovered exactly through your testing, and which information is inaccurate.

As far as I can tell through both looking at the profiler and directly checking material references, you can set any non-texture property of a material through MaterialPropertyBlock without giving it the PerRendererData attribute and it won't create a new instance of the material.


All of Unity's own documentation appears to be consistent with this. Unity also makes mention here of internally using MaterialPropertyBlock to set color, scale, and wind factors on tree materials, and if you go take a look at the built-in tree shaders, you'll see that they aren't using the PerRendererData attribute on any of the color/scale/wind related properties.


For the record, this is all based on what I'm seeing in Unity 5.4. I don't know if this may have been different in previous versions.

As of unity 5.6, it seems like there are a variety of things supposed to be set for instanced properties: https://docs.unity3d.com/Manual/GPUInstancing.html