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

相关推荐
死也不注释4 小时前
【鸡零狗碎记录】
unity·c#
huoyingcg5 小时前
武汉火影数字|数字党建展厅制作 VR红色数字纪念馆 党史馆数字化打造
科技·ar·vr·虚拟现实·增强现实
★YUI★7 小时前
学习游戏制作记录(剑投掷技能)7.26
学习·游戏·unity·c#
★YUI★1 天前
学习游戏制作记录(克隆技能)7.25
学习·游戏·unity·c#
不绝1911 天前
ARPG开发流程第一章——方法合集
算法·游戏·unity·游戏引擎
玩代码1 天前
Unity里的加力
开发语言·unity
贵州晓智信息科技1 天前
Unity 性能优化全攻略
unity·性能优化·游戏引擎
UWA1 天前
UWA DAY 2025 游戏开发者大会|全议程
游戏·unity·性能优化·游戏开发·uwa·unreal engine
unicrom_深圳市由你创科技1 天前
Unity 的UI动画调节
ui·unity·游戏引擎
咩咩觉主2 天前
Unity编辑器拓展 IMGUI与部分Utility知识总结(代码+思维导图)
unity·c#·编辑器·游戏引擎