Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions assets/shaders/sky_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ uniform vec4 skySettings;
#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
#define MOON_HIGHLIGHT_INTENSITY_FACTOR 1.0

layout(location = 0) out vec4 outColor;

Expand All @@ -45,7 +48,7 @@ void main () {

float moonHighlight = 0.0;
if (negLDotV >= 0.0 && -l.y >= 0.0) {
moonHighlight = pow(negLDotV, moonExponent) * MOON_HIGHLIGHT_INTENSITY_FACTOR;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
skyMaterial.setFloat("colorExp", backdropProvider.getColorExp(), true);
skyMaterial.setFloat4("skySettings", sunExponent, moonExponent, skyDaylightBrightness, skyNightBrightness, true);

// Moon phase in [0, 1): 0/1 is new moon, 0.5 is full moon. Fold it into a triangle wave so
// the highlight peaks at full moon and fades to nothing at new moon, rather than jumping. #94
float moonPhase = backdropProvider.getMoonPhase();

Check warning on line 171 in src/main/java/org/terasology/corerendering/rendering/dag/nodes/BackdropNode.java

View check run for this annotation

Terasology Jenkins.io / Java Compiler

ERROR: cannot find symbol
float moonPhaseIntensity = 1.0f - Math.abs(moonPhase * 2.0f - 1.0f);
skyMaterial.setFloat("moonPhaseIntensity", moonPhaseIntensity, true);

Camera camera = worldRenderer.getActiveCamera();
skyMaterial.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
skyMaterial.setMatrix4("modelViewMatrix", camera.getNormViewMatrix());
Expand Down