- Home /
Shader compile spikes
Hi all,
I have a scene that has some particle systems and SpriteRenderers in it. There is not much active Monobehaviours in it. And there is a camera movement that shows different parts of the scene. The problem is when camera starts moving it seems very laggy. I connect my ios devices (ios 9) to profiler and get some screenshots. It seems that spikes are caused by some renderers that decide to compile shaders at the first time that they go visible. The cause of spikes might be different but here are the screenshots.
cpu profile on spike
cpu profile on normal time
I know that i can do something like
void compileShaders() {
var rendererList = FindObjectsOfType<Renderer>();
for (int i = 0; i < rendererList.Length; i++) {
var materials = rendererList[i].sharedMaterials;
for (int j = 0; j < materials.Length; j++) {
var material = materials[j];
// compile shader with some code (thats not what im asking)
}
}
}
My question is; Are there some more elegant ways of doing it in unity? For example, some setting like "compile shaders at scene load" or "compile shaders at prefab load" or "compile shaders at material load" or maybe there is a different kind of aproach.
Any help will be appreciated.
Answer by tanoshimi · Nov 30, 2016 at 03:54 PM
This is what ShaderVariantCollections are for, which should then be specified under the "Preloaded Shaders" list in Graphics Settings.
Awesome! That's the kind of the answer that I'm looking for.
Your answer
Follow this Question
Related Questions
Why does "Clear" under Render.OpaqueGeometry spike every few frames in WebGL? 0 Answers
Shader.Parse overhead 0 Answers
Oculus rendeing bug 0 Answers