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

相关推荐
平行云PVT8 小时前
数字孪生信创云渲染技术解析:从混合信创到全国产化架构
linux·unity·云原生·ue5·图形渲染·webgl·gpu算力
星幻元宇VR14 小时前
VR环保学习机|科技助力绿色教育新模式
大数据·科技·学习·安全·vr·虚拟现实
小小数媒成员14 小时前
Unity的包含文件
unity·游戏引擎
mxwin16 小时前
Unity Shader 实战屏幕颜色抓取实现径向模糊 (URP)
unity·游戏引擎·shader·uv
林枫依依20 小时前
Unity2017 项目源码打开即崩溃,无法打开的解决办法
unity
wearegogog12320 小时前
ESP32迷你无人机开发代码详解
游戏引擎·无人机·cocos2d
心前阳光1 天前
Unity使用豆包语音模型
unity·游戏引擎
张老师带你学1 天前
unity资源:星际飞船 陨石 虫族 星球
科技·游戏·unity·模型·游戏美术
心前阳光1 天前
Unity使用豆包语言模型
unity·语言模型
魔士于安1 天前
unity宇宙飞船
游戏·unity·游戏引擎·贴图·模型