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

相关推荐
在路上看风景12 小时前
15. 纹理尺寸是4的倍数
unity
星依网络14 小时前
使用LabelImg工具标注数据(游戏辅助脚本开发)
python·游戏引擎·图形渲染·骨骼绑定
AT~15 小时前
unity 使用Socket和protobuf实现网络连接
unity·游戏引擎
gxdtgsy18 小时前
2025 VR全景内容制作软件横向深度对比:主流工具的核心架构/市场/技术分析
架构·vr
数据和云19 小时前
Oracle没有退路
数据库·oracle·vr
feiduoge20 小时前
教程 36 - 方向光照
windows·游戏引擎·图形渲染
怣疯knight21 小时前
Cocos creator判断节点是否能用的方法
unity·cocos2d
tealcwu21 小时前
Google Play的Keystore不可用时的解决方法
unity
呼呼突突1 天前
Unity使用TouchSocket的RPC
unity·rpc·游戏引擎
Robert--cao1 天前
人机交互(如 VR 手柄追踪、光标移动、手势识别)的滤波算法
人工智能·算法·人机交互·vr·滤波器