- Home /
Single pass (multiview) with OpenGLES3 or Vulkan behaves unexpected when building on Oculus Quest 2
So I am trying to use single pass or in oculus case multiview for my VR application. Now I have noticed weird behavior with the shader that I am using. This is with Unity version 2020.1.13f1 and OpenGLES3.
I import an asset bundle via script that has an object with a texture and shading on it, when I try to build this its just black and I get this error "Runtime/GfxDevice/opengles/GfxDeviceGLES.cpp Line: 353. OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_OPERATION: Operation illegal in current state".
Now the weird thing about this is when I put the same object with texture and shader in my project instead of loading it via assetbundles and then build it it works fine.
In my shader I have currently set:
#pragma multi_compile __ UNITY_STEREO_MULTIVIEW_ENABLED
#pragma multi_compile_instancing
In appdata
UNITY_VERTEX_INPUT_INSTANCE_ID
In struct v2f
UNITY_VERTEX_OUTPUT_STEREO
In v2f vert
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
GPU Instancing is also enabled.
I don't quite understand how this happens so any help would be appreciated!
Answer by BigFluffyCookie · Jan 20, 2021 at 12:32 PM
Alright so I figured something out. The reason why the shader would work when in the project but not when in an asset bundle that gets loaded in during runtime seems to be that the shader got compiled in a different unity project when creating the asset bundle and the macros for vertex stereo output seem to get ignored (even with #pragma multi_compile_instancing defined in the shader!). Since the asset bundle is already built for the target platform unity won't recompile the shader when building the application so it doesn't contain necessary shader code for single-pass stereo.
So now because in the project the asset bundle was built in multi-view wasn't enabled,the shader was apparently not compiled to support single-pass stereo.
So basically the solution is to have multiview enabled (and the correct graphic API enabled) in whatever project the assetbundles are built in.
Also in case this is relevant for anyone else when building for android theres different macros for the shaders, not the one I have in my original question.
https://docs.unity3d.com/Manual/Android-SinglePassStereoRendering.html
However - I'm surprised by this behaviour, because I did set "Instancing Variants" in Project Settings -> Graphics -> Shader Stripping to "Keep All" in the project in which I'm building the asset bundles. I was under the assumption that this exactly should prevent that the shader code required for single-pass stereo would be stripped out (https://docs.unity3d.com/Manual/class-GraphicsSettings.html). Is this a bug or is this a different class of shader stripping which can currently not be controlled in Unity?
Is this worthy of a bug report or is this intended behaviour?
I just spent 5 hours trying to figure out why my asset bundles weren't appearing in builds, but were clearly there because the overhead map cam was rendering them... When I finally figured out that the issue was tied to Multiview, your post popped up and gave my life meaning again. You are an absolute legend.
Answer by spatialwb · May 29 at 03:20 AM
We had a similar issue, and it turned out that our AndroidMobile build and Meta Quest (Oculus) builds were using the same addressable catalog.
By default the catalog naming is done with a hash (a hash of all the bundles that are contained in the catalog), but we opted for a more human readable name for us, which resulted in two separate builds writing to the same catalog json file.
We resolved it by making the catalog name unique per target platform.
/Android/catalog_6.19.1.47468.json -> /Android/catalog_6.19.1.47468_MetaQuest.json
/Android/catalog_6.19.1.47468.json -> /Android/catalog_6.19.1.47468_AndroidMobile.json
TLDR: our Quest app was sometimes loading AndroidMobile bundles, and our AndroidMobile app was sometimes loading Quest bundles.
Your answer
Follow this Question
Related Questions
[Oculus Rift] AvatarSurfaceShaderSelfOcluding.shader will not import 0 Answers
unity 5.6 assetbundle shader name lost 2 Answers
How to load material with Unlit/Transparent Shader from Assets bundle 0 Answers
Missing shader variants/features in asset bundles 2 Answers
Streamed textures appearing as default white only on iOS 0 Answers