[英]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.