冯乐乐的《Unity Shader入门精要》附带项目,其中部分shader已经修改测试
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.2 KiB

3 years ago
Shader "Unlit/TestFogShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_FogAlpha("Fog Alpha",Range(0.0,1.0))= 1.0
_FogColor("Fog Color",COLOR) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Transparent" }
LOD 100
Pass
{
Cull Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 srcVertex : TEXCOORD1;
float4 scrPos : TEXCOORD2;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _FogAlpha;
fixed4 _FogColor;
v2f vert (appdata v)
{
v2f o;
o.srcVertex = v.vertex;
o.vertex = UnityObjectToClipPos(v.vertex);
o.scrPos = ComputeScreenPos(o.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 colAlpha = fixed4(col.rgb,clamp(col.a*abs(i.scrPos.y),0.0,1.0));
return colAlpha*_FogAlpha*_FogColor;
}
ENDCG
}
}
}