阴影设置软硬,色彩,是否接受阴影Shader

Shader "Custom/SetShadow"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_ShadowIntensity("ShadowIntensity",Range(0,1))=0
		_ShadowColor("ShadowColor",color)=(1,1,1,1)
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#pragma multi_compile_fwdbase
			#include "UnityCG.cginc"
			#include "AutoLight.cginc"
			#include "Lighting.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 pos : SV_POSITION;
			    float3 worldPos:TEXCOORD1;
		        SHADOW_COORDS(2)	
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			fixed4 _ShadowColor;
			fixed _ShadowIntensity;
			v2f vert (appdata v)
			{
				v2f o;
				o.pos = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				o.worldPos=mul(unity_ObjectToWorld,v.vertex).xyz;
				TRANSFER_SHADOW(o);
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{
				// sample the texture
				fixed4 col = tex2D(_MainTex, i.uv);
			    UNITY_LIGHT_ATTENUATION(atten,i,i.worldPos);
			   
			    if(atten<=0.1)
				{
				  atten=_ShadowIntensity;
				  return fixed4(col.rgb*atten*_ShadowColor.rgb,col.a);
				}
				return fixed4(col.rgb*atten,col.a);
			}
			ENDCG
		}
	}
	FallBack "Diffuse"
}

猜你喜欢

转载自blog.csdn.net/qq_37310110/article/details/80576842
今日推荐