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

相关推荐
wgslucky9 小时前
Godot GDScript初学者遇到的问题记录
游戏引擎·godot
点心的游戏开发世界12 小时前
GDScript 入门笔记(五):函数
笔记·游戏引擎·godot
谢斯14 小时前
[unity]如何在unity中添加newtonsoft-json
unity·json·游戏引擎
天人合一peng15 小时前
Unity标记固定颜色及投影标记
unity
云雨巫山19 小时前
Unity 游戏开发性能优化全景手册
unity·智能手机·性能优化·游戏引擎
maybeyaluokenai19 小时前
unity build in渲染管线概述
unity·图形渲染
学习星球19 小时前
AI 原生游戏开发:Godot 4 + AI Agent 全栈指南(Ziva 3 / Godot MCP 深度实战)
人工智能·游戏引擎·godot
云雨巫山19 小时前
Unity 性能优化 · 图解全景手册
unity·性能优化·游戏引擎
工业HMI实战笔记1 天前
未来已来:AR、VR与AI在下一代HMI中的展望
人工智能·ar·vr
Madokaly1 天前
DOTween的Vector3Plugin
unity