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

相关推荐
1uther6 分钟前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎
死也不注释3 小时前
【Unity UGUI 交互组件——Slider(7)】
unity·游戏引擎·交互
程序猿多布8 小时前
XLua教程之热补丁技术
unity·c#·lua·xlua
SmalBox11 小时前
【光照】Unity中的[光照模型]概念辨析
unity·渲染
挂科是不可能出现的11 小时前
unity导入blender动画
unity·游戏引擎·blender
派葛穆12 小时前
Unity-按钮实现场景跳转
java·unity·游戏引擎
程序猿多布14 小时前
XLua教程之Lua调用C#
unity·c#·lua·xlua
lrh30251 天前
Custom SRP - Point and Spot Lights
unity·srp·render pipeline
绀目澄清1 天前
unity UGUI 鼠标画线
unity·计算机外设·游戏引擎
Magnum Lehar1 天前
3d wpf游戏引擎的导入文件功能c++的.h实现
3d·游戏引擎·wpf