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

相关推荐
云卓SKYDROID1 小时前
无人机中继器模式技术对比
人工智能·游戏引擎·php·无人机·cocos2d·高科技·云卓科技
凯禾瑞华养老实训室2 小时前
智慧养老实训室建设指南:厂家的产品选型与应用建议
大数据·人工智能·ar·vr·虚拟仿真·智慧健康养老服务与管理
future_studio18 小时前
聊聊 Unity(小白专享、熟悉基础编程 ... ...)
unity·游戏引擎
搞科研的小刘选手19 小时前
【通信&网络安全主题】第六届计算机通信与网络安全国际学术会议(CCNS 2025)
大数据·人工智能·网络安全·vr·通信工程·网络技术·计算机工程
A-上海蛙色元宇宙3DVR陈总1 天前
红色 VR 大空间:技术赋能红色文化传承的运营价值与实践路径
vr
ellis19701 天前
toLua[六] Examples 05_LuaCoroutine分析
unity
程序员正茂2 天前
Unity3d中Tab控件的实现
ui·unity·tab·控件
朗迪锋2 天前
利用人工智能、数字孪生、AR/VR 进行军用飞机维护
人工智能·ar·vr
三掌柜6662 天前
突破AR视觉交互边界:Unity赋能Rokid AR眼镜实现高精度图像识别与实时跟踪
unity·ar·交互
Brianna Home3 天前
Godot4.3开发2D游戏全记录
游戏·游戏引擎·godot·游戏程序·动画