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

相关推荐
极客柒3 分钟前
Unity 塔防自用可视化路点寻路编辑器
unity·编辑器·游戏引擎
程序猿多布32 分钟前
Unity AssetBundle详解
unity·assetbundle
萘柰奈5 小时前
Unity学习----【进阶】Addressables(二)--加载资源与打包及更新
学习·unity
lvcoc10 小时前
unity 接入火山引擎API,包括即梦AI
windows·unity·ai·火山引擎
一线灵11 小时前
跨平台游戏引擎 Axmol-2.8.1 发布
junit·游戏引擎
ykjhr_3d14 小时前
用户眼中的VR自来水厂之旅
vr·vr自来水厂
酷雷曼VR全景14 小时前
为什么要用VR全景?5个答案告诉你
人工智能·科技·vr·vr全景·酷雷曼
王家视频教程图书馆17 小时前
2025年最新 unityHub游戏引擎开发2d手机游戏和桌面游戏教程
游戏·unity·游戏引擎
SmalBox17 小时前
【URP】法线贴图为什么主要是蓝色的?
unity·渲染
二川bro2 天前
第25节:VR基础与WebXR API入门
前端·3d·vr·threejs