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

相关推荐
落羽的落羽几秒前
【Linux系统】进程终止、进程等待与进程替换的概念与实现
linux·服务器·c++·人工智能·深度学习·机器学习·游戏引擎
世洋Blog12 小时前
Unity中图片的内存中占用大小、AB占用大小、内存形式
unity·游戏引擎
熬夜敲代码的小N13 小时前
Unity热更新技术详解
unity·游戏引擎
地狱为王21 小时前
Cesium for Unity 去除Cesium Logo
unity·游戏引擎·cesium
BuHuaX21 小时前
Lua入门
开发语言·unity·junit·c#·游戏引擎·lua
wonder135791 天前
RectTransform位置计算方法和UI自适应
ui·unity·ugui
世洋Blog1 天前
Unity发布自己的插件包
unity·游戏引擎
吃好喝好玩好睡好1 天前
OpenHarmony下Electron+Flutter应用自动化测试框架构建全流程指南
大数据·flutter·electron·vr·数据库架构
ytttr8731 天前
基于C#的CAN总线数据解析BMS上位机
android·unity·c#
雪下的新火2 天前
ASE07-魔法药剂炼制效果
经验分享·unity·shader·ase·游戏效果