-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCloud.txt
247 lines (200 loc) · 8.57 KB
/
Cloud.txt
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
float3 color = float3(0,0,0);
float3 sun_direction = normalize( float3(0.6,0.45,-0.8) );
float3 SunPower = float3(1.0,0.9,0.6) * 750.0;
float3 LOW_SCATTER = float3(1.0, 0.7, 0.5);
float mu = dot(sun_direction, dir);
float4 test = float4(0,0,0,0);
//skyRay
//nbSample = RaymarchStep;
float3 result = float3(0,0,0);
float3 p = org + distToAtmStart * dir;
float stepS = (distToAtmEnd - distToAtmStart) / RaymarchStep;
float T = 1;
//phaseFuntion
p += dir * stepS;// * hashSky;
if(dir.z < yThreshold){
for(int i = 0; i < RaymarchStep; i++){
float cloudHeightIn;
float density = 0.0;
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////sample clouds/////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
float atmosHeight = length(p - center) - EarthRadius;
cloudHeightIn = clamp((atmosHeight-CloudStart)/(CloudHeight), 0.0, 1.0);
p.z += Time*10.3;
float largeWeather = clamp((WeatherTex.SampleLevel(WeatherTexSampler, -0.0000005*p.yx, 0.0).x-0.03)*10.0, 0.0, 2.0);
p.x += Time*8.3;
float weather = largeWeather*max(0.0, WeatherTex.SampleLevel(WeatherTexSampler, 0.000002*p.yx, 0.0).x - 0.01) /0.72;
//weather *= smoothstep(0.0, 0.5, cloudHeightIn) * smoothstep(1.0, 0.5, cloudHeightIn);
float cloudShape = pow(weather, 0.3+1.5*smoothstep(0.2, 0.5, cloudHeightIn));
//if(cloudShape <= 0.0) return 0.0;
if(cloudShape > 0.0){
p.x += Time*12.3;
//calculate fbm return FBM1
float3x3 m = {0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64};
float f_FBM;
float3 pFBM = p * 0.01 * FPerlin; //float den= max(0.0, cloudShape-0.7*fbm(p*.01));
//noise1
float3 pN = floor(pFBM);
float3 fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
float2 uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
float2 rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
float noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM = 0.5000*noise; pFBM = mul(m,pFBM)*2.02;/////////////1
//noise2
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.2500*noise; pFBM = mul(m,pFBM)*2.03;///////////////2
//noise3
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.1250*noise;/////////////////3
float den = max(0.0, cloudShape - f_FBM);
//if(den <= 0.0) return 0.0;
if(den > 0.0){
p.y += Time*15.2;
//den= max(0.0, den-0.2*fbm(p*0.05));
//calculate FBM
pFBM = p * 0.05 * FPerlin;
//noise1
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM = 0.5000*noise; pFBM = mul(m,pFBM)*2.02;/////////////1
//noise2
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.2500*noise; pFBM = mul(m,pFBM)*2.03;///////////////2
//noise3
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.1250*noise;/////////////////3
den = max(0.0, den - f_FBM);
density = largeWeather*0.2*min(1.0, 5.0*den);
}else density = 0.0;
}else density = 0.0;
//color = float3(density, density, density);
if(density > 0.0){
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float zMaxl = 600;
float stepL = zMaxl/LightStep;
float lighRayDen = 0.0;
float3 pL = p;
pL += sun_direction*stepL;//*hash(dot(p, vec3(12.256, 2.646, 6.356)) + iTime);
for(int j = 0; j < LightStep; j++){
//////sample ///////
pL += sun_direction*float(j)*stepL;
atmosHeight = length(p - center) - EarthRadius;
cloudHeightIn = clamp((atmosHeight-CloudStart)/(CloudHeight), 0.0, 1.0);
p.z += Time*10.3;
largeWeather = clamp((WeatherTex.SampleLevel(WeatherTexSampler, -0.0000005*p.yx, 0.0).x-0.03)*10.0, 0.0, 2.0);
p.x += Time*8.3;
weather = largeWeather*max(0.0, WeatherTex.SampleLevel(WeatherTexSampler, 0.000002*p.yx, 0.0).x - 0.01) /0.72;
//weather *= smoothstep(0.0, 0.5, cloudHeightIn) * smoothstep(1.0, 0.5, cloudHeightIn);
cloudShape = pow(weather, 0.3+1.5*smoothstep(0.2, 0.5, cloudHeightIn));
//if(cloudShape <= 0.0) return 0.0;
if(cloudShape > 0.0){
p.x += Time*12.3;
//calculate fbm return FBM1
float3x3 m = {0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64};
float f_FBM;
float3 pFBM = p * 0.01 * FPerlin; //float den= max(0.0, cloudShape-0.7*fbm(p*.01));
//noise1
float3 pN = floor(pFBM);
float3 fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
float2 uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
float2 rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
float noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM = 0.5000*noise; pFBM = mul(m,pFBM)*2.02;/////////////1
//noise2
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.2500*noise; pFBM = mul(m,pFBM)*2.03;///////////////2
//noise3
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.1250*noise;/////////////////3
float den = max(0.0, cloudShape - f_FBM);
//if(den <= 0.0) return 0.0;
if(den > 0.0){
p.y += Time*15.2;
//den= max(0.0, den-0.2*fbm(p*0.05));
//calculate FBM
pFBM = p * 0.05 * FPerlin;
//noise1
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM = 0.5000*noise; pFBM = mul(m,pFBM)*2.02;/////////////1
//noise2
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.2500*noise; pFBM = mul(m,pFBM)*2.03;///////////////2
//noise3
pN = floor(pFBM);
fN = frac(pFBM);
fN = fN*fN*(3.0-2.0*fN);
uvN = (pN.xy+float2(37.0,17.0)*pN.z) + fN.xy;
rgN = NoiseTex.SampleLevel(NoiseTexSampler, (uvN+0.5)/256.0, 0.0).yx;
noise = lerp(rgN.x, rgN.y, fN.z);
f_FBM += 0.1250*noise;/////////////////3
den = max(0.0, den - f_FBM);
density = largeWeather*0.2*min(1.0, 5.0*den);
}else density = 0.0;
}else density = 0.0;
lighRayDen += density;
}
float scatterAmount = lerp(0.008, 1.0, smoothstep(0.96, 0.0, mu));
float beersLaw = exp(-stepL*lighRayDen)+0.5*scatterAmount*exp(-0.1*stepL*lighRayDen)+scatterAmount*0.4*exp(-0.02*stepL*lighRayDen);
float intensity = beersLaw * phaseFunction * lerp(0.05 + 1.5*pow(min(1.0, density*8.5), 0.3+5.5*cloudHeightIn), 1.0, clamp(lighRayDen*0.4, 0.0, 1.0));
//end
float3 ambient = (0.5 + 0.6*cloudHeightIn)*float3(0.2, 0.5, 1.0)*6.5 + float3(0.8,0.8,0.8) * max(0.0, 1.0-2.0*cloudHeightIn);
float3 radiance = ambient + SunPower*intensity;
radiance*=density;
color += T*(radiance - radiance*exp(-density*stepS)) / density;
T *= exp(-density*stepS);
if(T <= 0.05) break;
}
p += dir*stepS;
}
//float fogPhase = henyey;//0.5*HenyeyGreenstein(mu, 0.7)+0.5*HenyeyGreenstein(mu, -0.6);
test = float4(lerp(0.1*LOW_SCATTER*SunPower+10.0*float3(0.55, 0.8, 1.0), color, exp(-0.0003*fogDistance)), 1.0) * 0.05;
}
//return float4(color,1);
return float4(color, 1);