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

相关推荐
一线灵12 小时前
跨平台游戏引擎 Axmol-2.11.6 发布
游戏引擎
两水先木示14 小时前
【Unity】Lens Flare光晕简单使用案例
unity·游戏引擎
专注仿真15 小时前
Unity 小游戏实战:2D 横版闯关 / 3D 跑酷 / 塔防 / 解谜四类项目工程化拆解与复用实践
游戏·游戏引擎·游戏程序
郝学胜-神的一滴1 天前
游戏设计、原型与开发 26:四种循环
开发语言·数据结构·游戏·游戏引擎·游戏策划
两水先木示1 天前
【Unity】刮刮乐案例-RenderTexture实现思路
unity·游戏引擎
学术小李1 天前
用虚幻引擎(UE)打开Obj模型
游戏引擎·虚幻
张不无-Unity2 天前
Unity的四种灯光Directional、Point、Spot 和 Area
unity·游戏引擎
淡海水3 天前
02-02-原理篇-Scriban模板引擎原理深度解析
unity·excel·游戏开发·luban
ttod_qzstudio4 天前
系统架构设计师论文逐句拆解(三):ATAM 架构评估,怎样把“方案比较”写成质量属性权衡
unity·架构·系统架构·软考
道可云5 天前
一次拍摄,让展厅永不闭馆:VR空间如何把真实场景搬到线上?
vr