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

相关推荐
蛙色3DVR2 小时前
大空间多人互动技术、大空间LBE、VR大空间什么意思?如何实现?
vr
MediaTea2 小时前
Ae 效果详解:VR 颜色渐变
前端·vr
PassionY3 小时前
Unity DOTS从入门到精通之 C# Job System
unity·ecs·dots·jobsystem·burst·baker·entities
red_redemption7 小时前
Unity--Cubism Live2D模型使用
unity·live2d·cubism sdk
咩咩觉主11 小时前
C# &Unity 唐老狮 No.6 模拟面试题
开发语言·unity·面试·c#·游戏引擎·唐老师
虾球xz13 小时前
游戏引擎学习第147天
数据库·学习·游戏引擎
HELLOMILI15 小时前
第四章:反射-Reflecting Your World《Unity Shaders and Effets Cookbook》
游戏·unity·游戏引擎·游戏程序·图形渲染·材质·着色器
虾球xz16 小时前
游戏引擎学习第146天
学习·ffmpeg·游戏引擎
小沙盒16 小时前
godot在_process()函数实现非阻塞延时触发逻辑
javascript·游戏引擎·godot
MediaTea17 小时前
Ae 效果详解:VR 平面到球面
平面·vr