【发布时间】:2015-12-07 16:46:44
【问题描述】:
首先,我对着色器编程一无所知,但我的游戏需要它,所以我在互联网上找到了一个剪辑区域着色器,然后我试图对其进行修改并添加一些功能!我在我的精灵中添加了着色器,并在我的 PC 和一些安卓设备上检查了它,但之后我在 HTC One(我的朋友手机)上检查了它,但奇怪的问题发生了!
如您所见,左侧没有在视觉上剪裁。
我发现的第一个着色器只有用于剪切精灵的宽度和长度,然后我在着色器中添加了从左到右的宽度和颜色。
有一个代码:
Shader "Sprites/ClipAreaWithAlpha"
{
Properties
{
_Color ("Color Tint", Color) = (1,1,1,1)
_MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
_Length ("Length", Range(0.0, 1.0)) = 1.0
_WidthR("Width from right", Range(0.0, 1.0)) = 1.0
_WidthL ("Width from left", Range(0.0, 1.0)) = 0.0
}
SubShader
{
LOD 200
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
}
Pass
{
Cull Off
Lighting Off
ZWrite Off
Offset -1, -1
Fog { Mode Off }
ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
float _Length;
float _WidthR;
float _WidthL;
half4 _Color;
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
half4 color : COLOR;
};
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = v.texcoord;
o.color = _Color;
return o;
}
half4 frag (v2f IN) : COLOR
{
if ((IN.texcoord.x<_WidthL) || (IN.texcoord.x>_WidthR) || (IN.texcoord.y<0) || (IN.texcoord.y>_Length))
{
half4 colorTransparent = half4(0,0,0,0) ;
return colorTransparent;
}
else
{
half4 tex = tex2D(_MainTex, IN.texcoord);
tex.a = IN.color.a;
return tex;
}
}
ENDCG
}
}
}
正如我之前所说,此着色器在我检查过的另一台 android 设备上正常,但在 HTC One 上却不能正常工作。我不知道问题出在哪里!我很感谢您的解决方案。
这个着色器有这个警告:MaterialPropertyBlock is used to modify these values
【问题讨论】:
-
我还没有找到解决办法。
-
尝试删除“ColorMask RGB”