2015-09-29 20:31:25 +00:00
|
|
|
#include "GodRaysResult.h"
|
|
|
|
|
|
|
|
GodRaysResult::GodRaysResult(double inside_length, double full_length):
|
|
|
|
inside_length(inside_length), full_length(full_length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-29 23:08:15 +00:00
|
|
|
Color GodRaysResult::apply(const Color &raw, const Color &atmosphered, const GodRaysParams ¶ms)
|
2015-09-29 20:31:25 +00:00
|
|
|
{
|
|
|
|
if (inside_length == 0.0)
|
|
|
|
{
|
|
|
|
return raw;
|
|
|
|
}
|
|
|
|
else if (inside_length < full_length)
|
|
|
|
{
|
|
|
|
double diff = full_length - inside_length;
|
2015-09-29 23:08:15 +00:00
|
|
|
double factor = 1.0 - params.penetration * diff;
|
|
|
|
double minimum = params.resistance;
|
|
|
|
double complement = 1.0 - minimum;
|
|
|
|
if (factor < minimum)
|
2015-09-29 20:31:25 +00:00
|
|
|
{
|
2015-09-29 23:08:15 +00:00
|
|
|
factor = minimum;
|
2015-09-29 20:31:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-29 23:08:15 +00:00
|
|
|
factor = pow((factor - minimum) / complement, params.boost) * complement + minimum;
|
2015-09-29 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Color(raw.r + (atmosphered.r - raw.r) * factor,
|
|
|
|
raw.g + (atmosphered.g - raw.g) * factor,
|
|
|
|
raw.b + (atmosphered.b - raw.b) * factor,
|
|
|
|
atmosphered.a);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return atmosphered;
|
|
|
|
}
|
|
|
|
}
|