atmosphere: make haze night-cycle aware
This commit is contained in:
1 parent
7f733b8efe
commit
b9abacbdda
1 file changed
+21
-5
Vendored
+21
-5
@@ -2777,6 +2777,16 @@ function airlightColor(altRad, moonAlt, moonFrac) {
|
|||||||
// (0 = pure physics, 1 = the theme colour), and gain / nightGain scale the
|
// (0 = pure physics, 1 = the theme colour), and gain / nightGain scale the
|
||||||
// day and night exposure. Configured per theme in window.THEMES[theme].
|
// day and night exposure. Configured per theme in window.THEMES[theme].
|
||||||
// .lighting; a theme without that block is pure physics.
|
// .lighting; a theme without that block is pure physics.
|
||||||
|
function hazeColorDynamic(base, air, amb, star, moonI) {
|
||||||
|
var target = 0.07 + 1.15 * Math.max(0, amb) + 0.55 * Math.max(0, star)
|
||||||
|
+ 0.25 * Math.max(0, moonI);
|
||||||
|
target = Math.max(0.06, Math.min(0.72, target));
|
||||||
|
var col = mixRgb(base, air, 0.55);
|
||||||
|
var lum = 0.2126 * col[0] + 0.7152 * col[1] + 0.0722 * col[2];
|
||||||
|
var scale = target / Math.max(0.02, lum);
|
||||||
|
scale = Math.max(0.05, Math.min(2.5, scale));
|
||||||
|
return [col[0] * scale, col[1] * scale, col[2] * scale];
|
||||||
|
}
|
||||||
function themeColor(v, fallback) {
|
function themeColor(v, fallback) {
|
||||||
if (typeof v === 'number') return hex(v);
|
if (typeof v === 'number') return hex(v);
|
||||||
if (typeof v === 'string') {
|
if (typeof v === 'string') {
|
||||||
@@ -5812,6 +5822,12 @@ window.clouds3dRender = function(target) {
|
|||||||
_moonI *= _exp;
|
_moonI *= _exp;
|
||||||
_amb *= _exp;
|
_amb *= _exp;
|
||||||
}
|
}
|
||||||
|
var _terrainHazeColor = hazeColorDynamic(TERRAIN_HAZE_COLOR, _air, _amb, _star, _moonI);
|
||||||
|
var _frontHazeColor = hazeColorDynamic(FRONT_HAZE_COLOR, _air, _amb, _star, _moonI);
|
||||||
|
var _airHazeColor = hazeColorDynamic(AIR_HAZE_COLOR, _air, _amb, _star, _moonI);
|
||||||
|
var _hazeMaxScale = 0.35 + 1.1 * Math.max(0, _amb) + 0.45 * Math.max(0, _star)
|
||||||
|
+ 0.25 * Math.max(0, _moonI);
|
||||||
|
_hazeMaxScale = Math.max(0.25, Math.min(1.0, _hazeMaxScale));
|
||||||
gl.uniform3f(s.uAirColor, _air[0], _air[1], _air[2]);
|
gl.uniform3f(s.uAirColor, _air[0], _air[1], _air[2]);
|
||||||
gl.uniform3f(s.uRayleighBeta, TAU_RAYLEIGH[0], TAU_RAYLEIGH[1], TAU_RAYLEIGH[2]);
|
gl.uniform3f(s.uRayleighBeta, TAU_RAYLEIGH[0], TAU_RAYLEIGH[1], TAU_RAYLEIGH[2]);
|
||||||
gl.uniform1f(s.uSunAirMass, airMass(Math.max(sunAlt, 0.0)));
|
gl.uniform1f(s.uSunAirMass, airMass(Math.max(sunAlt, 0.0)));
|
||||||
@@ -5822,14 +5838,14 @@ window.clouds3dRender = function(target) {
|
|||||||
gl.uniform1f(s.uAirHazeScaleHeightUnits, AIR_HAZE_SCALE_HEIGHT_UNITS);
|
gl.uniform1f(s.uAirHazeScaleHeightUnits, AIR_HAZE_SCALE_HEIGHT_UNITS);
|
||||||
gl.uniform1f(s.uAirHazeGain, AIR_HAZE_GAIN);
|
gl.uniform1f(s.uAirHazeGain, AIR_HAZE_GAIN);
|
||||||
gl.uniform1f(s.uAirHazeMaxAlpha, AIR_HAZE_MAX_ALPHA);
|
gl.uniform1f(s.uAirHazeMaxAlpha, AIR_HAZE_MAX_ALPHA);
|
||||||
gl.uniform3f(s.uAirHazeColor, AIR_HAZE_COLOR[0], AIR_HAZE_COLOR[1], AIR_HAZE_COLOR[2]);
|
gl.uniform3f(s.uAirHazeColor, _airHazeColor[0], _airHazeColor[1], _airHazeColor[2]);
|
||||||
gl.uniform1i(s.uTerrainDistTex, 7);
|
gl.uniform1i(s.uTerrainDistTex, 7);
|
||||||
gl.uniform1f(s.uFrontHazeOn, FRONT_HAZE_ON ? 1.0 : 0.0);
|
gl.uniform1f(s.uFrontHazeOn, FRONT_HAZE_ON ? 1.0 : 0.0);
|
||||||
gl.uniform1f(s.uFrontHazeDensity, FRONT_HAZE_DENSITY);
|
gl.uniform1f(s.uFrontHazeDensity, FRONT_HAZE_DENSITY);
|
||||||
gl.uniform1f(s.uFrontHazeScaleHeightUnits, FRONT_HAZE_SCALE_HEIGHT_UNITS);
|
gl.uniform1f(s.uFrontHazeScaleHeightUnits, FRONT_HAZE_SCALE_HEIGHT_UNITS);
|
||||||
gl.uniform1f(s.uFrontHazeGain, FRONT_HAZE_GAIN);
|
gl.uniform1f(s.uFrontHazeGain, FRONT_HAZE_GAIN);
|
||||||
gl.uniform1f(s.uFrontHazeMaxAlpha, FRONT_HAZE_MAX_ALPHA);
|
gl.uniform1f(s.uFrontHazeMaxAlpha, FRONT_HAZE_MAX_ALPHA * _hazeMaxScale);
|
||||||
gl.uniform3f(s.uFrontHazeColor, FRONT_HAZE_COLOR[0], FRONT_HAZE_COLOR[1], FRONT_HAZE_COLOR[2]);
|
gl.uniform3f(s.uFrontHazeColor, _frontHazeColor[0], _frontHazeColor[1], _frontHazeColor[2]);
|
||||||
gl.uniform1f(s.uFarPlane, 100.0);
|
gl.uniform1f(s.uFarPlane, 100.0);
|
||||||
gl.uniform3f(s.uSunColor, _beam[0], _beam[1], _beam[2]);
|
gl.uniform3f(s.uSunColor, _beam[0], _beam[1], _beam[2]);
|
||||||
gl.uniform1f(s.uSunInt, _beamL);
|
gl.uniform1f(s.uSunInt, _beamL);
|
||||||
@@ -6125,8 +6141,8 @@ window.clouds3dRender = function(target) {
|
|||||||
gl.uniform1f(terr.uHazeDensity, TERRAIN_HAZE_DENSITY);
|
gl.uniform1f(terr.uHazeDensity, TERRAIN_HAZE_DENSITY);
|
||||||
gl.uniform1f(terr.uHazeScaleHeightUnits, TERRAIN_HAZE_SCALE_HEIGHT_UNITS);
|
gl.uniform1f(terr.uHazeScaleHeightUnits, TERRAIN_HAZE_SCALE_HEIGHT_UNITS);
|
||||||
gl.uniform1f(terr.uHazeGain, TERRAIN_HAZE_GAIN);
|
gl.uniform1f(terr.uHazeGain, TERRAIN_HAZE_GAIN);
|
||||||
gl.uniform1f(terr.uHazeMaxAlpha, TERRAIN_HAZE_MAX_ALPHA);
|
gl.uniform1f(terr.uHazeMaxAlpha, TERRAIN_HAZE_MAX_ALPHA * _hazeMaxScale);
|
||||||
gl.uniform3f(terr.uHazeColor, TERRAIN_HAZE_COLOR[0], TERRAIN_HAZE_COLOR[1], TERRAIN_HAZE_COLOR[2]);
|
gl.uniform3f(terr.uHazeColor, _terrainHazeColor[0], _terrainHazeColor[1], _terrainHazeColor[2]);
|
||||||
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, terr.vbo);
|
gl.bindBuffer(gl.ARRAY_BUFFER, terr.vbo);
|
||||||
var STRIDE = 11 * 4; // 11 floats per vertex
|
var STRIDE = 11 * 4; // 11 floats per vertex
|
||||||
|
|||||||
Reference in new issue
Block a user