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

相关推荐
xcLeigh11 小时前
Unity基础:MonoBehaviour的生命周期——Awake、OnEnable、Start、Update执行顺序
unity·游戏引擎
qq_2131578912 小时前
其域lcc2丢失部分lod/远处显示空洞的解决方式
unity·lcc2
辻弋20112 小时前
自动检测硬件生成驱动清单、实时监控FPS、120秒性能记录——30+项优化模块化开关,所有改动可精确复原
服务器·windows·游戏引擎·电脑·开源软件
点心的游戏开发世界14 小时前
GDScript 入门笔记:目录
开发语言·笔记·游戏引擎·godot
XR技术研习社14 小时前
关于 PICO 串流测试中报错 IndexOutOfRangeException: renderPassIndex 的两个排障方法
unity·ar·xr·vr
想做后端的前端15 小时前
Unity · 性能优化:内存管理完全指南:从托管堆到跨桥开销
unity·性能优化·游戏引擎
平行云18 小时前
实时云渲染信创架构解析:从GPU池化到全栈适配的技术演进
linux·unity·docker·ue5·webgl·数字孪生·实时云渲染
玖玥拾20 小时前
Lua 基础语法(五)Unity xLua基础配置与 C# 访问 Lua
开发语言·unity·c#·lua
玖玥拾2 天前
Lua 基础语法(二)
开发语言·unity·lua
点心的游戏开发世界2 天前
GDScript 入门笔记(十六):文件读写与数据持久化
开发语言·笔记·游戏引擎·godot