2015-09-29 20:31:25 +00:00
|
|
|
#include "GodRaysResult.h"
|
|
|
|
|
2015-11-18 18:37:00 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
GodRaysResult::GodRaysResult(double inside_length, double full_length)
|
|
|
|
: inside_length(inside_length), full_length(full_length) {
|
2015-09-29 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
Color GodRaysResult::apply(const Color &raw, const Color &atmosphered, const GodRaysParams ¶ms) {
|
|
|
|
if (inside_length == 0.0) {
|
2015-09-29 20:31:25 +00:00
|
|
|
return raw;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else if (inside_length < full_length) {
|
2015-09-29 20:31:25 +00:00
|
|
|
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;
|
2015-11-09 21:30:46 +00:00
|
|
|
if (factor < minimum) {
|
2015-09-29 23:08:15 +00:00
|
|
|
factor = minimum;
|
2015-11-09 21:30:46 +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
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +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 {
|
2015-09-29 20:31:25 +00:00
|
|
|
return atmosphered;
|
|
|
|
}
|
|
|
|
}
|