반응형

Shader "CatDarkGame/VFShadow"
{
	Properties
	{
		_MainTex("Texture", 2D) = "white" {}
		_Color("Color", Color) = (1,1,1,1)
	}

	SubShader
	{
		Pass
		{
			Tags{"LightMode" = "ForwardBase" "Queue" = "Opaque" }

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_fwdbase


			#include "UnityCG.cginc"

			 #include "Lighting.cginc"
			 #include "AutoLight.cginc"

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

			struct v2f
			{
				float4 pos : SV_POSITION;
				float2 uv : TEXCOORD0;
				float3 viewDir: TEXCOORD1;
				float3 worldnormal : TEXCOORD2;
				float3 lightDir : TEXCOORD3;
				SHADOW_COORDS(4)	
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			fixed4 _Color;

			v2f vert(appdata v)
			{
				v2f o;
				o.pos = UnityObjectToClipPos(v.vertex);
				o.worldnormal = UnityObjectToWorldNormal(v.normal);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				o.viewDir = WorldSpaceViewDir(v.vertex);
				o.lightDir = WorldSpaceLightDir(v.vertex);

				TRANSFER_SHADOW(o)
				return o;
			}

			fixed4 frag(v2f i) : SV_Target
			{
				fixed fReceiveShadow = SHADOW_ATTENUATION(i);		//! Receive Shadow 감쇠 값
				fReceiveShadow = lerp(fReceiveShadow, 1.0f, 0.5f);	//! Receive Shadow 진함 조정 

				float fNDotL = dot(i.lightDir, i.worldnormal);
				float fHLambert = fNDotL * 0.5f + 0.5f;

				return float4(fHLambert * fReceiveShadow * _Color.rgb, 1);
			}
			ENDCG
		}


		//! Cast Shadow Pass
		Pass
		{
			Tags {"LightMode" = "ShadowCaster"}

			CGPROGRAM

			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_shadowcaster
			#pragma fragmentoption ARB_precision_hint_fastest	//! Fragment FP 성능 옵션

			#include "UnityCG.cginc"

			struct v2f 
			{	
				V2F_SHADOW_CASTER;
			};

			v2f vert(appdata_base v)
			{
				v2f o;
				TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);
				return o;
			}

			float4 frag(v2f i) : SV_Target
			{
				SHADOW_CASTER_FRAGMENT(i);
			}
			ENDCG
		}
	}
}

 

 

Buy Me A Coffee

반응형

'Unity > Shader & VFX' 카테고리의 다른 글

URP 반투명 굴절 구현(Transparent Grabpass)  (3) 2022.03.22
[Tutorial] Hexagon Barrier  (0) 2020.02.14
[Stencil] 3D 영정사진  (0) 2020.02.10
Unity Normal Map 구현 & 분석  (6) 2020.02.05
Hexagon Barrier  (1) 2020.01.31

WRITTEN BY
CatDarkGame
Technical Artist dhwlgn12@gmail.com

,