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

相关推荐
世洋Blog23 分钟前
装饰器模式实践:告别臃肿的继承链,优雅解耦初始化状态管理
unity·设计模式·c#·装饰器模式
feiduoge1 小时前
教程 41 - 增强纹理映射(采样器)
windows·游戏引擎·图形渲染
feiduoge3 小时前
教程 37 - 法线贴图
windows·游戏引擎·图形渲染
feiduoge3 小时前
教程 42 - 可写纹理
windows·游戏引擎·图形渲染
qq_428639614 小时前
虚幻基础:mod制作流程
游戏引擎·虚幻
xhyyvr9 小时前
VR青少年法治教育综合信息平台:青少年法治探险小课堂
vr·vr法治教育·vr法治体验馆·vr法治展厅·vr预防诈骗
老朱佩琪!10 小时前
Unity原型模式
开发语言·经验分享·unity·设计模式·原型模式
老朱佩琪!11 小时前
Unity组合模式
unity·游戏引擎·组合模式
老朱佩琪!11 小时前
Unity装饰器设计模式
unity·设计模式
九影网络11 小时前
虚实游戏怎么选?详解AR与VR游戏的核心区别
游戏·ar·vr