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

相关推荐
ykjhr_3d26 分钟前
东莞车间教学vr虚拟仿真实训制作公司
3d·vr·华锐视点·虚拟仿真实训·虚拟车间
No8g攻城狮26 分钟前
【VR应用】部署企业级 VR 应用,主流方案有哪些及每个方案的优点和缺点
图像处理·计算机视觉·vr
垂葛酒肝汤11 小时前
Unity的UI扫光效果Shader
ui·unity·游戏引擎
mxwin14 小时前
Unity Shader Alpha测试 · 模板测试 · 深度测试
unity·游戏引擎
2601_9560028117 小时前
冬日狂想曲(赠去马赛克补丁)2026.5.13最新版免费下载 转存后自动更新 (看到请立即转存 资源随时失效)pc手机版通用
智能手机·游戏引擎·电脑·游戏程序·动画·游戏美术
Sator118 小时前
unity解决粒子与物体接触时的硬边缘问题
unity·游戏引擎
RPGMZ20 小时前
RPGMZ NPC头顶自动显示一段消息
前端·游戏引擎·rpgmz·rpgmakermz
ykjhr_3d21 小时前
新能源汽车虚拟仿真vr教学解决方案
汽车·vr·虚拟现实·新能源汽车·vr虚拟仿真
程序员JerrySUN1 天前
Jetson边缘嵌入式实战课程第三讲:L4T 与 Jetson 系统架构
linux·服务器·人工智能·安全·unity·系统架构·游戏引擎
萌萌的提莫队长1 天前
Unity HDRP 渲染管线 Camera 输出到RenderTexture没有Alpha通道
unity·游戏引擎