-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsky_frag.glsl
More file actions
70 lines (52 loc) · 2.16 KB
/
Copy pathsky_frag.glsl
File metadata and controls
70 lines (52 loc) · 2.16 KB
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
#version 330 core
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
in vec4 v_position;
in vec2 v_uv0;
in vec3 v_colorYxy;
in vec3 v_skyVec;
uniform sampler2D texSky180;
uniform sampler2D texSky90;
uniform float colorExp;
uniform vec3 zenith;
uniform vec4 skySettings;
#define sunExponent skySettings.x
#define moonExponent skySettings.y
#define skyDaylightBrightness skySettings.z
#define skyNightBrightness skySettings.w
// 0.0 at new moon, 1.0 at full moon - see CelestialSystem#getMoonPhase(). Modulates the moon
// highlight's peak brightness so the "moon" dims and brightens through its cycle (#94).
uniform float moonPhaseIntensity = 1.0;
const vec4 eyePos = vec4(0.0, 0.0, 0.0, 1.0);
#define HIGHLIGHT_BLEND_START 0.1
#define SUN_HIGHLIGHT_INTENSITY_FACTOR 1.0
layout(location = 0) out vec4 outColor;
void main () {
vec3 v = normalize(v_position.xyz);
vec3 l = normalize(sunVec.xyz);
float lDotV = dot(l, v);
float negLDotV = dot(-l, v);
float sunHighlight = 0.0;
if (lDotV >= 0.0 && l.y >= 0.0) {
sunHighlight = pow(lDotV, sunExponent) * SUN_HIGHLIGHT_INTENSITY_FACTOR;
}
if (l.y < HIGHLIGHT_BLEND_START && l.y >= 0.0) {
sunHighlight *= 1.0 - (HIGHLIGHT_BLEND_START - l.y) / HIGHLIGHT_BLEND_START;
}
float moonHighlight = 0.0;
if (negLDotV >= 0.0 && -l.y >= 0.0) {
moonHighlight = pow(negLDotV, moonExponent) * moonPhaseIntensity;
}
if (-l.y < HIGHLIGHT_BLEND_START && -l.y >= 0.0) {
moonHighlight *= 1.0 - (HIGHLIGHT_BLEND_START + l.y) / HIGHLIGHT_BLEND_START;
}
vec4 skyColor = vec4(0.0, 0.0, 0.0, 1.0);
/* PROCEDURAL SKY COLOR */
vec4 cloudsColor = texture(texSky180, v_uv0.xy);
vec4 cloudsColorNight = texture(texSky90, v_uv0.xy);
/* DAY AND NIGHT TEXTURES */
skyColor.rgb = skyDaylightBrightness * daylight * cloudsColor.rgb + (1.0 - daylight) * skyNightBrightness * cloudsColorNight.rgb;
skyColor.rgb *= mix(convertColorYxy(v_colorYxy, colorExp).rgb, vec3(1.0, 1.0, 1.0), 1.0 - daylight);
skyColor.rgb += vec3((1.0 - cloudsColor.r) * sunHighlight + (1.0 - cloudsColor.r) * moonHighlight);
outColor.rgba = skyColor.rgba;
}