您当前的位置: 首页 >  unity

unity工具人

暂无认证

  • 2浏览

    0关注

    205博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity-Shader-接触边界发光

unity工具人 发布时间:2021-08-22 23:34:17 ,浏览量:2

Shader "Kaima/Depth/IntersectionHighlight"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_IntersectionColor("Intersection Color", Color) = (1,1,0,0)
		_IntersectionWidth("Intersection Width", Range(0, 1)) = 0.1
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

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

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
				float4 screenPos : TEXCOORD1;
				float eyeZ : TEXCOORD2;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			sampler2D _CameraDepthTexture;
			fixed4 _IntersectionColor;
			float _IntersectionWidth;
			
			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				o.screenPos = ComputeScreenPos(o.vertex);
				COMPUTE_EYEDEPTH(o.eyeZ);
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{
				fixed4 col = tex2D(_MainTex, i.uv);

				float screenZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPos)));
				
				float halfWidth = _IntersectionWidth / 2;
				float diff = saturate(abs(i.eyeZ - screenZ) / halfWidth);

				fixed4 finalColor = lerp(_IntersectionColor, col, diff);
				return finalColor;
			}
			ENDCG
		}
	}
}

在这里插入图片描述

关注
打赏
1656671177
查看更多评论
立即登录/注册

微信扫码登录

0.0543s