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

相关推荐
孟无岐16 小时前
【Laya】Laya 类使用说明
typescript·游戏引擎·游戏程序·laya
xhyyvr17 小时前
“电”击预警!VR跨步电压安全体验系统
vr·vr公共安全·vr公共安全体验馆
在路上看风景17 小时前
1.2 Unity资源分类
unity·游戏引擎
one named slash18 小时前
BMFont在Unity中生成艺术字
unity·游戏引擎
Axis tech19 小时前
TechViz VR解决方案:增强沉浸式设计评审与演示的技术革新
vr
郝学胜-神的一滴19 小时前
图形学中的纹理映射问题:摩尔纹与毛刺的深度解析
c++·程序人生·unity·游戏引擎·图形渲染·unreal engine
在路上看风景20 小时前
10. CPU-GPU协作渲染
unity
程序员agions20 小时前
Unity 游戏开发邪修秘籍:从入门到被策划追杀的艺术
unity·cocoa·lucene
JIes__20 小时前
Unity(一)——场景切换、退出游戏、鼠标隐藏锁定...
unity·游戏引擎
NIKITAshao1 天前
Unity URP Volume组件详解(笔记)
unity·游戏引擎