Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader variants for RPM avatar missing when loaded in addressable scene #715

Open
BorisDex opened this issue Aug 30, 2024 · 2 comments
Open
Labels
bug Something isn't working import Import of glTF files run-time
Milestone

Comments

@BorisDex
Copy link

I’ve encountered an issue with shader variants when loading GLTF objects into an addressable scene: some materials look wrong (no transparency, wrong lighting...).
After investigating, I discovered that the necessary shader variant was missing, causing Unity to apply a fallback shader. To troubleshoot, I enabled strictShaderVariantMatching in the Project Settings/Player, which resulted in numerous ‘Shader Shader Graphs/glTF-pbrMetallicRoughness, subshader 0, pass 0, stage pixel: variant SHADOWS_SHADOWMASK _ADDITIONAL_LIGHTS _MAIN_LIGHT_SHADOWS_CASCADE _SHADOWS_SOFT _SURFACE_TYPE_TRANSPARENT not found.’ errors.

I confirmed that glTFastShaderVariantsURP.shadervariants is included in the PreloadedShaders array, so I was puzzled by this issue. Loading an object into a built-in scene worked as expected. However, loading the same object into a scene loaded from Unity Addressables resulted in missing shader variants.

I’ve created a test project to demonstrate this issue: https://github.com/dnnkeeper/UnityRPMLoadingTest

After discussion in forum I managed to pin down that ShaderGraphMaterialGenerator is unable to find suitable shader using Shader.Find method because shader is loaded with the Addressable system.

I replaced Shader.Find method with this code, and my issue was resolved after I added glTF-pbrMetallicRoughness.shadergraph as Shader Graphs/glTF-pbrMetallicRoughness to addressable group

        protected static Shader FindShader(string shaderName, ICodeLogger logger)
        {
            var shaderLoading = Addressables.LoadAssetAsync<Shader>(shaderName);
            Shader shader = shaderLoading.WaitForCompletion();

            if (shader != null)
            {
                return shader;
            }

            shader = Shader.Find(shaderName);
            if (shader == null)
            {
                logger?.Error(LogCode.ShaderMissing, shaderName);
            }
            return shader;
        }

It seems that GLTF package needs to reference the Addressable system and use this loading method when this system is present.

@BorisDex BorisDex added the bug Something isn't working label Aug 30, 2024
@atteneder
Copy link
Owner

@BorisDex Thanks for reporting and putting in the effort to pin it down!

I think this would be a meaningful addition, given it's wrapped in a version define and documented properly.

@atteneder atteneder moved this from To do to Runtime Loading in glTFast development Sep 4, 2024
@atteneder
Copy link
Owner

After giving it some more thought we concluded that it's probably a better solution to create an injection point for FindShader. Users are then able to implement their own shader lookup solution without introducing fixed heuristics for Addressables.

I cannot offer a timeline yet.

@atteneder atteneder added import Import of glTF files run-time labels Dec 10, 2024
@atteneder atteneder added this to the 6.x milestone Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working import Import of glTF files run-time
Projects
Status: Planned
Development

No branches or pull requests

2 participants