unity中全息投影带贴图shader
2017-11-20 16:10
531 查看
Shader "Custom/Hologram" { Properties{ _Color("Color", Color) = (1,1,1,1) _ColorScale("Scale", Float) = 1 _ScaningAmount("Scaning Amount", Float) = 10 _ScaningSpeed("Scaning Speed", Float) = 1 _SplashLevel("Splash Level", Range(0, 1)) = 0 _SplashFrequency("Splash Frequency", Float) = 1 _MainTex("Base (RGB)", 2D) = "white" { } _Illum("Illumin (A)", 2D) = "white" { } } SubShader{ Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True" } LOD 300 CGPROGRAM #pragma surface surf Lambert sampler2D _MainTex; sampler2D _Illum; struct Input { float2 uv_MainTex; float2 uv_Illum; }; void surf(Input IN, inout SurfaceOutput o) { fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); fixed4 c = tex * _Color; o.Albedo = c.rgb; o.Emission = c.rgb * tex2D(_Illum, IN.uv_Illum).a; o.Alpha = c.a; } ENDCG CGINCLUDE #include "UnityCG.cginc" fixed4 _Color; float _ColorScale; float _ScaningAmount; float _ScaningSpeed; fixed _SplashLevel; float _SplashFrequency; struct v2f { float4 pos : SV_POSITION; float4 srcPos : TEXCOORD0; float3 worldNormal : TEXCOORD1; float3 worldViewDir : TEXCOORD2; }; v2f vert(appdata_base v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.srcPos = ComputeScreenPos(o.pos); o.worldNormal = UnityObjectToWorldNormal(v.normal); o.worldViewDir = UnityWorldSpaceViewDir(v.vertex); return o; } fixed4 frag(v2f i) : SV_TARGET{ fixed3 worldNormal = normalize(i.worldNormal); fixed3 worldViewDir = normalize(i.worldViewDir); // 视线和法线越平行,看到的全息投影越亮 fixed3 hologram = _Color.rgb * abs(dot(worldNormal, worldViewDir)) * _ColorScale; // 计算扫描线的亮暗 float t = _Time.y; fixed tDecimal = t - floor(t); float splashFrequency = tDecimal * _SplashFrequency; half y = (i.srcPos.y * _ScaningAmount) / i.srcPos.w + tDecimal * _ScaningSpeed; half scaninglineY = floor(y); half scaningScale = lerp(0, 1, abs((y - scaninglineY) - 0.5) * 2); fixed4 finalColor = fixed4(hologram, _Color.a * scaningScale * lerp(1 - _SplashLevel, 1, splashFrequency - floor(splashFrequency))); return finalColor; } ENDCG Pass { ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Front CGPROGRAM #pragma vertex vert #pragma fragment frag ENDCG } Pass { ZWrite Off Blend SrcAlpha One Cull Back CGPROGRAM #pragma vertex vert #pragma fragment frag ENDCG } } }
相关文章推荐
- unity混合两种贴图shader
- Unity游戏画面品质增强,shader和贴图
- unity中使用自定义shader进行光照贴图烘培无法出现透明度的坑爹问题
- [置顶] 神临的Unity shader 学习之法线贴图(三)
- Unity Shader:三向贴图(Tri-planar mapping)---解决地形拉伸贴图变形以及贴图边缘的缝隙问题
- Unity-Shader之法线贴图使用注意事项
- Unity Shader Example 8 (光照贴图)
- 在Unity的后处理shader中通过屏幕像素坐标和深度贴图反推世界坐标
- Unity之Shader过滤掉不带Alpha通道贴图的背景颜色 - 四
- 【猫猫的Unity Shader之旅】之法线贴图的运用
- 【Unity实用小方法】判断shader使用贴图数
- Unity之Shader Pass 通道显示贴图的几种方法- 六
- Unity 检查带有默认贴图的shader
- Unity Shader-法线贴图(Normal Map)与视差贴图(Parallax Map)
- Unity 法线贴图、高光贴图、Cube Map shader
- 【Unity Shader】 CubeMap(立方体贴图)
- [Unity] Shader(着色器)之纹理贴图
- Unity Shader-法线贴图(Normal Map)与视差贴图(Parallax Map)
- UnityShader之纹理贴图滚动实现(修改UV坐标)
- 学习UnityShader入门精要笔记3——更复杂的光照