//Shader By Alpha 2016/06/14//
//转载请注明出处//
Shader "MXR/CutoutSoftEdgeShadow" {
Properties {
_Color ("Main Color", Color) = (1, 1, 1, 1)
_Cutoff ("Base Alpha cutoff", Range (0,.9)) = .5
_Texture1 ("Texture 1", 2D) = ""
}
SubShader {
Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
Pass {
Tags { "LightMode"="ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct appdata_t {
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD1;
LIGHTING_COORDS(2, 3)
};
sampler2D _Texture1;
float4 _Texture1_ST;
float _Cutoff;
float4 _LightColor0;
v2f vert (appdata_t v)
{
v2f o;
// o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord, _Texture1);
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
float4 _Color;
half4 frag (v2f i) : COLOR
{
half4 col = tex2D(_Texture1, i.texcoord);
clip(col.a - _Cutoff);
float4 atten = LIGHT_ATTENUATION(i);
return col * atten;
}
ENDCG
}
// Second pass:
// render the semitransparent details.
Pass {
Tags { "RequireOption" = "SoftVegetation" "LightMode"="ForwardBase"}
blend srcalpha oneminussrcalpha
// Dont write to the depth buffer
ZWrite off
// Set up alpha blending
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct appdata_t {
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
LIGHTING_COORDS(4, 5)
};
sampler2D _Texture1;
float4 _Texture1_ST;
float _Cutoff;
v2f vert (appdata_t v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord, _Texture1);
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
float4 _Color;
half4 frag (v2f i) : COLOR
{
half4 col = tex2D(_Texture1, i.texcoord);
clip(-(col.a - _Cutoff));
float4 atten = LIGHT_ATTENUATION(i);
return col * atten;
}
ENDCG
}
}
FallBack "Diffuse"
}
Unity3d同时支持半透、Cutout、阴影三种属性Shader
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...