我在Unity中工作,使用Unity 5.2.2的最新版本,我在问,是否有可能创建一个可以淡出蒙版的alpha蒙版着色器。现在我有这个着色器
Shader "MaskedTexture"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent"}
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] {combine texture, previous}
}
}
}

我需要添加一个颜色属性还是什么?我想要的就是淡出这个物体,这样它就不再可见了。我不能简单地禁用它,它实际上必须平滑地淡出。
谢谢。
发布于 2015-11-30 16:46:55
我想通了。
Shader "MaskTexture"
{
Properties
{
_Color ("Main Color", Color) = (1, 1, 1, 1)
_MainTex ("Base (RGB) Transparency (A)", 2D) = "" { }
_Mask ("Culling Mask", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] { combine texture, previous }
SetTexture [_MainTex] {
constantColor [_Color]
combine previous * constant
}
}
}
}发布于 2015-11-28 00:29:42
我不知道你做蒙版的方式,但我通常会使用像素着色器。我找到了这篇博文,我认为它对你有帮助。http://bensilvis.com/unity3d-unlit-alpha-mask-shader/
我使用了代码并为alpha添加了一个额外的值来调整蒙版的数量。
// - no lightmap support
// - no per-material color
Shader "AlphaMask" {
Properties {
_alphaValue ("Alpha Value", Range (0, 1)) = 1
_MainTex ("Base (RGB)", 2D) = "white" {}
_AlphaTex ("Alpha mask (R)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _AlphaTex;
float _alphaValue;
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
fixed4 col2 = tex2D(_AlphaTex, i.texcoord);
//Uncomment for only alpha of mask
//float alpha = col2.r+_alphaValue;
//return fixed4(col.r, col.g, col.b,alpha);
return fixed4(col.r, col.g, col.b,_alphaValue);
}
ENDCG
}
}
}希望这就是你要找的
https://stackoverflow.com/questions/33960669
复制相似问题