Shader for Quest 2: 自定义shader在Unity Editor中可以使用,但是在Quest 2中却不可以

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 API

The Oculus Quest 2 primarily uses OpenGL ES and Vulkan.
在这里插入图片描述

确保shader compatible with the Graphics API

在这里插入图片描述

设置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.在这里插入图片描述
除了自己的custom shader需要拖进来之外,一些内置的shaders,例如Unlit/Texture 也需要拖进来。这可能是由于将Graphics API修改了,这些内置的shaders也不能被找到了。

其他

如果还不行,那可能是其他代码逻辑的问题,或者是shader的问题。那可以先写一个简单的shader,例如简单变成红色,赋值到一个default cube or sphere上,一步一步地看是哪里出了问题。例如在我的代码中,就发现全部360图片呈现白色,是因为另外一个球遮挡住了其他球。

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值