实现被遮挡部分高亮的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" }
此方法对于简模,比如正方体,高亮会有问题