Unity Shader Compilation strips keyword STEREO_MULTIVIEW_ON on GLES3

I am developing my own Unity XR plugin but I’m having trouble getting the Multiview (Singlepass) feature to work.

After inspecting the shaders by compiling and showing the code, I discovered that Unity is not using the STEREO_MULTIVIEW_ON keyword to compile them. However, the Oculus XR Plugin does use this keyword to compile my shaders.

I’m confused as to why STEREO_MULTIVIEW_ON is being stripped in my implementation.

There are a lot of restrictions for this mode. Do you meet all of them?

If yes, try disabling shader variant stripping in the graphics options just to see if that’s the problem.

hi, c0d3_m0nk3y, my device support the multi view extension, and if I import package of OculusXR and not check it (still use my own Unity XR Plugin), then the shader would be compiled with the keyword STEREO_MULTIVIEW_ON. I would finally get what I want.

By the way, how to disable shader variant stripping?

Thanks!

hi, c0d3_m0nk3y.
In the graphics options, I have disabled shader variant stripping, by choose option “Strip Unused” or “Keep All” in the Shader Stripping → Instancing Variants. It still doesn’t work.

I guess maybe Unity should be “told” now it is in XR mode then can he choose to use the relative keywords for compiling shaders. However, how to tell Unity this.

That’s very much possible if you are developing your own XR plugin. Maybe you can look at the source code of the XR package in the Library directory and find out how the package is doing it.

See Library/PackageCache/com.unity.render-pipelines.universal@10.8.1/Runtime/XR/XRPass.cs

        internal void StartSinglePass(CommandBuffer cmd)
        {
            if (enabled)
            {
                if (singlePassEnabled)
                {
                    if (viewCount <= TextureXR.slices)
                    {
                        if (SystemInfo.supportsMultiview)
                        {
                            cmd.EnableShaderKeyword("STEREO_MULTIVIEW_ON");
                            cmd.SetGlobalVectorArray("unity_StereoEyeIndices", stereoEyeIndices);
                        }
                        else
                        {
                            cmd.EnableShaderKeyword("STEREO_INSTANCING_ON");
                            cmd.SetInstanceMultiplier((uint)viewCount);
                        }
                    }
                    else
                    {
                        throw new NotImplementedException($"Invalid XR setup for single-pass, trying to render too many views! Max supported: {TextureXR.slices}");
                    }
                }
            }
        }
1 Like