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

相关推荐
纪纯17 小时前
PicoVR Unity Integration SDK 3.4 常用交互API
unity·游戏引擎·vr·pico
龙智DevSecOps解决方案18 小时前
3A 游戏优化技术栈:如何打通引擎级分析工具与 DevOps 持续集成管线?
unity·性能优化·游戏开发·技术美术·perforce·unrealengine
葛兰岱尔19 小时前
从 SolidWorks 到 Three.js,从 Inventor 到 Unity——制造业CAD模型“几何-语义一体化“转换,不再是天方夜谭!
开发语言·javascript·unity
世界很奇妙塔20 小时前
AR/VR产业去泡沫后:从消费端娱乐,走向产业端全域赋能
ar·vr·娱乐
鼎艺创新科技21 小时前
三维电子沙盘中OSGB倾斜摄影数据的加载与渲染
游戏引擎·cocos2d
玉夏1 天前
【Shader基础】UV 与纹理采样 Part1
unity·着色器·uv
kyle~1 天前
Godot开源游戏引擎
开源·游戏引擎·godot
zdr尽职尽责1 天前
Unity录像功能
学习·ui·unity·游戏引擎
真鬼1231 天前
【Unity Cursor】AI规矩
unity·游戏引擎
mxwin1 天前
Unity Shader 深入理解 LinearEyeDepth 与 DepthTexture
unity·游戏引擎