Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved Unity Shader Compilation strips keyword STEREO_MULTIVIEW_ON on GLES3

Discussion in 'General Graphics' started by Xxxxxxxu, Sep 5, 2023.

  1. Xxxxxxxu

    Xxxxxxxu

    Joined:
    Aug 1, 2017
    Posts:
    12
    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.
     
    Last edited: Sep 6, 2023
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    691
    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.
     
  3. Xxxxxxxu

    Xxxxxxxu

    Joined:
    Aug 1, 2017
    Posts:
    12
    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!
     
  4. Xxxxxxxu

    Xxxxxxxu

    Joined:
    Aug 1, 2017
    Posts:
    12
    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.
     
  5. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    691
    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.
     
  6. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    691
    See Library/PackageCache/com.unity.render-pipelines.universal@10.8.1/Runtime/XR/XRPass.cs

    Code (CSharp):
    1.         internal void StartSinglePass(CommandBuffer cmd)
    2.         {
    3.             if (enabled)
    4.             {
    5.                 if (singlePassEnabled)
    6.                 {
    7.                     if (viewCount <= TextureXR.slices)
    8.                     {
    9.                         if (SystemInfo.supportsMultiview)
    10.                         {
    11.                             cmd.EnableShaderKeyword("STEREO_MULTIVIEW_ON");
    12.                             cmd.SetGlobalVectorArray("unity_StereoEyeIndices", stereoEyeIndices);
    13.                         }
    14.                         else
    15.                         {
    16.                             cmd.EnableShaderKeyword("STEREO_INSTANCING_ON");
    17.                             cmd.SetInstanceMultiplier((uint)viewCount);
    18.                         }
    19.                     }
    20.                     else
    21.                     {
    22.                         throw new NotImplementedException($"Invalid XR setup for single-pass, trying to render too many views! Max supported: {TextureXR.slices}");
    23.                     }
    24.                 }
    25.             }
    26.         }
     
    Xxxxxxxu likes this.