Skip to content

Commit be55064

Browse files
committed
Merge the limb-darkening branch
1 parent cbd67e6 commit be55064

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

src/celengine/render.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,8 @@ static void renderSphereUnlit(const RenderInfo& ri,
16451645
shadprop.texUsage |= TexUsage::OverlayTexture;
16461646
textures.push_back(ri.overlayTex);
16471647
}
1648+
if (ri.isStar)
1649+
shadprop.lightModel = ShaderProperties::StarModel;
16481650

16491651
// Get a shader for the current rendering configuration
16501652
auto* prog = r->getShaderManager().getShader(shadprop);
@@ -1656,6 +1658,8 @@ static void renderSphereUnlit(const RenderInfo& ri,
16561658
prog->textureOffset = 0.0f;
16571659
prog->ambientColor = ri.color.toVector3();
16581660
prog->opacity = 1.0f;
1661+
if (ri.isStar)
1662+
prog->eyePosition = ri.eyePos_obj;
16591663

16601664
Renderer::PipelineState ps;
16611665
ps.depthMask = true;
@@ -2206,6 +2210,7 @@ void Renderer::renderObject(const Vector3f& pos,
22062210
}
22072211
else
22082212
{
2213+
ri.isStar = obj.isStar;
22092214
renderSphereUnlit(ri, viewFrustum, planetMVP, this);
22102215
}
22112216
}
@@ -2832,30 +2837,13 @@ void Renderer::renderStar(const Star& star,
28322837
surface.appearanceFlags |= Surface::ApplyBaseTexture;
28332838
surface.appearanceFlags |= Surface::Emissive;
28342839

2840+
rp.isStar = true;
28352841
rp.surface = &surface;
28362842
rp.rings = nullptr;
28372843
rp.radius = star.getRadius();
28382844
rp.semiAxes = star.getEllipsoidSemiAxes();
28392845
rp.geometry = star.getGeometry();
2840-
2841-
Atmosphere atmosphere;
2842-
2843-
// Use atmosphere effect to give stars a fuzzy fringe
2844-
if (star.hasCorona() && rp.geometry == InvalidResource)
2845-
{
2846-
Color atmColor(color.red() * 0.5f, color.green() * 0.5f, color.blue() * 0.5f);
2847-
atmosphere.height = radius * CoronaHeight;
2848-
atmosphere.lowerColor = atmColor;
2849-
atmosphere.upperColor = atmColor;
2850-
atmosphere.skyColor = atmColor;
2851-
2852-
rp.atmosphere = &atmosphere;
2853-
}
2854-
else
2855-
{
2856-
rp.atmosphere = nullptr;
2857-
}
2858-
2846+
rp.atmosphere = nullptr;
28592847
rp.orientation = star.getRotationModel()->orientationAtTime(observer.getTime()).cast<float>();
28602848

28612849
renderObject(pos, distance, observer,

src/celengine/render.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,15 @@ class Renderer
458458
Surface* surface{ nullptr };
459459
const Atmosphere* atmosphere{ nullptr };
460460
RingSystem* rings{ nullptr };
461+
LightingState::EclipseShadowVector* eclipseShadows{ nullptr };
462+
463+
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
464+
Eigen::Vector3f semiAxes{ Eigen::Vector3f::Ones() };
461465
float radius{ 1.0f };
462466
float geometryScale{ 1.0f };
463-
Eigen::Vector3f semiAxes{ Eigen::Vector3f::Ones() };
467+
464468
ResourceHandle geometry{ InvalidResource };
465-
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
466-
LightingState::EclipseShadowVector* eclipseShadows;
469+
bool isStar{ false };
467470
};
468471

469472
struct DepthBufferPartition

src/celengine/renderinfo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ class Texture;
2121

2222
struct RenderInfo
2323
{
24+
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
2425
Color color{ 1.0f, 1.0f, 1.0f };
2526
Texture* baseTex{ nullptr };
2627
Texture* bumpTex{ nullptr };
2728
Texture* nightTex{ nullptr };
2829
Texture* glossTex{ nullptr };
2930
Texture* overlayTex{ nullptr };
31+
Color color{ 1.0f, 1.0f, 1.0f };
3032
Color specularColor{ 0.0f, 0.0f, 0.0f };
3133
float specularPower{ 0.0f };
3234
Eigen::Vector3f sunDir_eye{ Eigen::Vector3f::UnitZ() };
@@ -36,10 +38,9 @@ struct RenderInfo
3638
Color sunColor{ 1.0f, 1.0f, 1.0f };
3739
Color ambientColor{ 0.0f, 0.0f, 0.0f };
3840
float lunarLambert{ 0.0f };
39-
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
4041
float pixWidth{ 1.0f };
4142
float pointScale{ 1.0f };
43+
bool isStar{ false };
4244
};
4345

4446
extern LODSphereMesh* g_lodSphere;
45-

src/celengine/shadermanager.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,12 @@ ShaderManager::buildFragmentShader(const ShaderProperties& props)
20932093
source += "gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + scatterColor;\n";
20942094
}
20952095

2096+
// Include the effect of limb darkening.
2097+
if (props.lightModel == ShaderProperties::StarModel)
2098+
{
2099+
source += "gl_FragColor.rgb = gl_FragColor.rgb - vec3(1.0 - NV) * vec3(0.56, 0.61, 0.72);\n";
2100+
}
2101+
20962102
source += "}\n";
20972103

20982104
DumpFSSource(source);
@@ -2311,7 +2317,6 @@ ShaderManager::buildAtmosphereFragmentShader(const ShaderProperties& props)
23112317
source += "vec3 nposition = normalize(position);\n";
23122318
source += "vec3 N = normalize(normal);\n";
23132319
source += "vec3 eyeDir = normalize(eyePosition - nposition);\n";
2314-
source += "float NV = dot(N, eyeDir);\n";
23152320

23162321
source += DeclareLocal("NL", Shader_Float);
23172322
source += DeclareLocal("scatterEx", Shader_Vector3);
@@ -2326,7 +2331,7 @@ ShaderManager::buildAtmosphereFragmentShader(const ShaderProperties& props)
23262331
// from the line below.
23272332
for (unsigned i = 0; i < std::min(static_cast<unsigned int>(props.nLights), 1u); i++)
23282333
{
2329-
source += " float cosTheta = dot(V, " + LightProperty(i, "direction") + ");\n";
2334+
source += " float cosTheta = dot(eyeDir, " + LightProperty(i, "direction") + ");\n";
23302335
source += ScatteringPhaseFunctions(props);
23312336

23322337
// TODO: Consider premultiplying by invScatterCoeffSum

src/celengine/shadermanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ enum class LightingModel : std::uint16_t
6262
EmissiveModel = 0x0100,
6363
ParticleModel = 0x0200,
6464
UnlitModel = 0x0400,
65+
StarModel = 0x0800,
6566
};
6667

6768
ENUM_CLASS_BITWISE_OPS(LightingModel);

0 commit comments

Comments
 (0)