forked from jdupuy/whitecaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skymap.glsl
50 lines (37 loc) · 1.1 KB
/
skymap.glsl
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
uniform vec3 sunDir;
varying vec2 U; // sky map texture coordinates (world space stereographic projection)
#ifdef _VERTEX_
void main() {
gl_Position = gl_Vertex;
U = gl_Vertex.xy * 1.1;
}
#endif
#ifdef _FRAGMENT_
void main() {
vec2 u = U;
float l = dot(u, u);
vec4 result = vec4(0.0);
if (l <= 1.02) {
if (l > 1.0) {
u = u / l;
l = 1.0 / l;
}
// inverse stereographic projection,
// from skymap coordinates to world space directions
vec3 r = vec3(2.0 * u, 1.0 - l) / (1.0 + l);
vec3 extinction;
result.rgb = skyRadiance(earthPos, r, sunDir, extinction);
#ifdef CLOUDS
vec4 cloudL = cloudColorV(vec3(0.0), r, sunDir);
result.rgb = cloudL.rgb * cloudL.a + result.rgb * (1.0 - cloudL.a);
#endif
} else {
// below horizon:
// use average fresnel * average sky radiance
// to simulate multiple reflections on waves
const float avgFresnel = 0.17;
result.rgb = skyIrradiance(earthPos.z, sunDir.z) / M_PI * avgFresnel;
}
gl_FragColor = result;
}
#endif