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 小时前
OpenHarmony混合开发实战指南
c语言·python·flutter·vr·visual studio
淡海水13 小时前
【节点】[Blackbody节点]原理解析与实际应用
unity·游戏引擎·shadergraph·图形·blackbody
avi911115 小时前
Unity-海水效果+ShaderGraph-非专业不谈虚的效果-分享实用Editor源码
unity·游戏引擎
猫不在19 小时前
MVC和MVVM
unity
吃好喝好玩好睡好20 小时前
OpenHarmony+Electron+Flutter:构建轻量化VR/AR跨端交互应用指南
flutter·electron·vr
老朱佩琪!20 小时前
在Unity中实现状态机设计模式
开发语言·unity·设计模式
憨辰20 小时前
Unity I2多语言拆分方案【内存、包体⬇️】
unity·游戏引擎
jtymyxmz1 天前
《Unity Shader》12.5 Bloom 效果
unity·游戏引擎
大江东去浪淘尽千古风流人物1 天前
【DSP】向量化操作的误差来源分析及其经典解决方案
linux·运维·人工智能·算法·vr·dsp开发·mr
jtymyxmz1 天前
《Unity Shader》12.6 运动模糊
unity·游戏引擎