Unity - 着色器在Android(OpenGL)和编辑器(DX11)上的工作方式不同

时间:2015-05-04 12:34:31

标签: android opengl-es unity3d directx shader

我写了一个圆形镂空精灵着色器,它在编辑器中工作正常。独立版本,但在Android设备上行为不正确。

本质上它是简单的像素着色器:

fixed4 frag(pixelData IN) : SV_Target
{
 const float PI = 3.1415;
 float angle = -atan2(IN.texcoord.x - 0.5, -IN.texcoord.y + 0.5) + PI;

 if (angle < _Percent * 2 * PI) //_Percent is in range from 0 to 1        
     return tex2D(_MainTex, IN.texcoord) * IN.color;            
 else
     return float4(1,1,1,0);            
}

在编辑器中渲染(DX9 GPU上的DX11)

enter image description here

Android屏幕截图(OpenGL - Nexus 4)

正如您可以在中间看到的那样,有些像素应该是红色的

enter image description here

我使用的是Unity 5.0.0f4。附加压缩测试项目:ShaderTest.zip(30kB)

2 个答案:

答案 0 :(得分:0)

atan2中,当y参数从上方接近零(例如 - IN.texcoord.x - 0.5 ~= +0)时,您将开始在PI附近获取值,因为您将获得{{ 1}},其中arctan(y/x) + PIy ~= 0http://en.wikipedia.org/wiki/Atan2)。 Android版本可能使用较低精度的浮点运算,因此在那里更加引人注目。可能如果您在桌面版上放大了足够的距离,您会看到像素也会失败。

答案 1 :(得分:0)

更新到更新版本的Unity后,问题解决了。