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

相关推荐
真鬼1232 小时前
Cesium、Cmake、Dotnet快捷下载
unity·游戏引擎
真鬼1232 小时前
【Unity安卓】Unity 嵌入 Android Studio 完整流程
android·unity·android studio
为你写首诗ge1 天前
【Unity知识分享】Mirror实现房间等待功能(创建房间 / 搜索房间、加入房间、房间准备、房间内角色设置、返回房间)
unity·mirror·房间等待功能
游乐码1 天前
Unity坦克案例疑难记录(二)
unity·游戏引擎
小白学鸿蒙1 天前
Funplay Unity MCP 接入 trae 实战
unity·游戏引擎·mcp
相信神话20211 天前
3.5《酒魂》体验与失败设计
游戏引擎·godot·godot4
星幻元宇VR1 天前
VR科普大空间|法治、禁毒、消防一体化沉浸式教育新模式
科技·学习·安全·vr·虚拟现实
游乐码1 天前
Unity基础(一)游戏中的数学Mathf函数
游戏·unity·游戏引擎
星幻元宇VR1 天前
VR地震平台|打造沉浸式防灾减灾科普新模式
科技·学习·安全·vr·虚拟现实
地狱为王2 天前
Unity实现猫脸关键点检测
unity·游戏引擎·猫脸关键点检测