Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limb darkening #2047

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions src/celengine/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,9 @@ static void renderSphereUnlit(const RenderInfo& ri,
textures.push_back(ri.overlayTex);
}

if (ri.isStar)
shadprop.lightModel = LightingModel::StarModel;

// Get a shader for the current rendering configuration
auto* prog = r->getShaderManager().getShader(shadprop);
if (prog == nullptr)
Expand All @@ -1838,6 +1841,8 @@ static void renderSphereUnlit(const RenderInfo& ri,
prog->textureOffset = 0.0f;
prog->ambientColor = ri.color.toVector3();
prog->opacity = 1.0f;
if (ri.isStar)
prog->eyePosition = ri.eyePos_obj;

Renderer::PipelineState ps;
ps.depthMask = true;
Expand Down Expand Up @@ -2388,6 +2393,7 @@ void Renderer::renderObject(const Vector3f& pos,
}
else
{
ri.isStar = obj.isStar;
renderSphereUnlit(ri, viewFrustum, planetMVP, this);
}
}
Expand Down Expand Up @@ -3014,30 +3020,13 @@ void Renderer::renderStar(const Star& star,
surface.appearanceFlags |= Surface::ApplyBaseTexture;
surface.appearanceFlags |= Surface::Emissive;

rp.isStar = true;
rp.surface = &surface;
rp.rings = nullptr;
rp.radius = star.getRadius();
rp.semiAxes = star.getEllipsoidSemiAxes();
rp.geometry = star.getGeometry();

Atmosphere atmosphere;

// Use atmosphere effect to give stars a fuzzy fringe
if (star.hasCorona() && rp.geometry == InvalidResource)
{
Color atmColor(color.red() * 0.5f, color.green() * 0.5f, color.blue() * 0.5f);
atmosphere.height = radius * CoronaHeight;
atmosphere.lowerColor = atmColor;
atmosphere.upperColor = atmColor;
atmosphere.skyColor = atmColor;

rp.atmosphere = &atmosphere;
}
else
{
rp.atmosphere = nullptr;
}

rp.atmosphere = nullptr;
rp.orientation = star.getRotationModel()->orientationAtTime(observer.getTime()).cast<float>();

renderObject(pos, distance, observer,
Expand Down
9 changes: 6 additions & 3 deletions src/celengine/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,15 @@ class Renderer
Surface* surface{ nullptr };
const Atmosphere* atmosphere{ nullptr };
RingSystem* rings{ nullptr };
LightingState::EclipseShadowVector* eclipseShadows{ nullptr };

Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reodering is to decrease the struct size

Eigen::Vector3f semiAxes{ Eigen::Vector3f::Ones() };
float radius{ 1.0f };
float geometryScale{ 1.0f };
Eigen::Vector3f semiAxes{ Eigen::Vector3f::Ones() };

ResourceHandle geometry{ InvalidResource };
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
LightingState::EclipseShadowVector* eclipseShadows;
bool isStar{ false };
};

struct DepthBufferPartition
Expand Down
7 changes: 4 additions & 3 deletions src/celengine/renderinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class Texture;

struct RenderInfo
{
Color color{ 1.0f, 1.0f, 1.0f };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reodering is to decrease the struct size

Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };

Texture* baseTex{ nullptr };
Texture* bumpTex{ nullptr };
Texture* nightTex{ nullptr };
Texture* glossTex{ nullptr };
Texture* overlayTex{ nullptr };
Color color{ 1.0f, 1.0f, 1.0f };
Color specularColor{ 0.0f, 0.0f, 0.0f };
float specularPower{ 0.0f };
Eigen::Vector3f sunDir_eye{ Eigen::Vector3f::UnitZ() };
Expand All @@ -36,10 +38,9 @@ struct RenderInfo
Color sunColor{ 1.0f, 1.0f, 1.0f };
Color ambientColor{ 0.0f, 0.0f, 0.0f };
float lunarLambert{ 0.0f };
Eigen::Quaternionf orientation{ Eigen::Quaternionf::Identity() };
float pixWidth{ 1.0f };
float pointScale{ 1.0f };
bool isStar{ false };
};

extern LODSphereMesh* g_lodSphere;

8 changes: 6 additions & 2 deletions src/celengine/shadermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,11 @@ ShaderManager::buildFragmentShader(const ShaderProperties& props)
source += "gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + scatterColor;\n";
}

if (props.lightModel == LightingModel::StarModel)
{
source += "gl_FragColor.rgb = gl_FragColor.rgb - vec3(1.0 - NV) * vec3(0.56, 0.61, 0.72);\n";
}

source += "}\n";

DumpFSSource(source);
Expand Down Expand Up @@ -2319,14 +2324,13 @@ ShaderManager::buildAtmosphereFragmentShader(const ShaderProperties& props)

// Sum the contributions from each light source
source += "vec3 color = vec3(0.0);\n";
source += "vec3 V = normalize(eyeDir);\n";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eyeDir is already normalized since we implemented per-pixel shading.


// Only do scattering calculations for the primary light source
// TODO: Eventually handle multiple light sources, and removed the 'min'
// from the line below.
for (unsigned i = 0; i < std::min(static_cast<unsigned int>(props.nLights), 1u); i++)
{
source += " float cosTheta = dot(V, " + LightProperty(i, "direction") + ");\n";
source += " float cosTheta = dot(eyeDir, " + LightProperty(i, "direction") + ");\n";
source += ScatteringPhaseFunctions(props);

// TODO: Consider premultiplying by invScatterCoeffSum
Expand Down
1 change: 1 addition & 0 deletions src/celengine/shadermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum class LightingModel : std::uint16_t
EmissiveModel = 0x0100,
ParticleModel = 0x0200,
UnlitModel = 0x0400,
StarModel = 0x0800,
};

ENUM_CLASS_BITWISE_OPS(LightingModel);
Expand Down
Loading