在网上研究了好长一段时间的高度雾 ,大概的方法分两种,一种是屏幕特效,一种是区域的模拟,都是需要开启相机的深度图,对移动端来说效率还是有一定的影响的,最后都放弃了。用我的野路子方法实现了个物体上的高度雾,远近雾,云海 效果如图:
代码如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77Shader "scenes/FogSceneObj" { Properties { _MainTex ("Texture", 2D) = "white" {} _DepthStartFog("StartFog",float) = 0 _DepthEndFog("EndFog",float) = 0.2 _FogColor("FogColor",Color) = (1,1,1,1) _LineStartFog("LineStartFog",float) = 0 _LineEndFog ("LineEndFog",float) = 50 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; float2 uvLM:TEXCOORD1; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; #ifdef LIGHTMAP_ON half2 uvLM:TEXCOORD1; #endif float3 worldPos:TEXCOORD2; fixed LineDistance : TEXCOORD3; }; sampler2D _MainTex; float4 _MainTex_ST; fixed _DepthStartFog; fixed _DepthEndFog; fixed4 _FogColor; fixed _LineStartFog; fixed _LineEndFog; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; o.uv = TRANSFORM_TEX(v.uv, _MainTex); #ifdef LIGHTMAP_ON o.uvLM = v.uvLM.xy*unity_LightmapST.xy + unity_LightmapST.zw; #endif o.LineDistance = distance(o.worldPos.xyz, _WorldSpaceCameraPos.xyz); return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); #ifdef LIGHTMAP_ON fixed3 lm = (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uvLM))); col.rgb *= lm; #endif fixed Depthfog =saturate( (i.worldPos.y - _DepthStartFog) / (_DepthEndFog - _DepthStartFog)); col.rgb = lerp(_FogColor.rgb, col.rgb, Depthfog); fixed Linefog = saturate((i.LineDistance - _LineStartFog)/ (_LineEndFog - _LineStartFog)); col.rgb = lerp( col.rgb, _FogColor.rgb, Linefog); return col; } ENDCG } } }
说明:这是个shader,能在搞效率的情况下实现这样的shader,我们的美术比较满意。缺点:需要每个物体都用这样的shader,才能实现,然后每个物体要设置数值。需要给美术写工具 统一调整数值。
最后
以上就是怕孤独白昼最近收集整理的关于Shader之——高效率高度雾 云海的全部内容,更多相关Shader之——高效率高度雾内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复