Hi all,
Happy user of a Pro version of NGUI, I've encountered a porting issue on Android (on a Galaxy S II), using soft clipped panels : nothing was clipped. It happens the same goes for alpha and hard clipping too.
I finally managed to discover what was wrong : the "#pragma fragmentoption ARB_precision_hint_fastest" directive is not supported on those devices. I also discovered it is not supported on some MacMinis neither, so the problem probably spreads to a lot of other systems.
To fix that, I duplicated the subshader, just removing the aforementioned line of code, so that compatibility-based shader auto selection takes effect. It works, but I find it quite ugly to have the exact same shader duplicated just to remove a single line of code (in particular when its a pragma declaring a 'fragment
option'

).
Isn't their a better way to achieve that using Unity's shader language ? (If not, I think its time for a feature request

: optional options )
In all cases, could a fix be committed to NGUI's repository ?
EDIT: attached one of the modified shaders, with just a bit of code factorization using a Category. For the others, well, you've got the idea

...
Shader "Unlit/Transparent Colored (SoftClip)"
{
Properties
{
_MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
}
Category {
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
}
Cull Off
Lighting Off
ZWrite Off
Fog { Mode Off }
ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha
SubShader
{
LOD 200
Pass
{
Offset -1, -1
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
float2 _ClipSharpness = float2(20.0, 20.0);
struct appdata_t
{
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float2 worldPos : TEXCOORD1;
};
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = v.texcoord;
o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
return o;
}
fixed4 frag (v2f IN) : COLOR
{
// Softness factor
float2 factor = (float2(1.0, 1.0) - abs(IN.worldPos)) * _ClipSharpness;
// Sample the texture
fixed4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
col.a *= clamp( min(factor.x, factor.y), 0.0, 1.0);
return col;
}
ENDCG
}
}
SubShader
{
LOD 200
Pass
{
Offset -1, -1
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
float2 _ClipSharpness = float2(20.0, 20.0);
struct appdata_t
{
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float2 worldPos : TEXCOORD1;
};
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = v.texcoord;
o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
return o;
}
fixed4 frag (v2f IN) : COLOR
{
// Softness factor
float2 factor = (float2(1.0, 1.0) - abs(IN.worldPos)) * _ClipSharpness;
// Sample the texture
fixed4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
col.a *= clamp( min(factor.x, factor.y), 0.0, 1.0);
return col;
}
ENDCG
}
}
SubShader
{
LOD 100
AlphaTest Greater .01
Pass
{
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex]
{
Combine Texture * Primary
}
}
}
}
}