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

相关推荐
WarPigs1 天前
Unity无法修改Assembly-CSharp.csproj错误
unity
FairGuard手游加固2 天前
手游加固怎么做?SO、IL2CPP、AssetBundle 与运行时保护详解
安全·游戏·unity
阿松爱学习3 天前
【Unity开发】监听Scene场景事件
unity·c#
xiaogai_gai3 天前
BOM 物料清单同步实战:金蝶云星空 → 四化智造 MES 修改场景深度拆解
unity·游戏引擎
淡海水3 天前
03-03-架构篇-SGen GC架构解析
unity·架构·c#·gc·sgen
chaoyuanl3 天前
从平面到包裹:超元力飞行影院如何构建“人在景中、身随景动”的感知闭环
人工智能·科技·平面·xr·vr·娱乐
/**书香门第*/3 天前
Cocos Creator 打螺丝游戏的实现
游戏引擎·cocos2d·螺丝·打螺丝
chaoyuanl3 天前
超元力VR大空间CS项目落地解决方案:五大选购要点,开店全程扶持
大数据·人工智能·vr
萌萌的提莫队长4 天前
Unity相机捕捉,图像识别,抠像+合成
opencv·unity
Jmyd01234 天前
VR全景线上展会制作流程技术解析:全景采集、点云重建与Web端渲染优化实战
前端·javascript·vr·三维数字化