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

相关推荐
2501_941145851 小时前
虚拟现实与增强现实技术在教育培训与沉浸式学习场景中的创新应用研究
学习·ar·vr
jtymyxmz3 小时前
《Unity Shader》7.2.3 实践 在切线空间下计算
unity·游戏引擎
在路上看风景7 小时前
1.5 Material
unity
2501_9411421313 小时前
虚拟现实与人工智能结合在远程教育互动平台中提升沉浸体验与个性化教学的应用
人工智能·vr
2501_9411437316 小时前
虚拟现实与增强现实在在线教育中的沉浸式教学与个性化学习应用研究
学习·ar·vr
WarPigs1 天前
Unity红点系统笔记
unity·游戏引擎
郭逍遥1 天前
[Godot] C#基于噪声的简单TileMap地图生成
游戏引擎·godot
作孽就得先起床1 天前
unity UnauthorizedAccessException: 拒绝访问路径
unity·游戏引擎
tealcwu1 天前
【Unity踩坑】Unity项目提示文件合并有冲突
elasticsearch·unity·游戏引擎
tealcwu2 天前
【Unity小技巧】如何将3D场景转换成2D场景
3d·unity·游戏引擎