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

相关推荐
淡海水1 天前
【节点】[EvaluateTipThickness节点]原理解析与实际应用
unity·游戏引擎·shadergraph·图形·evaluate·thickness
小贺儿开发1 天前
Unity3D 木胎雕刻
科技·unity·人机交互·互动·雕刻
HY小海2 天前
【Unity游戏创作】常见的设计模式
unity·设计模式·c#·游戏程序
淡海水3 天前
【节点】[EvaluateSimulationAdditionalData节点]原理解析与实际应用
unity·游戏引擎·shadergraph·图形·simulation·evaluate
kUhzIPVBnE3 天前
基于VSG并网仿真的转动惯量和阻尼自适应控制探索
vr
小贺儿开发3 天前
Unity3D 文物互动大屏
3d·unity·实时互动·udp·socket·网络通信
mtouch3334 天前
三维沙盘系统配置管理数字沙盘模块
人工智能·ai·ar·vr·虚拟现实·电子沙盘·数字沙盘
秦奈4 天前
Unity学习复习随笔(12):网络开发基础
网络·笔记·学习·unity
淡海水4 天前
【节点】[EvaluateRefractionData节点]原理解析与实际应用
unity·游戏引擎·shadergraph·data·图形·evaluate·refraction
淡海水4 天前
【节点】[EvaluateScatteringColor节点]原理解析与实际应用
unity·游戏引擎·shadergraph·color·图形·evaluate·scattering