Hexagon Barrier

Unity/Shader & VFX 2020. 1. 31. 23:40
반응형

Shader "JH/FX/Sh_HexagonBarrier"
{
	Properties
	{
		[HDR] _BaseColor("Base Color", Color) = (1,1,1,1)

		[HDR] _InnerSpecularColor("Inner Specular Color", Color) = (1,1,1,1)
		_InnerSpecularPow("Inner Specular Pow", float) = 30
		_InnerSpecularMul("Inner Specular Mul", float) = 0.1
       
		_BumpTex("Hex Normal Texture", 2D) = "bump" {}
	
		_FresnelPow("Fresnel Pow", float) = 2
		_FresnelMul("Fresnel Mul", float) = 1
		[HDR] _FresnelColor("Fresnel Color", Color) = (1,1,1,1)

		_DistortionTex("Distortion Texture", 2D) = "bump" {}
		_DistortionMul("Distortion Mul", float) = 1.0

		[HDR] _HexLineColor("Hex Line Color", Color) = (1,1,1,1)
		_HexTex("Hex Texture", 2D) = "white" {}
		_LineTex("Line Mask Texture", 2D) = "white" {}

		[HDR] _OverlapColor("Overlap Color", Color) = (1,1,1,1)
		_DepthFadeMul("DepthFadeMul", float) = 1
    }
    SubShader
    {
		Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
        LOD 100

		GrabPass
		{
			"_GrapPass"
		}

		Cull back
		ZWrite Off
		Blend SrcAlpha OneMinusSrcAlpha

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
           

            #include "UnityCG.cginc"

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

            struct v2f
            {
               
                float4 vertex : SV_POSITION;
				float2 uv : TEXCOORD0;
				half3 viewDir : TEXCOORD1;
				float4 grabPos : TEXCOORD2;

				half3 tspace0 : TEXCOORD3;
				half3 tspace1 : TEXCOORD4;
				half3 tspace2 : TEXCOORD5;

				float3 lightDir : TEXCOORD6;
				float4 screenPosition : TEXCOORD7;
            };

			float4 _BaseColor;
            
			sampler2D _HexTex;
			float4 _HexTex_ST;
			float4 _HexLineColor;

			sampler2D _LineTex;
			float4 _LineTex_ST;


			sampler2D _BumpTex;
			float4 _BumpTex_ST;

			sampler2D _DistortionTex;
			float4 _DistortionTex_ST;
			half _DistortionMul;

			sampler2D _GrapPass;

			float _FresnelMul;
			float _FresnelPow;
			half4 _FresnelColor;

			half _InnerSpecularPow;
			half _InnerSpecularMul;
			float4 _InnerSpecularColor;
			

			float _DepthFadeMul;
			sampler2D _CameraDepthTexture;

			float4 _OverlapColor;

			fixed Fuc_Fresnel(half fNDotV, half fPow, half fMul)
			{
				half fInverseRim = 1 - abs(fNDotV);
				return saturate((pow(fInverseRim, fPow) * fMul));
			}

            v2f vert (appdata v)
            {
                v2f o;
				
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _BumpTex);

				half3 worldnormal = UnityObjectToWorldNormal(v.normal);
				o.viewDir = normalize(WorldSpaceViewDir(v.vertex));
				o.grabPos = ComputeGrabScreenPos(o.vertex);

				half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz);
				half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
				half3 wBitangent = cross(worldnormal, wTangent) * tangentSign;
				o.tspace0 = half3(wTangent.x, wBitangent.x, worldnormal.x);
				o.tspace1 = half3(wTangent.y, wBitangent.y, worldnormal.y);
				o.tspace2 = half3(wTangent.z, wBitangent.z, worldnormal.z);
				
				o.lightDir = ObjSpaceLightDir(v.vertex);

				o.screenPosition = ComputeScreenPos(o.vertex);
				COMPUTE_EYEDEPTH(o.screenPosition.z);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
				fixed intersect = saturate((abs(LinearEyeDepth(tex2Dproj(_CameraDepthTexture,i.screenPosition).r) - i.screenPosition.z)) / (_DepthFadeMul));
				intersect = 1-saturate(intersect);

				fixed3 fHexNormal = UnpackNormal(tex2D(_BumpTex, i.uv * _BumpTex_ST.rg));
				
				half3 worldNormal;
				worldNormal.x = dot(i.tspace0, fHexNormal);
				worldNormal.y = dot(i.tspace1, fHexNormal);
				worldNormal.z = dot(i.tspace2, fHexNormal);


				fixed3 fHalfVector = normalize(i.lightDir + i.viewDir);
				float fBPSpecular = saturate(dot(worldNormal, fHalfVector));
				
				fBPSpecular = clamp(0, 0.1f, pow(fBPSpecular, _InnerSpecularPow) * _InnerSpecularMul);
				

				half fNDotV = dot(worldNormal, i.viewDir);
				fixed fFresnel = Fuc_Fresnel(fNDotV, _FresnelPow, _FresnelMul);
				fFresnel *= lerp(0.5f, 1.0f, abs(sin(_Time.y*2)));
				half4 fFresnelColor = _FresnelColor * fFresnel;
				fixed fFresnel_Back = Fuc_Fresnel(fNDotV, 1.5f, 5.0f);
			

				float3 fDistortionTex = UnpackNormal(tex2D(_DistortionTex, i.uv * _DistortionTex_ST.rg + float2(0.0f, _Time.y*0.0f)));
				fixed2 fDistortionData = fDistortionTex.rg * _DistortionMul;
				fixed4 fGrapPass = tex2Dproj(_GrapPass, i.grabPos -float4(fDistortionData.r, fDistortionData.g, 0, 0));
				fGrapPass = clamp(0.01, 1, fGrapPass * fFresnel_Back);


				fixed4 fHexTex = tex2D(_HexTex, i.uv * _HexTex_ST.rg);
				fixed4 fLineTex = tex2D(_LineTex, i.uv * _LineTex_ST.rg + float2(0.0f, _Time.y*1.0f));

				float4 fHexColor = 1;
				fHexColor.rgb = fHexTex.r*fLineTex.r *_HexLineColor.rgb * Fuc_Fresnel(fNDotV, 8.5f, 5.0f);
				fHexColor.a = fHexTex.r*fLineTex.r *_HexLineColor.a;
				
				float4 fFinalColor = 1;
				fFinalColor.rgb = fGrapPass.rgb +
					fFresnelColor +
					(fBPSpecular * _InnerSpecularColor) + fHexColor.rgb +
					((intersect) * _OverlapColor);
				
				fFinalColor.a = fFresnelColor.a + fGrapPass.a + fHexColor.a;
				fFinalColor.rgb = (fFinalColor.rgb+0.01f) * _BaseColor.rgb ;
				fFinalColor.a +=  _BaseColor.a + ((intersect));
				fFinalColor.a = saturate(fFinalColor.a);
				return fFinalColor;
            }
            ENDCG
        }
    }
}

 

반응형

WRITTEN BY
CatDarkGame
Technical Artist dhwlgn12@gmail.com

,