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

相关推荐
nnsix12 小时前
Unity的dllType Native和Managed的区别
unity·游戏引擎
编码旅者13 小时前
《Virt A Mate(VAM)》免安装豪华版v1.22中文汉化整合
游戏引擎·图形渲染·vr·动画
Clank的游戏栈14 小时前
AI游戏开发全自动编程课程体系(Cursor版,支持Unity/Cocos, Laya后续支持)
人工智能·unity·游戏引擎
鹿野素材屋15 小时前
技术闲聊:为什么网游会在固定时间点,刷出固定的道具?
前端·网络·unity
发际线危机1213816 小时前
Unity发布apk部分真机虚线采样变成实线问题
unity·游戏引擎
FVV112316 小时前
电脑录屏工具Bandicam 无时长限制,支持4K画质
eclipse·游戏引擎·ar·动画·ogre
Axis tech17 小时前
使用ART光学动作捕捉系统,创建大型可重构FLEX沉浸式可视化解决方案
vr
猫不吃咸鱼19 小时前
Unity中攻击检测敌人的多种方法
游戏·unity·c#·游戏引擎
又来07719 小时前
Unity 无人机物理模拟开发日志:从零打造穿越机手感
unity·游戏引擎·无人机
CreasyChan21 小时前
Unity UniRx Observable 类详解及使用
游戏·unity·c#·游戏引擎