0
首先,我對於着色器編程沒有任何意見,但是我需要它用於我的遊戲,所以我在互聯網上找到了剪輯區域着色器,然後嘗試修改它並添加一些功能去吧!我向我的精靈添加了着色器,並在我的PC和一些Android設備上檢查了它,但是之後我在HTC One(我的朋友移動設備)上檢查過它,但奇怪的問題正在發生!Unity3D中的剪輯區域着色器
正如你所看到的左側沒有限視覺。
我發現的第一個着色器只有剪裁精靈的寬度和長度,然後我從左側和右側的寬度加上寬度,並將顏色着色添加到着色器。
有一個代碼:
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
}
}
}
正如我以前說過這個着色器是對我查了,但是,HTC之一,它不能很好地和正確地工作在其他Android設備確定。我不知道問題出在哪裏!我很感謝解決方案。
而這種着色器這樣的警告:MaterialPropertyBlock is used to modify these values
我還沒有找到解決方案。 – ATHellboy
嘗試刪除「ColorMask RGB」 –