First, I built every single prefab into individual AssetBundle but didn’t build all the shaders into a single AssetBundle. So every prefab AssetBundle would contain a copy of the shader it used. This way GPU instancing worked successfully and game objects instantiated from the same prefab would be batched.
Second, I built all the shader into a single AssetBundle. So every prefab AssetBundle would depend on the shader AssetBundle. However, i found the GPU instancing didn’t work as expected. Does anybody know why? Thanks~
I used Unity5.6.1f1
Check the Graphics Setting Shader stripping Instancing Variants. choose Keep all ~
Sorry, it’s useless to me when targeting android and ios, weird. Any other ideas?
Okay, solved by adding a shader variant collection file in the same assetbundle along with the shader file. A instancing variant which enabled keyword “INSTANCING_ON” must be included in the shader variant collections.
Hi hearstzhang, I came across the same problem recently. Could you tell me more about how you used the ShaderVariantCollection? Did you manually create your own ShaderVariantCollection file and assigned it to preloaded shaders in GraphicSettings, or you just preload the shaders via scripts(WarmUP)? How about the Shader Strip setting? is it Strip Unused or Keep all?
No, shader variant collection seems useless when you try to pack it into the same assetbundle along with the shader you want.
The key to the result is that, go to graphics settings, and adjust “Shader stripping” area.
But if you want to keep everything and strip nothing, some built-in shaders such as Standard shader will become huge.
So here’s another solution. You have to make sure that Unity “know” which shader variant you want. For example, if you want to use this shader in your Scene, you should pack the shader the same time Unity pack this scene. What I mean is you pack your shader and your Scene in same AB. And if you want to use this shader with some renderers, and you built a material for such purpose, you pack your shader and the material in the same AB as well. By the way, do not include it in “Always included shader”, which does not mean strip nothing, keep everything. This is the ultimate solution if you don’t want to modify Shader stripping settings.