diff --git a/src/celengine/render.cpp b/src/celengine/render.cpp index 6c73d993f6..5b260a2cc5 100644 --- a/src/celengine/render.cpp +++ b/src/celengine/render.cpp @@ -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) @@ -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; @@ -2388,6 +2393,7 @@ void Renderer::renderObject(const Vector3f& pos, } else { + ri.isStar = obj.isStar; renderSphereUnlit(ri, viewFrustum, planetMVP, this); } } @@ -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(); renderObject(pos, distance, observer, diff --git a/src/celengine/render.h b/src/celengine/render.h index e5b7e9dfe1..c75a6ea8a5 100644 --- a/src/celengine/render.h +++ b/src/celengine/render.h @@ -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() }; + 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 diff --git a/src/celengine/renderinfo.h b/src/celengine/renderinfo.h index b45be8fb7b..ea91fda292 100644 --- a/src/celengine/renderinfo.h +++ b/src/celengine/renderinfo.h @@ -21,12 +21,14 @@ class Texture; struct RenderInfo { - Color color{ 1.0f, 1.0f, 1.0f }; + 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() }; @@ -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; - diff --git a/src/celengine/shadermanager.cpp b/src/celengine/shadermanager.cpp index 870e1e4403..385f4b5e80 100644 --- a/src/celengine/shadermanager.cpp +++ b/src/celengine/shadermanager.cpp @@ -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); @@ -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"; // 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(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 diff --git a/src/celengine/shadermanager.h b/src/celengine/shadermanager.h index 2b9ecd9b93..34e8baa406 100644 --- a/src/celengine/shadermanager.h +++ b/src/celengine/shadermanager.h @@ -62,6 +62,7 @@ enum class LightingModel : std::uint16_t EmissiveModel = 0x0100, ParticleModel = 0x0200, UnlitModel = 0x0400, + StarModel = 0x0800, }; ENUM_CLASS_BITWISE_OPS(LightingModel);