Added safety offset on lighting
This avoids shadow algorithm to hit the surface it is currently checking
This commit is contained in:
parent
cafa9b4c74
commit
e81487ae08
5 changed files with 32 additions and 4 deletions
|
@ -110,6 +110,7 @@ Color GodRaysSampler::getRawLight(const Vector3 &location, bool filtered) const
|
|||
if (lighting)
|
||||
{
|
||||
LightStatus status(lighting, location, *camera_location, filtered);
|
||||
status.setSafetyOffset(0.0); // Not a hard surface, safety offset not needed
|
||||
lighting->fillStatus(status, location);
|
||||
return status.getSum();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
LightStatus::LightStatus(LightingManager *manager, const Vector3 &location, const Vector3 &eye, bool filtered)
|
||||
{
|
||||
this->safety_offset = -0.0000001;
|
||||
this->max_power = 0.0;
|
||||
this->manager = manager;
|
||||
this->location = location;
|
||||
|
@ -25,7 +26,7 @@ void LightStatus::pushComponent(LightComponent component)
|
|||
return;
|
||||
}
|
||||
|
||||
if (manager->alterLight(component, location))
|
||||
if (manager->alterLight(component, location.add(component.direction.scale(safety_offset))))
|
||||
{
|
||||
if (power > max_power)
|
||||
{
|
||||
|
@ -64,3 +65,8 @@ Color LightStatus::getSum() const
|
|||
|
||||
return final;
|
||||
}
|
||||
|
||||
void LightStatus::setSafetyOffset(double safety_offset)
|
||||
{
|
||||
this->safety_offset = -safety_offset;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,17 @@ public:
|
|||
*/
|
||||
Color getSum() const;
|
||||
|
||||
/**
|
||||
* Set the safety offset for this status.
|
||||
*
|
||||
* The offset is used to not hit the surface we are currently working on immediately.
|
||||
* It adds a small vector toward the light at the start of shadow casting.
|
||||
* This number should remain very small to not produce precision errors.
|
||||
*/
|
||||
void setSafetyOffset(double safety_offset);
|
||||
|
||||
private:
|
||||
double safety_offset;
|
||||
double max_power;
|
||||
LightingManager* manager;
|
||||
Vector3 location;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
LightingManager::LightingManager()
|
||||
{
|
||||
specularity = true;
|
||||
filtering = true;
|
||||
}
|
||||
|
||||
int LightingManager::getStaticLightsCount() const
|
||||
|
@ -81,7 +82,7 @@ void LightingManager::unregisterFilter(LightFilter *filter)
|
|||
|
||||
bool LightingManager::alterLight(LightComponent &component, const Vector3 &location)
|
||||
{
|
||||
if (component.altered)
|
||||
if (filtering and component.altered)
|
||||
{
|
||||
for (auto filter:filters)
|
||||
{
|
||||
|
@ -105,6 +106,11 @@ void LightingManager::setSpecularity(bool enabled)
|
|||
specularity = enabled;
|
||||
}
|
||||
|
||||
void LightingManager::setFiltering(bool enabled)
|
||||
{
|
||||
filtering = enabled;
|
||||
}
|
||||
|
||||
Color LightingManager::applyFinalComponent(const LightComponent &component, const Vector3 &eye, const Vector3 &location, const Vector3 &normal, const SurfaceMaterial &material)
|
||||
{
|
||||
Color result, light_color;
|
||||
|
|
|
@ -77,6 +77,11 @@ public:
|
|||
*/
|
||||
void setSpecularity(bool enabled);
|
||||
|
||||
/**
|
||||
* Enable or disable the filtering (shadows).
|
||||
*/
|
||||
void setFiltering(bool enabled);
|
||||
|
||||
/**
|
||||
* Apply a final component on a surface material.
|
||||
*/
|
||||
|
@ -93,11 +98,11 @@ public:
|
|||
Color apply(const Vector3 &eye, const Vector3 &location, const Vector3 &normal, const SurfaceMaterial &material);
|
||||
|
||||
private:
|
||||
int specularity;
|
||||
bool specularity;
|
||||
bool filtering;
|
||||
std::vector<LightComponent> static_lights;
|
||||
std::vector<LightFilter *> filters;
|
||||
std::vector<LightSource *> sources;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue