Fixed lighting bug that occurred when multiple solar systems were rendered. Solar system centric light source positions from the wrong solar system were being used, resulting in completely incorrect illumination.

ver1_5_1
Chris Laurel 2004-11-11 09:41:51 +00:00
parent 252182a102
commit 384e3ca8b7
2 changed files with 20 additions and 3 deletions

View File

@ -1117,6 +1117,7 @@ setupLightSources(const vector<const Star*>& nearStars,
{
Vec3d v = ((*iter)->getPosition(t) - center) *
astro::microLightYearsToKilometers(1.0);
Renderer::LightSource ls;
ls.position = Point3d(v.x, v.y, v.z);
ls.luminosity = (*iter)->getLuminosity();
@ -1217,6 +1218,8 @@ void Renderer::render(const Observer& observer,
{
nearStars.clear();
universe.getNearStars(observer.getPosition(), 1.0f, nearStars);
unsigned int solarSysIndex = 0;
for (vector<const Star*>::const_iterator iter = nearStars.begin();
iter != nearStars.end(); iter++)
{
@ -1224,12 +1227,15 @@ void Renderer::render(const Observer& observer,
SolarSystem* solarSystem = universe.getSolarSystem(sun);
if (solarSystem != NULL)
{
setupLightSources(nearStars, *sun, now, lightSources);
setupLightSources(nearStars, *sun, now,
lightSourceLists[solarSysIndex]);
renderPlanetarySystem(*sun,
*solarSystem->getPlanets(),
observer,
now,
solarSysIndex,
(labelMode & (BodyLabelMask)) != 0);
solarSysIndex++;
}
}
starTex->bind();
@ -1707,6 +1713,7 @@ void Renderer::render(const Observer& observer,
renderList[i].appMag,
now,
observer.getOrientation(),
lightSourceLists[renderList[i].solarSysIndex],
nearPlaneDistance, farPlaneDistance);
}
}
@ -5387,6 +5394,7 @@ void Renderer::renderPlanet(Body& body,
float appMag,
double now,
Quatf orientation,
const vector<LightSource>& lightSources,
float nearPlaneDistance,
float farPlaneDistance)
{
@ -5928,6 +5936,7 @@ void Renderer::renderPlanetarySystem(const Star& sun,
const PlanetarySystem& solSystem,
const Observer& observer,
double now,
unsigned int solarSysIndex,
bool showLabels)
{
Point3f starPos = sun.getPosition();
@ -5949,6 +5958,8 @@ void Renderer::renderPlanetarySystem(const Star& sun,
// relative to the observer.
Vec3d posd = bodyPos - observerPos;
vector<LightSource>& lightSources = lightSourceLists[solarSysIndex];
// Compute the apparent magnitude; instead of summing the reflected
// light from all nearby stars, we just consider the one with the
// highest apparent brightness.
@ -5979,6 +5990,7 @@ void Renderer::renderPlanetarySystem(const Star& sun,
rle.radius = body->getRadius();
rle.discSizeInPixels = discSize;
rle.appMag = appMag;
rle.solarSysIndex = solarSysIndex;
renderList.insert(renderList.end(), rle);
}
@ -6000,6 +6012,7 @@ void Renderer::renderPlanetarySystem(const Star& sun,
rle.radius = radius;
rle.discSizeInPixels = discSize;
rle.appMag = appMag;
rle.solarSysIndex = solarSysIndex;
renderList.insert(renderList.end(), rle);
}
}
@ -6065,7 +6078,7 @@ void Renderer::renderPlanetarySystem(const Star& sun,
if (satellites != NULL)
{
renderPlanetarySystem(sun, *satellites, observer,
now, showLabels);
now, solarSysIndex, showLabels);
}
}
}

View File

@ -34,9 +34,11 @@ struct RenderListEntry
float appMag;
bool isCometTail;
int depthBucket;
int solarSysIndex;
};
static const unsigned int MaxLights = 8;
static const unsigned int MaxSolarSystems = 16;
struct DirectionalLight
{
@ -310,6 +312,7 @@ class Renderer
const PlanetarySystem& solSystem,
const Observer& observer,
double now,
unsigned int solarSysIndex,
bool showLabels = false);
void renderObject(Point3f pos,
@ -327,6 +330,7 @@ class Renderer
float appMag,
double now,
Quatf orientation,
const vector<LightSource>& lightSources,
float, float);
void renderStar(const Star& star,
@ -435,7 +439,7 @@ class Renderer
std::vector<EclipseShadow> eclipseShadows[MaxLights];
std::vector<const Star*> nearStars;
std::vector<LightSource> lightSources;
std::vector<LightSource> lightSourceLists[MaxSolarSystems];
std::vector<StarLabel> labelledStars;