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

相关推荐
ttod_qzstudio18 小时前
系统架构设计师论文逐句拆解(三):ATAM 架构评估,怎样把“方案比较”写成质量属性权衡
unity·架构·系统架构·软考
道可云1 天前
一次拍摄,让展厅永不闭馆:VR空间如何把真实场景搬到线上?
vr
小贺儿开发2 天前
Unity 轻量级外部素材加载器(热更新)
科技·学习·unity·程序员·工具·热更新·ugui
维爱智VR认知学能3 天前
VR课程软件版本迭代清单比对:资源哈希与依赖变更提取
json·哈希算法·vr
淡海水4 天前
01-03-认知篇-基础-Excel配置工作流痛点深度分析
unity·架构·excel·游戏开发·luban
谙弆悕博士4 天前
生物启发式集群(Swarm)工程实现:五条规则、一群蚂蚁和四十个粒子
人工智能·gpt·游戏引擎·cocos2d·蚁群算法·多智能体·boids
Frankie_stand5 天前
无人机售后故障处理全流程:从受理、SLA 时限到责任划分与改进闭环
游戏引擎·无人机·cocos2d
码云社区12 天前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案
java·vue.js·vr·租房小程序·在线租房·看房租房
zdr尽职尽责13 天前
UnityCli 兼容2022版本
ui·unity·ai·c#·游戏引擎
ellis197015 天前
Claude Code[二] 上下文相关的机制
unity·ai编程