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

相关推荐
飞浪纪元[FWC–FE]9 小时前
【无标题】
unity·游戏引擎
红黑色的圣西罗11 小时前
对象池简述
unity·c#
水龙吟啸12 小时前
基于Orbbec-Gemini深度相机与SFM-2D to 3D重建算法、手部识别视觉算法、Unity运动控制的3D水果切割游戏
python·深度学习·神经网络·c#·游戏引擎·3d视觉·3d重建
淡海水19 小时前
【节点】[Texture2DAsset节点]原理解析与实际应用
unity·游戏引擎·shadergraph·图形·texture2dasset
向宇it19 小时前
【unity游戏开发——网络】unity+PurrNet联机实战,实现一个多人对战类《CS/CSGO》《CF/穿越火线》《PUBG/吃鸡》的FPS射击游戏
游戏·unity·游戏引擎·交互·联机
旧梦吟19 小时前
脚本网页 双子星棋
算法·flask·游戏引擎·css3·html5
gshh__1 天前
SuperMap Hi-Fi 3D SDK for Unreal 如何修改模型选中高亮颜色
ue5·游戏引擎·supermap
沉默金鱼2 天前
Unity实用技能-GM命令
unity·游戏引擎
chillxiaohan2 天前
unity粗糙、高光、光泽度调节shader记录
unity·游戏引擎
xhyyvr2 天前
VR模拟触电体验系统:沉浸式感知危险,筑牢触电安全防线
vr·vr公共安全·vr公共安全体验馆·vr公共安全展厅·vr预防触电