Skip to content

Commit dc6ef79

Browse files
committed
Limb darkening for stars
1 parent 7ac19f9 commit dc6ef79

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

src/celengine/render.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,9 @@ static void renderSphereUnlit(const RenderInfo& ri,
18311831
textures.try_push_back(ri.overlayTex);
18321832
}
18331833

1834+
if (ri.isStar)
1835+
shadprop.lightModel = ShaderProperties::StarModel;
1836+
18341837
// Get a shader for the current rendering configuration
18351838
auto* prog = r->getShaderManager().getShader(shadprop);
18361839
if (prog == nullptr)
@@ -1841,6 +1844,8 @@ static void renderSphereUnlit(const RenderInfo& ri,
18411844
prog->textureOffset = 0.0f;
18421845
prog->ambientColor = ri.color.toVector3();
18431846
prog->opacity = 1.0f;
1847+
if (ri.isStar)
1848+
prog->eyePosition = ri.eyePos_obj;
18441849

18451850
Renderer::PipelineState ps;
18461851
ps.depthMask = true;
@@ -2391,6 +2396,7 @@ void Renderer::renderObject(const Vector3f& pos,
23912396
}
23922397
else
23932398
{
2399+
ri.isStar = obj.isStar;
23942400
renderSphereUnlit(ri, viewFrustum, planetMVP, this);
23952401
}
23962402
}
@@ -3017,6 +3023,7 @@ void Renderer::renderStar(const Star& star,
30173023
surface.appearanceFlags |= Surface::ApplyBaseTexture;
30183024
surface.appearanceFlags |= Surface::Emissive;
30193025

3026+
rp.isStar = true;
30203027
rp.surface = &surface;
30213028
rp.rings = nullptr;
30223029
rp.radius = star.getRadius();

src/celengine/render.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,15 @@ class Renderer
460460
Surface* surface{ nullptr };
461461
const Atmosphere* atmosphere{ nullptr };
462462
RingSystem* rings{ nullptr };
463+
LightingState::EclipseShadowVector* eclipseShadows{ nullptr };
464+
465+
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
466+
Eigen::Vector3f semiAxes{ Eigen::Vector3f::Ones() };
463467
float radius{ 1.0f };
464468
float geometryScale{ 1.0f };
465-
Eigen::Vector3f semiAxes{ Eigen::Vector3f::Ones() };
469+
466470
ResourceHandle geometry{ InvalidResource };
467-
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
468-
LightingState::EclipseShadowVector* eclipseShadows;
471+
bool isStar{ false };
469472
};
470473

471474
struct DepthBufferPartition

src/celengine/renderinfo.h

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

2222
struct RenderInfo
2323
{
24-
Color color{ 1.0f, 1.0f, 1.0f };
24+
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
25+
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,11 @@ ShaderManager::buildFragmentShader(const ShaderProperties& props)
25332533
source += "gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + scatterColor;\n";
25342534
}
25352535

2536+
if (props.lightModel == ShaderProperties::StarModel)
2537+
{
2538+
source += "gl_FragColor.rgb = gl_FragColor.rgb - vec3(1.0 - NV) * vec3(0.56, 0.61, 0.72);\n";
2539+
}
2540+
25362541
source += "}\n";
25372542

25382543
DumpFSSource(source);

src/celengine/shadermanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ShaderProperties
8989
EmissiveModel = 0x0100,
9090
ParticleModel = 0x0200,
9191
UnlitModel = 0x0400,
92+
StarModel = 0x0800,
9293
};
9394

9495
enum

0 commit comments

Comments
 (0)