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

相关推荐
B0URNE6 小时前
【Unity基础详解】Unity3D全程学习路线
学习·unity·游戏引擎
一步一个foot-print10 小时前
[Unity Shader Base] RayMarching in Cloud Rendering
unity·游戏引擎
ithinking11010 小时前
kotlin 集成 unity
unity·android studio
心无旁骛~15 小时前
MotionTrans: 从人类VR数据学习机器人操作的运动级迁移
学习·机器人·vr
xhyyvr15 小时前
VR水污染体验系统——VR 里的碧水守护
vr·vr环保·vr环保学习机·vr环境保护
立刀人15 小时前
关于Unity 轴心点 Pivot、锚点 Anchor和控制轴
unity·游戏引擎
SpiderCodeJ15 小时前
【UE5】- VR小技巧 :用PC处理代替频繁使用VR头显开发
ue5·vr·虚拟现实
佩京科技VR20 小时前
VR党建赛车模拟系统:让党史学习“开“出沉浸式新体验
vr·vr党建学习机·vr党建赛车
Hody911 天前
【XR开发系列】Unity第一印象:编辑器界面功能布局介绍(六大功能区域介绍)
unity·编辑器·xr
lrh30252 天前
Custom SRP - 14 Multiple Cameras
unity·渲染管线·srp