The problem here is that this shader doesn’t work with instancing if light probes are enabled (it’s refuses to instance at all, the Frame Debugger states that “The objects are affected by different light probes”. If I force the mesh renderers not to use light probes then the instancing works. Instancing will also work if I will have “Always” as a “LightMode” tag value (or remove the tag entirely). UnityCG.cginc is unmodified.
Due to no reasonable documentation for adding instancing with light probes and/or lightmaps support and having no luck finding the answer in the standard shader and generated surface shader, I ask here: how can I do this and where can I find direct examples of the implementation? Thank you.
The TLDR is you need to use a Light Probe Proxy Volume, aka a LPPV.
Or you need to manually calculate and pass the light probe data to shaders as the built in probe data isn’t setup to be instanced. But converting the probe data to what Unity’s shaders use isn’t exposed anywhere in Unity’s code, so you have to search online for how to calculate that data from the interpolated probe data. And Unity breaks instancing even with a LPPV, so even then it doesn’t work properly even through it should.
But wait, that doesn’t add up at all… Standard shader and surface shaders can all use instancing with light probes, they don’t need LPPV at all. I dug in them and the generated surface shader code and found no signs of them manually calculating/interpolating the SH data. I do not draw my meshes using C# apis, they are drawn using Mesh Renderers, so the SH data needs to be calculated nicely by Unity itself if the standard and surface shaders can work with them.
The manual even states this: “You can use GPU Instancing to automatically batch dynamic Mesh Renderers affected by baked Light Probes (including their occlusion data)”, but there’s no explanation on how to actually implement it (hence me stating about no manual on implementing more “advanced” instancing features).
Finally, UnityInstancing.cginc actually has redefinitions of SH data to point to an array, just like with transform matricies, so that most certainly has to be working.
Hmm, you’re right. They’ve updated instancing w/ light probes since I last looked at this. Ideally there shouldn’t be anything you need to do to make instancing work then. The fact that it doesn’t seems like a bug.