被遮挡部分高亮
2021/5/16 18:55:40
本文主要是介绍被遮挡部分高亮,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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.结论
此方法对于简模,比如正方体,高亮会有问题
这篇关于被遮挡部分高亮的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南