91 lines
2.8 KiB
GLSL
91 lines
2.8 KiB
GLSL
#include "/Lib/Settings.glsl"
|
|
#include "/Lib/Utilities.glsl"
|
|
// MinecraftPT — Lighting Constants
|
|
// Per-frame lighting values computed inline (no SSBO dependency).
|
|
// These are cheap functions of the sun angle and camera position; computed
|
|
// per-pass instead of via a shared buffer for maximum loader compatibility.
|
|
|
|
#ifndef LIGHTING_CONSTANTS_GLSL
|
|
#define LIGHTING_CONSTANTS_GLSL
|
|
|
|
#include "/Lib/BasicFunctions/PrecomputedAtmosphere.glsl"
|
|
|
|
// Sun direction in world space (matches the shadow camera direction)
|
|
vec3 GetSunDirWorld(){
|
|
#ifndef DIMENSION_NETHER
|
|
#ifndef DIMENSION_END
|
|
return normalize(shadowModelViewInverse2);
|
|
#else
|
|
return normalize(shadowModelViewInverse2) * fsign(0.5 - sunAngle);
|
|
#endif
|
|
#else
|
|
return normalize(shadowModelViewInverse2) * fsign(0.5 - sunAngle);
|
|
#endif
|
|
}
|
|
|
|
// Atmosphere camera position (scaled Earth radius + camera altitude)
|
|
vec3 GetAtmoCamera(){
|
|
return vec3(0.0, max(cameraPosition.y, 63.0) * 0.001 + atmosphereModel_bottom_radius, 0.0);
|
|
}
|
|
|
|
// Sun irradiance (direct light color/intensity)
|
|
vec3 GetSunIrradiance(){
|
|
vec3 sunDir = GetSunDirWorld();
|
|
vec3 moon, sunSky, moonSky;
|
|
return GetSunAndSkyIrradiance(GetAtmoCamera(), sunDir, -sunDir, moon, sunSky, moonSky);
|
|
}
|
|
|
|
vec3 GetMoonIrradiance(){
|
|
vec3 sunDir = GetSunDirWorld();
|
|
vec3 moon, sunSky, moonSky;
|
|
GetSunAndSkyIrradiance(GetAtmoCamera(), sunDir, -sunDir, moon, sunSky, moonSky);
|
|
return moon;
|
|
}
|
|
|
|
vec3 GetCelestialIrradiance(){
|
|
return GetSunIrradiance() + GetMoonIrradiance();
|
|
}
|
|
|
|
vec3 GetAtmoIrradiance(){
|
|
vec3 sunDir = GetSunDirWorld();
|
|
vec3 moon, sunSky, moonSky;
|
|
GetSunAndSkyIrradiance(GetAtmoCamera(), sunDir, -sunDir, moon, sunSky, moonSky);
|
|
return sunSky + moonSky;
|
|
}
|
|
|
|
// Cloud-altitude irradiances
|
|
vec3 GetCloudSunIrradiance(){
|
|
vec3 sunDir = GetSunDirWorld();
|
|
vec3 atmoCamera = vec3(0.0, mix(CLOUD_CLEAR_ALTITUDE, CLOUD_RAIN_ALTITUDE, wetness) * 0.001 + atmosphereModel_bottom_radius, 0.0);
|
|
vec3 moon, sunSky, moonSky;
|
|
return GetSunAndSkyIrradiance(atmoCamera, sunDir, -sunDir, moon, sunSky, moonSky);
|
|
}
|
|
|
|
vec3 GetCloudAtmoIrradiance(){
|
|
vec3 sunDir = GetSunDirWorld();
|
|
vec3 atmoCamera = vec3(0.0, mix(CLOUD_CLEAR_ALTITUDE, CLOUD_RAIN_ALTITUDE, wetness) * 0.001 + atmosphereModel_bottom_radius, 0.0);
|
|
vec3 moon, sunSky, moonSky;
|
|
GetSunAndSkyIrradiance(atmoCamera, sunDir, -sunDir, moon, sunSky, moonSky);
|
|
return sunSky + moonSky;
|
|
}
|
|
|
|
// Moon/sun phase for fog time factor
|
|
vec2 GetFogTimeFactor(){
|
|
vec3 sunDir = GetSunDirWorld();
|
|
float timeNoon = pow(1.0 - (clamp(sunDir.y, 0.2, 0.99) - 0.2) / 0.8, 6.0);
|
|
float moonlightStrength = curve(saturate(sunDir.y * -5.0));
|
|
return vec2(timeNoon, moonlightStrength);
|
|
}
|
|
|
|
// Dimension-aware irradiance override
|
|
vec3 GetDimensionAmbient(){
|
|
#ifdef DIMENSION_NETHER
|
|
return vec3(0.08, 0.02, 0.01) * NETHER_BRIGHTNESS;
|
|
#elif defined DIMENSION_END
|
|
return vec3(0.02, 0.02, 0.04);
|
|
#else
|
|
return GetAtmoIrradiance();
|
|
#endif
|
|
}
|
|
|
|
#endif |