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

相关推荐
一线灵1 小时前
跨平台游戏引擎 Axmol-2.10.0 发布
游戏引擎
沉默金鱼9 小时前
Unity实用技能-格式化format文字
ui·unity·游戏引擎
jyy_999 小时前
通过网页地址打开unity的exe程序,并传参
unity
qq_205279051 天前
Unity TileMap 使用经验
unity·游戏引擎
心灵宝贝1 天前
Mac Unity 2018.dmg游戏工具 安装步骤 简单易懂教程(附安装包)
macos·unity·游戏引擎
TO_ZRG1 天前
Unity SDK 通过 Registry 分发及第三方依赖处理指南
unity·游戏引擎
7***n751 天前
C++在游戏中的Cocos2d-x
游戏·游戏引擎·cocos2d
龙智DevSecOps解决方案2 天前
Perforce《2025游戏技术现状报告》Part 1:游戏引擎技术的广泛影响以及生成式AI的成熟之路
人工智能·unity·游戏引擎·游戏开发·perforce
u***u6852 天前
Vue虚拟现实案例
前端·vue.js·vr
xhyyvr2 天前
VR预防艾滋体验系统:一场潜入身体的VR旅程,照亮艾滋防控
vr·vr公共安全·vr社区安全学习机·vr社区安全·vr与预防艾滋病