-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloudShader.shader
96 lines (76 loc) · 3.17 KB
/
CloudShader.shader
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Unlit/CloudShader"
{
Properties
{
_Color ("Main Color", Color) = (1,0.5,0.5,1)
_BgColor ("Background Color", Color) = (1,0.5,0.5,1)
_MaxDist("Maximum Distance", Float) = 100
_MinDist("Minimum Distance", Float) = 20
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
// Fog {}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct MeshData
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct Interpolators
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float3 cameraDistance : TEXCOORD1;
float4 worldDistance : TEXCOORD2;
};
float _MaxDist;
float _MinDist;
float4 _Color;
float4 _BgColor;
float getFogFactor(float d) {
if (d<=_MinDist) return 0;
if (d>=_MaxDist) return 1;
return 1 - (_MaxDist - d) / (_MaxDist - _MinDist);
}
float4 mix(float4 originalColor, float4 fogColor, float fogFactor) {
return originalColor*(1-fogFactor)+fogColor*fogFactor;
}
Interpolators vert (MeshData v)
{
Interpolators o;
o.cameraDistance = UnityObjectToViewPos(v.vertex);
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldDistance = mul(unity_ObjectToWorld, v.vertex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (Interpolators i) : SV_Target
{
// Include Fog
float fogAmount = getFogFactor(-i.cameraDistance.z);
fixed4 blend = mix(_Color, _BgColor, fogAmount);
// Add Watercolour pattern. Mulitiplied by 0.04 to increase size of pattern
fixed3 waterColorVertex = (i.worldDistance)*0.04;
// For loop for stilness of watercolour pattern
for(int n = 1; n<2; n++) {
float i = float(n);
waterColorVertex = waterColorVertex + float3(0.5/i*sin(i*waterColorVertex.y + _Time.y + 0.3*i) + 0.8, 0.5/i*sin(waterColorVertex.z + _Time.y + 0.3*i) + 0.8, 0.5/i*sin(waterColorVertex.x + _Time.y + 0.3*i) + 0.8);
}
// black and white water pattern on all three axis
fixed4 waterColPattern = float4(sin(waterColorVertex.x + waterColorVertex.y + waterColorVertex.z),sin(waterColorVertex.x + waterColorVertex.y + waterColorVertex.z),sin(waterColorVertex.x + waterColorVertex.y + waterColorVertex.z), sin(waterColorVertex.x + waterColorVertex.y + waterColorVertex.z));
return blend+(waterColPattern/40);
}
ENDCG
}
}
}