Skip to content

Commit e673af1

Browse files
committed
rayleigh: scale density from tropopause height
1 parent ec99e79 commit e673af1

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

data/shaders/opengl/basesphere_uniforms.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ layout(std140) uniform BaseSphereData {
3030

3131
// Eclipse data
3232
Eclipse eclipse;
33+
vec2 tropoHeight; // height for (R, M) in km, pressure is 0.1 atm
3334
};
3435

3536
// NOTE: you must include attributes.glsl first!

src/BaseSphere.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ struct BaseSphereDataBlock {
3232
alignas(16) vector3f srad;
3333
alignas(16) vector3f lrad;
3434
alignas(16) vector3f sdivlrad;
35+
36+
alignas(16) vector2f tropoHeight;
3537
};
36-
static_assert(sizeof(BaseSphereDataBlock) == 192, "");
38+
static_assert(sizeof(BaseSphereDataBlock) == 208, "");
3739

3840
std::unique_ptr<Graphics::Drawables::Sphere3D> BaseSphere::m_atmos;
3941

@@ -123,6 +125,8 @@ void BaseSphere::SetMaterialParameters(const matrix4x4d &trans, const float radi
123125
++j;
124126
}
125127

128+
matData.tropoHeight = ap.tropoHeight;
129+
126130
// FIXME: these two should share the same buffer data instead of making two separate allocs
127131
m_surfaceMaterial->SetBufferDynamic(s_baseSphereData, &matData);
128132
m_surfaceMaterial->SetPushConstant(s_numShadows, int(shadows.size()));

src/galaxy/AtmosphereParameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct AtmosphereParameters {
1414
vector3f rayleighCoefficients;
1515
vector3f mieCoefficients;
1616
vector2f scaleHeight;
17+
vector2f tropoHeight;
1718
};
1819

1920
#endif // ATMOSPHEREPARAMETERS_H_INCLUDED

src/galaxy/SystemBody.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ double SystemBody::GetAtmPressure(double altitude) const
209209
return atmosPressure;
210210
} else {
211211
// above tropopause
212-
const double tropopauseTemp = surfaceTemperature_T0 - lapseRate_L * m_tropopause;
212+
const double tropopauseTemp = GetAtmAverageTemp(m_tropopause);
213213
return 0.1 * exp((-surfaceGravity_g * gasMolarMass * (altitude - m_tropopause)) / (GAS_CONSTANT_R * tropopauseTemp));
214214
}
215215
}
@@ -371,7 +371,7 @@ AtmosphereParameters SystemBody::CalcAtmosphereParams() const
371371
const double massPlanet_in_kg = (m_mass.ToDouble() * EARTH_MASS);
372372
const double g = G * massPlanet_in_kg / (radiusPlanet_in_m * radiusPlanet_in_m);
373373

374-
double T = static_cast<double>(m_averageTemp);
374+
double T = static_cast<double>(GetAtmAverageTemp(m_tropopause));
375375

376376
// XXX hack to avoid issues with sysgen giving 0 temps
377377
// temporary as part of sysgen needs to be rewritten before the proper fix can be used
@@ -391,9 +391,11 @@ AtmosphereParameters SystemBody::CalcAtmosphereParams() const
391391

392392
const float radiusPlanet_in_km = radiusPlanet_in_m / 1000;
393393
const float atmosHeight_in_km = radiusPlanet_in_km * (params.atmosRadius - 1);
394+
const float tropopause_in_km = static_cast<float>(m_tropopause / 1000);
394395
params.rayleighCoefficients = GetCoefficients(radiusPlanet_in_km, atmosHeight_in_km, atmosScaleHeight);
395396
params.mieCoefficients = GetCoefficients(radiusPlanet_in_km, atmosHeight_in_km, atmosScaleHeight / 6.66); // 7994 / 1200 = 6.61
396397
params.scaleHeight = vector2f(atmosScaleHeight, atmosScaleHeight / 6.66);
398+
params.tropoHeight = vector2f(tropopause_in_km, tropopause_in_km / 6.66);
397399

398400
return params;
399401
}

0 commit comments

Comments
 (0)