[Unity Shader] 在移动平台无法正常显示可能的原因:

一、手机GPU对于目标平台的不支持。

这边需要参考具体手机GPU对图形API的支持性,下面是Unity官方文档对Supported #pragma target的描述:

Here is the list of shader models supported, with roughly increasing set of capabilities (and in some cases higher platform/GPU requirements):

#pragma target 2.0

  • Works on all platforms supported by Unity. DX9 shader model 2.0.
  • Limited amount of arithmetic & texture instructions; 8 interpolators; no vertex texture sampling; no derivatives in fragment shaders
    ; no explicit LOD
     texture sampling.

#pragma target 2.5 (default)

  • Almost the same as 3.0 target (see below), except still only has 8 interpolators, and does not have explicit LOD texture sampling.
  • Compiles into DX11 feature level 9.3 on Windows Phone.

#pragma target 3.0

  • DX9 shader model 3.0: derivative instructions, texture LOD sampling, 10 interpolators, more math/texture instructions allowed.
  • Not supported on DX11 feature level 9.x GPUs (e.g. most Windows Phone devices).
  • Might not be fully supported by some OpenGL ES 2.0 devices, depending on driver extensions present and features used.

#pragma target 3.5 (or es3.0)

  • OpenGL ES 3.0 capabilities (DX10 SM4.0 on D3D platforms, just without geometry shaders).
  • Not supported on DX11 9.x (WinPhone), OpenGL ES 2.0.
  • Supported on DX11+, OpenGL 3.2+, OpenGL ES 3+, Metal, Vulkan, PS4
    /XB1 consoles.
  • Native integer operations in shaders, texture arrays, etc
    .

#pragma target 4.0

  • DX11 shader model 4.0.
  • Not supported on DX11 9.x (WinPhone), OpenGL ES 2.0/3.0/3.1, Metal.
  • Supported on DX11+, OpenGL 3.2+, OpenGL ES 3.1+AEP, Vulkan, PS4/XB1 consoles.
  • Has geometry shaders and everything that es3.0 target has.

#pragma target 4.5 (or es3.1)

  • OpenGL ES 3.1 capabilities (DX11 SM5.0 on D3D platforms, just without tessellation shaders).
  • Not supported on DX11 before SM5.0, OpenGL before 4.3 (i.e. Mac), OpenGL ES 2.0/3.0.
  • Supported on DX11+ SM5.0, OpenGL 4.3+, OpenGL ES 3.1, Metal, Vulkan, PS4/XB1 consoles.
  • Has compute shaders, random access texture writes, atomics etc. No geometry or tessellation shaders.

#pragma target 4.6 (or gl4.1)

  • OpenGL 4.1 capabilities (DX11 SM5.0 on D3D platforms, just without compute shaders). This is basically the highest OpenGL level supported by Macs.
  • Not supported on DX11 before SM5.0, OpenGL before 4.1, OpenGL ES 2.0/3.0/3.1, Metal.
  • Supported on DX11+ SM5.0, OpenGL 4.1+, OpenGL ES 3.1+AEP, Vulkan, Metal (without geometry), PS4/XB1 consoles.

#pragma target 5.0

  • DX11 shader model 5.0.
  • Not supported on DX11 before SM5.0, OpenGL before 4.3 (i.e. Mac), OpenGL ES 2.0/3.0/3.1, Metal.
  • Supported on DX11+ SM5.0, OpenGL 4.3+, OpenGL ES 3.1+AEP, Vulkan, Metal (without geometry), PS4/XB1 consoles.

简而言之就是shader的pragma描述的对应平台相对的OpenGL版本你的手机集成的GPU是否支持。

如果不支持,shader最后的fallback语句,可能就会导致shader出现一些诡异的问题。

具体设备对应的GPU型号可以去CPU天梯图啊什么的搜索到,然后百度GPU对应的API平台。

 

二、#pragma对平台支持的剔除

一次项目中发现的问题,没仔细看还真是不知道- -,如下:

#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
exclude_renderers

exclude...剔除...也就是后面写的那些全不支持了,安卓平台的gles和ios的metal都被剔除了,所以打包之后肯定是会出问题...

 

随手记,暂时就这些了。。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

国家一级摸鱼选手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值