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

相关推荐
凯禾瑞华养老实训室10 小时前
产教融合新抓手:智慧健康养老服务与管理实训室报价及人才培育路径
大数据·人工智能·物联网·ar·vr·智慧健康养老服务与管理
技术小甜甜11 小时前
[Godot] 解决导出APK安装失败的常见问题:深入分析与调试方法
游戏引擎·godot·游戏开发
Axis tech12 小时前
MIT沉浸式实验室如何使用MANUS手套实现远程VR神经外科培训
科技·vr
老朱佩琪!16 小时前
Unity桥接模式
unity·设计模式·c#·桥接模式
技术小甜甜16 小时前
[Godot][入门] 安装与版本选择:3.x 还是 4.x?(按项目类型一键决策)
游戏引擎·godot·游戏开发·2d
陈言必行16 小时前
Unity 之 物理引擎中三种刚体力施加方式详解
unity·游戏引擎
foreveryao12316 小时前
Unity渲染流程(底层逻辑)
unity·游戏引擎·图形渲染
zhz521416 小时前
代码之恋(第十四篇:分叉的路径与意外的Push)
ai·重构·机器人·vr·伴侣机器人
small-pudding17 小时前
Unity中的PBR(基于物理的渲染)
unity·游戏引擎
CreasyChan17 小时前
3D游戏数学基础指南
游戏·3d·unity·数学基础