About shaders included in assetbundles
Dear all.
I created an assetbundle which includes all shaders being used in a scene, and some 3D models using those shaders are bundled separately. In short,
Asset Bundle 0 : shared shaders
Asset Bundle 1 : A 3D model. Its material uses a shader in 'Asset Bundle 0'.
Asset Bundle 2: A 3D model. This one also has a material uses a shader in 'Asset Bundle 0'.
Here is the problem.
When I load Asset Bundle 0, 'Shader.Parse' is called for all shaders included
in Asset Bundle 0.
So I expected all necessary shader compilations have to be done here,
but after this, when I load Asset Bundle 1 and Asset Bundle 2,
'Shader.Parse' is executed again and again on a same named shader which is included in Asset Bundle 0 although its compilation would have done when Asset Bundle 0 had loaded.
(I caught this result from Unity Profiler)
Are they different shader instances even though its shader name & code is same?
If they are, did I miss some necessary settings to share shaders between asset bundles?
I have spent half day to find a solution but all I found are out-dated ones related to 'BuildPipeline.PopAssetDependencies'.
A post below was quite useful but not enough.
http://forum.unity3d.com/threads/new-assetbundle-build-system-in-unity-5-0.293975/
Did I miss something important?
If so, how do I share custom shaders correctly among assetbundles and avoid unnecessary shader compilations?
Hello, sorry to necro this post, but how do you build AB1 and AB2 without shaders? Was it enough to assign shader to AB0 and build it together? I have multiple scenes which are using the same shaders over and over, but because I am building the scene as AB, unity is packing every shader multiple times to every scene AB which takes a lot of time. I was thinking about separating the shaders to their own AB as you are.
Answer by SuperHero · Feb 12, 2016 at 12:56 AM
Solved.
AssetBundle0 has to be built with 1 & 2.
and after loading it in a scene, I have to keep shader instances inside AssetBundle0 if I want to control its deletion time.
But still there are some problmes.
1. Built-in shaders: even though I set them as preloaded shader, still it takes long time to compile them on runtime.
2. How do aseetbundled materials work with 'Always includes shaders' on Graphics setting?
Your answer
Follow this Question
Related Questions
Anyway to detect for missing material from Renderer component? 1 Answer
Sorting (rendering) order of materials in mesh renderer 1 Answer
I can see the objects through the terrain. 1 Answer
Material.SetTexture doesn't work if not "_MainTex" 0 Answers
Assetbundled materials / Always Included Shaders / Preloaded Shaders 0 Answers