码迷,mamicode.com
首页 > 其他好文 > 详细

被遮挡部分高亮

时间:2021-05-24 13:02:50      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:hat   nes   about   lin   als   实现   standard   app   art   

1.前言

实现被遮挡部分高亮的shader

2.完整shader

Shader "Custom/HiddenHilight" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_Glossiness ("Smoothness", Range(0,1)) = 0.5
		_Metallic ("Metallic", Range(0,1)) = 0.0

			//part of being occlusion
		_Color("Occlusion Color", Color) = (0,1,1,1)
		_Width("Occlusion Width", Range(0, 10)) = 1
		_Intensity("Occlusion Intensity",Range(0, 10)) = 1
	}

	SubShader {
		Tags { "Queue" = "Transparent"}
		LOD 200

		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		#pragma surface surf Standard fullforwardshadows

		// Use shader model 3.0 target, to get nicer looking lighting
		#pragma target 3.0

		sampler2D _MainTex;

		struct Input {
			float2 uv_MainTex;
		};

		half _Glossiness;
		half _Metallic;
		fixed4 _Color;

		// Add instancing support for this shader. You need to check ‘Enable Instancing‘ on materials that use the shader.
		// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
		// #pragma instancing_options assumeuniformscaling
		UNITY_INSTANCING_BUFFER_START(Props)
			// put more per-instance properties here
		UNITY_INSTANCING_BUFFER_END(Props)

		void surf (Input IN, inout SurfaceOutputStandard o) {
			// Albedo comes from a texture tinted by color
			fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			o.Albedo = c.rgb;
			// Metallic and smoothness come from slider variables
			o.Metallic = _Metallic;
			o.Smoothness = _Glossiness;
			o.Alpha = c.a;
		}
		ENDCG

		Pass
		{
			ZTest Greater
			ZWrite Off

			Blend SrcAlpha OneMinusSrcAlpha

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

			struct v2f
			{
				float4 worldPos : SV_POSITION;
				float3 viewDir : TEXCOORD0;
				float3 worldNor : TEXCOORD1;
			};

			fixed4 _Color;
			fixed _Width;
			half _Intensity;

			v2f vert(appdata_base v)
			{
				v2f o;
				o.worldPos = UnityObjectToClipPos(v.vertex);
				o.viewDir = normalize(WorldSpaceViewDir(v.vertex));
				o.worldNor = UnityObjectToWorldNormal(v.normal);

				return o;
			}

			float4 frag(v2f i) : SV_Target
			{
				half NDotV = saturate(dot(i.worldNor, i.viewDir));
				NDotV = pow(1 - NDotV, _Width) * _Intensity;

				fixed4 color;
				color.rgb = _Color.rgb;
				color.a = NDotV;
				return color;
			}
			ENDCG
		}
	}
	FallBack "Diffuse"
}

3.结论

此方法对于简模,比如正方体,高亮会有问题

被遮挡部分高亮

标签:hat   nes   about   lin   als   实现   standard   app   art   

原文地址:https://www.cnblogs.com/llstart-new0201/p/14774455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!