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

相关推荐
Artistation Game1 天前
九、怪物行为逻辑
游戏·unity·游戏引擎
百里香酚兰1 天前
【AI学习笔记】基于Unity+DeepSeek开发的一些BUG记录&解决方案
人工智能·学习·unity·大模型·deepseek
妙为1 天前
unreal engine5制作动作类游戏时,我们使用刀剑等武器攻击怪物或敌方单位时,发现攻击特效、伤害等没有触发
游戏·游戏引擎·虚幻·碰撞预设
dangoxiba1 天前
[Unity Demo]从零开始制作空洞骑士Hollow Knight第十三集:制作小骑士的接触地刺复活机制以及完善地图的可交互对象
游戏·unity·visualstudio·c#·游戏引擎
小殷要努力刷题!1 天前
国创——VR虚拟陪伴
vr
摩尔线程1 天前
使用MTVerseXR SDK实现VR串流
3d·xr·图形渲染·vr·摩尔线程
先生沉默先2 天前
使用Materialize制作unity的贴图,Materialize的简单教程,Materialize学习日志
学习·unity·贴图
十画_8242 天前
Visual Studio 小技巧记录
unity·visual studio
red_redemption2 天前
cpp,git,unity学习
git·unity·游戏引擎
tealcwu2 天前
【Unity踩坑】Unity更新Google Play结算库
unity·游戏引擎