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

相关推荐
B0URNE5 小时前
【Unity基础详解】(11)Unity核心:输入系统
unity·游戏引擎
世洋Blog7 小时前
Unity开发微信小游戏-减少WASM包体大小
unity·游戏引擎·wasm·微信小游戏
TO_ZRG8 小时前
Unity 通过 NativePlugin 接入Android SDK 指南
android·unity·游戏引擎
jtymyxmz10 小时前
《Unity Shader》10.2.1 镜子效果
unity·游戏引擎
ellis197010 小时前
Unity打开新项目Package相关报错处理记录
unity
微:xsooop12 小时前
iOS 上架4.3a 审核4.3a 被拒4.3a 【灾难来袭】
flutter·unity·ios·uniapp
微光守望者12 小时前
Unity ScriptableObject详解:优化游戏架构的强大工具
unity·游戏引擎
jtymyxmz13 小时前
《Unity Shader》10.2.2 玻璃效果
unity·游戏引擎
zxc24460393416 小时前
gpu instancer crowd 动画使用方式
unity
C MIKE17 小时前
unity资源下载
unity