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

相关推荐
垂葛酒肝汤1 小时前
放置挂机游戏的离线和在线收益unity实现
游戏·unity·c#
孟无岐2 小时前
【Laya】Base64Tool 编码工具类使用说明
typescript·游戏引擎·游戏程序·laya
康de哥2 小时前
在OpenCode中配置unity3d-mcp
unity·glm-4.7·minimax m2.1·opencode·unity3d-mcp
Howrun7773 小时前
虚幻引擎_动画蓝图/混合空间/状态机_超详细教学
游戏引擎·虚幻
在路上看风景3 小时前
1.5 AssetDataBase
unity
星幻元宇VR4 小时前
VR消防行走平台|沉浸+互动双重提升应急教育
安全·vr·虚拟现实
星幻元宇VR4 小时前
突破传统消防训练,VR消防体验屋让培训更高效
安全·vr·虚拟现实
qianbo_insist4 小时前
unity 无头模式启动
unity·游戏引擎
郝学胜-神的一滴5 小时前
深入解析Mipmap层级判定原理:从理论到实践
c++·unity·godot·游戏程序·图形渲染·unreal engine
weixin_409383125 小时前
cocos shader闪光
游戏引擎·cocos2d