WEKIT-ECS / MIRAGE-XR

MirageXR is a reference implementation of an XR training system. MirageXR enables experts and learners to share experience via XR and wearables using ghost tracks, realtime feedback, and anchored instruction.
Other
27 stars 4 forks source link

gltf shader materials missing #1951

Open fwild opened 2 weeks ago

fwild commented 2 weeks ago

It seems the shader materials for gltf URP are not included in the build, thus throwing an exception whenever a 3D model is imported from sketchfab.

fwild commented 2 weeks ago

The solution seems to be described here: https://github.com/atteneder/glTFast/blob/openupm/Documentation~/ProjectSetup.md#materials-and-shader-variants

fwild commented 2 weeks ago

And the old shaders can be removed from Project Settings > Graphics > Always included shaders, according to https://github.com/atteneder/glTFast/issues/212

fwild commented 2 weeks ago

To reduce the amount of shaders actually included, it seems possible to use shader variant collections: https://docs.unity3d.com/2022.3/Documentation/Manual/shader-variant-collections.html

fwild commented 2 weeks ago

This fix actually works (removing old shaders, and saving the currently tracked shaders/variants to an asset, and adding this asset to the Preloaded Shaders list.

fwild commented 2 weeks ago

My other changes seem to have blown up the archive, though, size is now 550MB and it compiled for hours... Need to clean up all the options of turning off shader stripping before, then this should - hopefully - go back to the ~ 200MB+.

BenediktHensen commented 2 weeks ago

Yes, same, I also implemented the changes for this today and the Android compile took around 8 hours because of the many shader variants that are now always included. We could try out the mentioned workaround to run Unity, load some models and then write the shader usage to an asset file. This asset file can then be added to the list of pre-loaded shaders. The only question is whether the Sketchfab import always uses the same range of shaders, in which case this would be a great optimization, or whether this would limit the variety of models that can be imported. I did some tests with randomly downloaded Sketchfab models and the shader usage file showed only two used shader variants from the gltf importer.

fwild commented 2 weeks ago

Weirdly, it seems that something in the project still uses the legacy built in render pipeline, from what I could see when it compiled, so it's probably just something to be checked/optimised - we should only use a few standard materials. From what I could see, the gltfast importer only uses 3 materials, all of them in the according shader graph sub folder in the package dir. Have you looked into the tracked assets file what it tracks? I would try to remove any non needed materials before we try the additional hack with the shader variant collections...

fwild commented 2 weeks ago

Oh, and adding the three materials to the list of always included shaders should come to the same effect as doing the check you suggest (and adding an additional tracked assets file to the lost of preloaded shaders. Btw: I read somewhere that the preloaded does not force build inclusion, it just loads them first thing when starting?

fwild commented 2 weeks ago

There is a subsection in Editor.log (this is stored in your local app data folder somewhere), which shows how many shader variants are there, and how many are left after stripping. For me, this section looks has some materials which are rather big. I can see, for example:

Compiling shader "Shader Graphs/glTF-pbrSpecularGlossiness" pass "Universal Forward" (vp)
    Full variant space:         12884901888
    After settings filtering:   2097152
    After built-in stripping:   8192
    After scriptable stripping: 8192

and

Compiling shader "Shader Graphs/glTF-pbrSpecularGlossiness" pass "BuiltIn Forward" (vp)
    After scriptable stripping: 24576
Compiling shader "Shader Graphs/glTF-pbrSpecularGlossiness" pass "BuiltIn ForwardAdd" (vp)
    After scriptable stripping: 3072
Compiling shader "Shader Graphs/glTF-pbrSpecularGlossiness" pass "BuiltIn Deferred" (vp)
    After scriptable stripping: 6144
Compiling shader "Shader Graphs/glTF-pbrMetallicRoughness" pass "Universal Forward" (vp)
    After scriptable stripping: 16384
Compiling shader "Shader Graphs/glTF-pbrMetallicRoughness" pass "BuiltIn Forward" (vp)
    After scriptable stripping: 49152
Compiling shader "Shader Graphs/glTF-pbrMetallicRoughness" pass "BuiltIn ForwardAdd" (vp)
    After scriptable stripping: 6144

et cetera