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

相关推荐
心灵宝贝42 分钟前
Mac Unity 2018.dmg游戏工具 安装步骤 简单易懂教程(附安装包)
macos·unity·游戏引擎
TO_ZRG2 小时前
Unity SDK 通过 Registry 分发及第三方依赖处理指南
unity·游戏引擎
7***n757 小时前
C++在游戏中的Cocos2d-x
游戏·游戏引擎·cocos2d
龙智DevSecOps解决方案12 小时前
Perforce《2025游戏技术现状报告》Part 1:游戏引擎技术的广泛影响以及生成式AI的成熟之路
人工智能·unity·游戏引擎·游戏开发·perforce
u***u68516 小时前
Vue虚拟现实案例
前端·vue.js·vr
xhyyvr16 小时前
VR预防艾滋体验系统:一场潜入身体的VR旅程,照亮艾滋防控
vr·vr公共安全·vr社区安全学习机·vr社区安全·vr与预防艾滋病
xhyyvr16 小时前
沉浸式骑行 + 实景警示:VR 摩托车骑行体验,把道路风险搬进虚拟课堂
vr·vr交通安全·vr摩托车骑行体验·vr摩托车·vr交通安全体验设备
Q***l68716 小时前
元宇宙虚拟现实
vr
Y***K43420 小时前
C在游戏中的Godot
游戏·游戏引擎·godot
WarPigs1 天前
Unity编辑器开发笔记
unity·编辑器·excel