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上,一步一步地看是哪里出了问题。

相关推荐
微三云生态系统架构师-彭丹13 小时前
任务卷轴积分系统架构设计:从任务状态机到合规风控的完整实现
unity·系统架构·游戏引擎
独立开发之道14 小时前
Three.js 创建 VR 内容:四步把一个普通 3D 场景送进头显
javascript·3d·vr
XR技术研习社15 小时前
从 PICO 文档看未来短期内的 Unity 版本选择
unity·游戏引擎·xr·vr
玖玥拾17 小时前
Unity 热更新(一)
unity·游戏引擎
软件黑马王子17 小时前
1.non-MonoBehaviour 单例模式泛型基类
unity·前端框架·c#
Jmyd012318 小时前
VR实训室与AR实训方案差异对比及选型适配指南
ar·vr·虚拟现实·虚拟仿真·虚拟实训·虚拟仿真实训课件
KhalilRuan1 天前
Unity性能优化
unity·性能优化·游戏引擎
ellis19701 天前
u3d IMGUI[二] 编辑器扩展
unity
五仁烧饼2 天前
Unity性能优化系列内存篇 - 移动端内存优化
unity·性能优化·游戏引擎
WiChP3 天前
【V0.1B15】从零开始的2D游戏引擎开发之路
游戏引擎