Shader全息效果实现
发表于2018-12-05
项目需要模型在展示时,可以拥有类似全息投影的效果,类似一些科幻电影或者是高科技的场景。本文就给大家分享下shader全息效果的实现。
效果图
Properties{ _Color("Color", Color) = (1,1,1,1) _MainTex("Albedo (RGB)", 2D) = "white" {} _DotProduct("Rim effect", Range(-1,1)) = 0.25 } SubShader{ Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } LOD 200 Cull Off CGPROGRAM #pragma surface surf Lambert alpha:fade nolighting sampler2D _MainTex; fixed4 _Color; float _DotProduct; struct Input { float2 uv_MainTex; float3 worldNormal; float3 viewDir; }; //void surf(Input IN, inout SurfaceOutputStandard o) { void surf(Input IN, inout SurfaceOutput o) { float4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; float border = 1 - (abs(dot(IN.viewDir, IN.worldNormal))); float alpha = (border * (1 - _DotProduct) + _DotProduct); o.Alpha = c.a * alpha; } ENDCG } FallBack "Diffuse"
也可以作为边缘、轮廓的算法。