忙于生活的奔波,迷失在这世间的万紫千红,只有坐在电脑前才会让我感到平静,但愿这次回到来人生不再漂泊。
shader使用了3个pass,来实现物体阴影与背景融合的效果,里面的宏参阅include的几个文件。
//code--------start
Shader "tcRecShadowAR" {//by tc ,at cas,in otc
subShader{
Tags { "Queue"="Opaque" "IgnoreProjector"="True" "RenderType"="Opaque" }
LOD 200
//
GrabPass {}
//visibly
Pass {
Tags {"LightMode" = "ForwardBase"}
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fwdbase
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#include "Lighting.cginc"
struct v2f
{
float4 pos : POSITION;
float4 uv : texcoord0;
LIGHTING_COORDS(1,2)
};
//
float4 _GrabTexture_ST;
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
#if UNITY_UV_STARTS_AT_TOP
float scale = -1.0;
#else
float scale = 1.0;
#endif
o.uv.xy = (float2(o.pos.x, o.pos.y*scale) + o.pos.w) * 0.5;
o.uv.zw = o.pos.zw;
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
//
sampler2D _GrabTexture;
float4 frag(v2f i) : COLOR
{
float4 c;
float atten = LIGHT_ATTENUATION(i);
c.rgb = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uv)) * atten;
c.a = saturate(1 - atten);
return c;
}
ENDCG
}
//
Pass {
Name "ShadowCollector"
Tags { "LightMode" = "ShadowCollector" }
//
Fog {Mode Off}
ZWrite On
ZTest LEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcollector
#define SHADOW_COLLECTOR_PASS
#include "UnityCG.cginc"
//
struct appdata {
float4 vertex : POSITION;
};
struct v2f {
V2F_SHADOW_COLLECTOR;
};
v2f vert (appdata v)
{
v2f o;
TRANSFER_SHADOW_COLLECTOR(o)
return o;
}
fixed4 frag (v2f i) : COLOR
{
SHADOW_COLLECTOR_FRAGMENT(i)
}
ENDCG
}
}
}
//code--------end