[英]Unity Alpha Diffuse Mask Shader
我正在使用最新版本的Unity 5.2.2在Unity中工作,我问是否可以创建可以淡化蒙版的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}
}
}
}
我需要添加颜色属性或其他内容吗? 我想要的只是淡出该对象,使其不再可见。 我不能只是禁用它,它实际上必须平滑消失。
谢谢。
弄清楚了。
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
}
}
}
}
我不知道您进行遮罩的方式,但是通常我会使用Pixelshader。 我发现了此博文,对您有帮助。 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
}
}
}
希望这是您要寻找的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.