Shader for Quest 2: 自定义shader在Unity Editor中可以使用,但是在Quest 2中却不可以

csharp 复制代码
GameObject segment = GameObject.Find("DisplayArea_" + i);
MeshRenderer renderer = segment.GetComponent<MeshRenderer>();
Material mat = new Material(Shader.Find("Custom/MyShader")); 
mat.mainTexture = option.Image360;

上面这份代码,在Unity Editor中可以使用,但是编译到Quest 2之后,却没有反应。这可能是由于多种原因引起的,可以按照下面的步骤修改。

设置Graphics

如果使用Visual Studio联调的话,可能会看到这个报错:

System.ArgumentNullException: Value cannot be null.

Parameter name: shader

解决方案:

Go to the graphics settings in Unity (Edit > Project Settings > Graphics) and make sure your custom shader is included in the list of always included shaders . This ensures the shader is compiled into the build.

设置Graphics API

The Oculus Quest 2 primarily uses OpenGL ES and Vulkan.

确保shader compatible with the Graphics API

其他

如果还不行,那可能是其他代码逻辑的问题,或者是shader的问题。那可以先写一个简单的shader,例如简单变成红色,赋值到一个default cube or sphere上,一步一步地看是哪里出了问题。

相关推荐
zhangphil12 小时前
Unity3D(Unity)跨平台游戏引擎简介
unity
Madokaly13 小时前
DOTween动画:TweenManager深度解析
unity
_ZHOURUI_H_1 天前
Unity TCP底层极限拆解:粘包、半包、CRC、序列号、双缓冲到底怎么一起工作的?
网络·网络协议·tcp/ip·游戏·unity·游戏引擎·游戏开发
KindSuper_liu2 天前
Unity 游戏网络基础:从 TCP、UDP 到 HTTP、TLS 与 Best HTTP
网络·游戏·unity
qq_170264752 天前
unity里GameObject和Texture的内存归属
java·unity·游戏引擎
weixin_404679312 天前
godot + vscode ai开发
ide·vscode·编辑器·游戏引擎·godot
还是大剑师兰特2 天前
Unity3D(Unity)完整详细介绍
unity·游戏引擎
ellis19702 天前
u3d插件xLua[七]例6 Coroutine
unity
逐米时代2 天前
沉浸式培训与现场协同:AR/VR表达复杂空间关系
ar·vr
Mixr_immersive3 天前
摆脱业态同质化!VR大空间CS如何成为文旅场馆吸金刚需项目
vr