Simplified setHazeColor.

This commit is contained in:
Nissim Hadar 2017-10-13 12:49:38 -07:00
parent c76229934c
commit 6697d7c93a
2 changed files with 23 additions and 29 deletions

View file

@ -31,32 +31,19 @@ enum HazeModes {
// For color modulated mode, the colour values are used as range values, which are then converted to range factors
// This is separate for each colour.
// The colour value is converted from [0.0 .. 1.0] to [5.0 .. 3000.0]
const float OFFSET = 5.0f;
const float BIAS = (3000.0f - 5.0f) / (1.0f - 0.0f);
void Haze::setHazeColor(const glm::vec3 hazeColor) {
auto& params = _hazeParametersBuffer.get<Parameters>();
if (params.hazeColor.r != hazeColor.r) {
_hazeParametersBuffer.edit<Parameters>().hazeColor.r = hazeColor.r;
if (params.hazeColor != hazeColor) {
_hazeParametersBuffer.edit<Parameters>().hazeColor = hazeColor;
float range = hazeColor.r * 2995.0f + 5.0f;
float factor = convertHazeRangeToHazeRangeFactor(range);
_hazeParametersBuffer.edit<Parameters>().colorModulationFactor.r = factor;
glm::vec3 range = hazeColor * BIAS + OFFSET;
glm::vec3 factor = convertHazeRangeToHazeRangeFactor(range);
_hazeParametersBuffer.edit<Parameters>().colorModulationFactor = factor;
}
if (params.hazeColor.g != hazeColor.g) {
_hazeParametersBuffer.edit<Parameters>().hazeColor.g = hazeColor.g;
float range = hazeColor.g * 2995.0f + 5.0f;
float factor = convertHazeRangeToHazeRangeFactor(range);
_hazeParametersBuffer.edit<Parameters>().colorModulationFactor.g = factor;
}
if (params.hazeColor.b != hazeColor.b) {
_hazeParametersBuffer.edit<Parameters>().hazeColor.b = hazeColor.b;
float range = hazeColor.b * 2995.0f + 5.0f;
float factor = convertHazeRangeToHazeRangeFactor(range);
_hazeParametersBuffer.edit<Parameters>().colorModulationFactor.b = factor;
}
}
}
void Haze::setHazeEnableLightBlend(const bool isHazeEnableLightBlend) {
auto& params = _hazeParametersBuffer.get<Parameters>();

View file

@ -22,25 +22,32 @@ namespace model {
// f = exp(-d * b)
// ln(f) = -d * b
// b = -ln(f)/d
inline float convertHazeRangeToHazeRangeFactor(const float hazeRange_m) { return (float)-log(p_005) / hazeRange_m; }
inline float convertHazeAltitudeToHazeAltitudeFactor(const float hazeAltitude_m) {
return (float)-log(p_005) / hazeAltitude_m;
inline glm::vec3 convertHazeRangeToHazeRangeFactor(const glm::vec3 hazeRange_m) {
return glm::vec3(
(float)(-log(p_005) / hazeRange_m.x),
(float)(-log(p_005) / hazeRange_m.y),
(float)(-log(p_005) / hazeRange_m.z));
}
// Derivation (s is th proportion of sun blend, a is the angle at which the blend is 50%, solve for m = 0.5
inline float convertHazeRangeToHazeRangeFactor(const float hazeRange_m) { return (float)(-log(p_005) / hazeRange_m); }
inline float convertHazeAltitudeToHazeAltitudeFactor(const float hazeAltitude_m) {
return (float)(-log(p_005) / hazeAltitude_m);
}
// Derivation (s is the proportion of sun blend, a is the angle at which the blend is 50%, solve for m = 0.5
// s = dot(lookAngle, sunAngle) = cos(a)
// m = pow(s, p)
// log(m) = p * log(s)
// p = log(m) / log(s)
inline float convertDirectionalLightAngleToPower(const float directionalLightAngle) {
return log(0.5) / log(cos(RADIANS_PER_DEGREE * directionalLightAngle));
return (float)(log(0.5) / log(cos(RADIANS_PER_DEGREE * directionalLightAngle)));
}
const glm::vec3 initialHazeColor{ 0.5, 0.6, 0.7 };
const glm::vec3 initialHazeColor{ 0.5f, 0.6f, 0.7f };
const float initialDirectionalLightAngle_degs{ 30.0f };
const glm::vec3 initialDirectionalLightColor{ 1.0, 0.9, 0.7 };
const glm::vec3 initialDirectionalLightColor{ 1.0f, 0.9f, 0.7f };
const float initialHazeBaseReference{ 0.0f };
// Haze range is defined here as the range the visibility is reduced by 95%