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

相关推荐
海鸥-w3 小时前
Unity中使用Cinemachine插件创建自由视角相机(freelookCamera)来实现第三人称漫游
数码相机·unity·游戏引擎
EQ-雪梨蛋花汤6 小时前
【Unity笔记】Unity音效管理:ScriptableObject配置 + 音量控制 + 编辑器预览播放自动化实现
笔记·unity·编辑器
zhongqu_3dnest8 小时前
数字空间与VR有什么关系?什么是数字空间?
vr·智慧园区·智慧文旅·vr体验·数字房产·数字空间·数字医疗
qq_4313313511 小时前
Unity ML-Agents + VScode 环境搭建 Windows
windows·vscode·unity·强化学习
林枫依依12 小时前
Unity 创建、读取、改写Excel表格数据
unity·excel
EQ-雪梨蛋花汤12 小时前
【Unity笔记】Unity 编辑器扩展:一键查找场景中组件引用关系(含完整源码)(组件引用查找工具实现笔记)
笔记·unity·编辑器
李詹13 小时前
游戏开发核心技术解析——从引擎架构到攻防体系的完整技能树
架构·ue5·游戏引擎·游戏程序·3dsmax·虚幻
枫景Maple14 小时前
Unity常用内置变换矩阵
unity·游戏引擎
太妃糖耶15 小时前
URP-UGUI交互功能实现
unity·游戏引擎·shader
小浪学编程15 小时前
C#学习1_认识项目/程序结构
开发语言·前端·学习·c#·游戏引擎