From 5fc68cae0d5d24f0745546a1d55397484e68c89d Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Mon, 30 Oct 2017 11:51:19 -0700 Subject: [PATCH] Converted Haze initialization values to static. --- libraries/entities/CMakeLists.txt | 2 +- libraries/entities/src/HazePropertyGroup.h | 20 +++---- libraries/entities/src/ZoneEntityItem.h | 2 +- libraries/model/src/model/Haze.cpp | 25 +++++++- libraries/model/src/model/Haze.h | 55 ++++++++++++++++- libraries/model/src/model/HazeInit.h | 69 ---------------------- libraries/render-utils/src/DrawHaze.h | 52 ++++++++-------- libraries/render-utils/src/HazeStage.h | 26 ++++---- 8 files changed, 128 insertions(+), 123 deletions(-) delete mode 100644 libraries/model/src/model/HazeInit.h diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index c23740654e..146aecf1f6 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -1,4 +1,4 @@ set(TARGET_NAME entities) setup_hifi_library(Network Script) include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") -link_hifi_libraries(shared networking octree avatars model) +link_hifi_libraries(shared networking octree avatars model gpu) diff --git a/libraries/entities/src/HazePropertyGroup.h b/libraries/entities/src/HazePropertyGroup.h index 1cbaa24f2a..1585f35c45 100644 --- a/libraries/entities/src/HazePropertyGroup.h +++ b/libraries/entities/src/HazePropertyGroup.h @@ -21,7 +21,7 @@ #include "PropertyGroup.h" #include "EntityItemPropertiesMacros.h" -#include +#include class EntityItemProperties; class EncodeBitstreamParams; @@ -77,24 +77,24 @@ public: bool& somethingChanged) override; // Range only parameters - DEFINE_PROPERTY(PROP_HAZE_RANGE, HazeRange, hazeRange, float, model::initialHazeRange_m); - DEFINE_PROPERTY_REF(PROP_HAZE_COLOR, HazeColor, hazeColor, xColor, model::initialHazeColorXcolor); - DEFINE_PROPERTY_REF(PROP_HAZE_GLARE_COLOR, HazeGlareColor, hazeGlareColor, xColor, model::initialHazeGlareColorXcolor); + DEFINE_PROPERTY(PROP_HAZE_RANGE, HazeRange, hazeRange, float, model::Haze::initialHazeRange_m); + DEFINE_PROPERTY_REF(PROP_HAZE_COLOR, HazeColor, hazeColor, xColor, model::Haze::initialHazeColorXcolor); + DEFINE_PROPERTY_REF(PROP_HAZE_GLARE_COLOR, HazeGlareColor, hazeGlareColor, xColor, model::Haze::initialHazeGlareColorXcolor); DEFINE_PROPERTY(PROP_HAZE_ENABLE_GLARE, HazeEnableGlare, hazeEnableGlare, bool, false); - DEFINE_PROPERTY_REF(PROP_HAZE_GLARE_ANGLE, HazeGlareAngle, hazeGlareAngle, float, model::initialGlareAngle_degs); + DEFINE_PROPERTY_REF(PROP_HAZE_GLARE_ANGLE, HazeGlareAngle, hazeGlareAngle, float, model::Haze::initialGlareAngle_degs); // Altitude parameters DEFINE_PROPERTY(PROP_HAZE_ALTITUDE_EFFECT, HazeAltitudeEffect, hazeAltitudeEffect, bool, false); - DEFINE_PROPERTY_REF(PROP_HAZE_CEILING, HazeCeiling, hazeCeiling, float, model::initialHazeBaseReference_m + model::initialHazeHeight_m); - DEFINE_PROPERTY_REF(PROP_HAZE_BASE_REF, HazeBaseRef, hazeBaseRef, float, model::initialHazeBaseReference_m); + DEFINE_PROPERTY_REF(PROP_HAZE_CEILING, HazeCeiling, hazeCeiling, float, model::Haze::initialHazeBaseReference_m + model::Haze::initialHazeHeight_m); + DEFINE_PROPERTY_REF(PROP_HAZE_BASE_REF, HazeBaseRef, hazeBaseRef, float, model::Haze::initialHazeBaseReference_m); // Background (skybox) blend value - DEFINE_PROPERTY_REF(PROP_HAZE_BACKGROUND_BLEND, HazeBackgroundBlend, hazeBackgroundBlend, float, model::initialHazeBackgroundBlend); + DEFINE_PROPERTY_REF(PROP_HAZE_BACKGROUND_BLEND, HazeBackgroundBlend, hazeBackgroundBlend, float, model::Haze::initialHazeBackgroundBlend); // hazeDirectional light attenuation DEFINE_PROPERTY(PROP_HAZE_ATTENUATE_KEYLIGHT, HazeAttenuateKeyLight, hazeAttenuateKeyLight, bool, false); - DEFINE_PROPERTY_REF(PROP_HAZE_KEYLIGHT_RANGE, HazeKeyLightRange, hazeKeyLightRange, float, model::initialHazeKeyLightRange_m); - DEFINE_PROPERTY_REF(PROP_HAZE_KEYLIGHT_ALTITUDE, HazeKeyLightAltitude, hazeKeyLightAltitude, float, model::initialHazeKeyLightAltitude_m); + DEFINE_PROPERTY_REF(PROP_HAZE_KEYLIGHT_RANGE, HazeKeyLightRange, hazeKeyLightRange, float, model::Haze::initialHazeKeyLightRange_m); + DEFINE_PROPERTY_REF(PROP_HAZE_KEYLIGHT_ALTITUDE, HazeKeyLightAltitude, hazeKeyLightAltitude, float, model::Haze::initialHazeKeyLightAltitude_m); }; #endif // hifi_HazePropertyGroup_h diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index ba5f3b3dee..3f78591745 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -19,7 +19,7 @@ #include "HazePropertyGroup.h" #include "StagePropertyGroup.h" #include -#include +#include class ZoneEntityItem : public EntityItem { public: diff --git a/libraries/model/src/model/Haze.cpp b/libraries/model/src/model/Haze.cpp index 1c9b989fd1..92042364c2 100644 --- a/libraries/model/src/model/Haze.cpp +++ b/libraries/model/src/model/Haze.cpp @@ -9,12 +9,35 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include -#include #include "Haze.h" using namespace model; +const float Haze::initialHazeRange_m{ 1000.0f }; +const float Haze::initialHazeHeight_m{ 200.0f }; + +const float Haze::initialHazeKeyLightRange_m{ 1000.0f }; +const float Haze::initialHazeKeyLightAltitude_m{ 200.0f }; + +const float Haze::initialHazeBackgroundBlend{ 0.0f }; + +const glm::vec3 Haze::initialColorModulationFactor{ + convertHazeRangeToHazeRangeFactor(initialHazeRange_m), + convertHazeRangeToHazeRangeFactor(initialHazeRange_m), + convertHazeRangeToHazeRangeFactor(initialHazeRange_m) +}; + +const glm::vec3 Haze::initialHazeColor{ 0.5f, 0.6f, 0.7f }; // Bluish +const xColor Haze::initialHazeColorXcolor{ 128, 154, 179 }; + +const float Haze::initialGlareAngle_degs{ 20.0f }; + +const glm::vec3 Haze::initialHazeGlareColor{ 1.0f, 0.9f, 0.7f }; +const xColor Haze::initialHazeGlareColorXcolor{ 255, 229, 179 }; + +const float Haze::initialHazeBaseReference_m{ 0.0f }; + Haze::Haze() { Parameters parameters; _hazeParametersBuffer = gpu::BufferView(std::make_shared(sizeof(Parameters), (const gpu::Byte*) ¶meters)); diff --git a/libraries/model/src/model/Haze.h b/libraries/model/src/model/Haze.h index bed82c80f9..c361fcde8c 100644 --- a/libraries/model/src/model/Haze.h +++ b/libraries/model/src/model/Haze.h @@ -12,17 +12,68 @@ #define hifi_model_Haze_h #include +#include + #include "Transform.h" #include "NumericalConstants.h" -#include "HazeInit.h" - namespace model { + const float LOG_P_005 = logf(0.05f); + const float LOG_P_05 = logf(0.5f); + + // Derivation (d is distance, b is haze coefficient, f is attenuation, solve for f = 0.05 + // f = exp(-d * b) + // ln(f) = -d * b + // b = -ln(f)/d + inline glm::vec3 convertHazeRangeToHazeRangeFactor(const glm::vec3 hazeRange_m) { + return glm::vec3( + -LOG_P_005 / hazeRange_m.x, + -LOG_P_005 / hazeRange_m.y, + -LOG_P_005 / hazeRange_m.z); + } + + // limit range and altitude to no less than 1.0 metres + inline float convertHazeRangeToHazeRangeFactor(const float hazeRange_m) { return -LOG_P_005 / glm::max(hazeRange_m, 1.0f); } + + inline float convertHazeAltitudeToHazeAltitudeFactor(const float hazeHeight_m) { return -LOG_P_005 / glm::max(hazeHeight_m, 1.0f); } + + // 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) + // limit to 0.1 degrees + inline float convertGlareAngleToPower(const float hazeGlareAngle) { + const float GLARE_ANGLE_LIMIT = 0.1f; + return LOG_P_05 / logf(cosf(RADIANS_PER_DEGREE * glm::max(GLARE_ANGLE_LIMIT, hazeGlareAngle))); + } + // Haze range is defined here as the range the visibility is reduced by 95% // Haze altitude is defined here as the altitude (above 0) that the haze is reduced by 95% class Haze { public: + // Initial values + static const float initialHazeRange_m; + static const float initialHazeHeight_m; + + static const float initialHazeKeyLightRange_m; + static const float initialHazeKeyLightAltitude_m; + + static const float initialHazeBackgroundBlend; + + static const glm::vec3 initialColorModulationFactor; + + static const glm::vec3 initialHazeColor; + static const xColor initialHazeColorXcolor; + + static const float initialGlareAngle_degs; + + static const glm::vec3 initialHazeGlareColor; + static const xColor initialHazeGlareColorXcolor; + + static const float initialHazeBaseReference_m; + using UniformBufferView = gpu::BufferView; Haze(); diff --git a/libraries/model/src/model/HazeInit.h b/libraries/model/src/model/HazeInit.h deleted file mode 100644 index 218a79fc1d..0000000000 --- a/libraries/model/src/model/HazeInit.h +++ /dev/null @@ -1,69 +0,0 @@ -// -// MakeHaze.h -// libraries/model/src/model -// -// Created by Nissim Hadar on 10/26/2017. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -#ifndef hifi_model_HazeInit_h -#define hifi_model_HazeInit_h - -namespace model { - const float LOG_P_005 = logf(0.05f); - const float LOG_P_05 = logf(0.5f); - - // Derivation (d is distance, b is haze coefficient, f is attenuation, solve for f = 0.05 - // f = exp(-d * b) - // ln(f) = -d * b - // b = -ln(f)/d - inline glm::vec3 convertHazeRangeToHazeRangeFactor(const glm::vec3 hazeRange_m) { - return glm::vec3( - -LOG_P_005 / hazeRange_m.x, - -LOG_P_005 / hazeRange_m.y, - -LOG_P_005 / hazeRange_m.z); - } - - // limit range and altitude to no less than 1.0 metres - inline float convertHazeRangeToHazeRangeFactor(const float hazeRange_m) { return -LOG_P_005 / glm::max(hazeRange_m, 1.0f); } - - inline float convertHazeAltitudeToHazeAltitudeFactor(const float hazeHeight_m) { return -LOG_P_005 / glm::max(hazeHeight_m, 1.0f); } - - // 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) - // limit to 0.1 degrees - inline float convertGlareAngleToPower(const float hazeGlareAngle) { - const float GLARE_ANGLE_LIMIT = 0.1f; - return LOG_P_05 / logf(cosf(RADIANS_PER_DEGREE * glm::max(GLARE_ANGLE_LIMIT, hazeGlareAngle))); - } - - const float initialHazeRange_m{ 1000.0f }; - const float initialHazeHeight_m{ 200.0f }; - - const float initialHazeKeyLightRange_m{ 1000.0f }; - const float initialHazeKeyLightAltitude_m{ 200.0f }; - - const float initialHazeBackgroundBlend{ 0.0f }; - - const glm::vec3 initialColorModulationFactor{ - convertHazeRangeToHazeRangeFactor(initialHazeRange_m), - convertHazeRangeToHazeRangeFactor(initialHazeRange_m), - convertHazeRangeToHazeRangeFactor(initialHazeRange_m) - }; - - const glm::vec3 initialHazeColor{ 0.5f, 0.6f, 0.7f }; // Bluish - const xColor initialHazeColorXcolor{ 128, 154, 179 }; - - const float initialGlareAngle_degs{ 20.0f }; - - const glm::vec3 initialHazeGlareColor{ 1.0f, 0.9f, 0.7f }; - const xColor initialHazeGlareColorXcolor{ 255, 229, 179 }; - - const float initialHazeBaseReference_m{ 0.0f }; -} -#endif // hifi_model_HazeInit_h diff --git a/libraries/render-utils/src/DrawHaze.h b/libraries/render-utils/src/DrawHaze.h index e7a3f2c636..786c39133b 100644 --- a/libraries/render-utils/src/DrawHaze.h +++ b/libraries/render-utils/src/DrawHaze.h @@ -56,15 +56,15 @@ class MakeHazeConfig : public render::Job::Config { public: MakeHazeConfig() : render::Job::Config() {} - float hazeColorR{ model::initialHazeColor.r }; - float hazeColorG{ model::initialHazeColor.g }; - float hazeColorB{ model::initialHazeColor.b }; - float hazeGlareAngle_degs{ model::initialGlareAngle_degs }; + float hazeColorR{ model::Haze::initialHazeColor.r }; + float hazeColorG{ model::Haze::initialHazeColor.g }; + float hazeColorB{ model::Haze::initialHazeColor.b }; + float hazeGlareAngle_degs{ model::Haze::initialGlareAngle_degs }; - float hazeGlareColorR{ model::initialHazeGlareColor.r }; - float hazeGlareColorG{ model::initialHazeGlareColor.g }; - float hazeGlareColorB{ model::initialHazeGlareColor.b }; - float hazeBaseReference_m{ model::initialHazeBaseReference_m }; + float hazeGlareColorR{ model::Haze::initialHazeGlareColor.r }; + float hazeGlareColorG{ model::Haze::initialHazeGlareColor.g }; + float hazeGlareColorB{ model::Haze::initialHazeGlareColor.b }; + float hazeBaseReference_m{ model::Haze::initialHazeBaseReference_m }; bool isHazeActive{ false }; bool isAltitudeBased{ false }; @@ -72,13 +72,13 @@ public: bool isModulateColorActive{ false }; bool isHazeEnableGlare{ false }; - float hazeRange_m{ model::initialHazeRange_m }; - float hazeHeight_m{ model::initialHazeHeight_m }; + float hazeRange_m{ model::Haze::initialHazeRange_m }; + float hazeHeight_m{ model::Haze::initialHazeHeight_m }; - float hazeKeyLightRange_m{ model::initialHazeKeyLightRange_m }; - float hazeKeyLightAltitude_m{ model::initialHazeKeyLightAltitude_m }; + float hazeKeyLightRange_m{ model::Haze::initialHazeKeyLightRange_m }; + float hazeKeyLightAltitude_m{ model::Haze::initialHazeKeyLightAltitude_m }; - float hazeBackgroundBlend{ model::initialHazeBackgroundBlend }; + float hazeBackgroundBlend{ model::Haze::initialHazeBackgroundBlend }; public slots: void setHazeColorR(const float value) { hazeColorR = value; emit dirty(); } @@ -128,15 +128,15 @@ public: HazeConfig() : render::Job::Config(true) {} // attributes - float hazeColorR{ model::initialHazeColor.r }; - float hazeColorG{ model::initialHazeColor.g }; - float hazeColorB{ model::initialHazeColor.b }; - float hazeGlareAngle_degs{ model::initialGlareAngle_degs }; + float hazeColorR{ model::Haze::initialHazeColor.r }; + float hazeColorG{ model::Haze::initialHazeColor.g }; + float hazeColorB{ model::Haze::initialHazeColor.b }; + float hazeGlareAngle_degs{ model::Haze::initialGlareAngle_degs }; - float hazeGlareColorR{ model::initialHazeGlareColor.r }; - float hazeGlareColorG{ model::initialHazeGlareColor.g }; - float hazeGlareColorB{ model::initialHazeGlareColor.b }; - float hazeBaseReference_m{ model::initialHazeBaseReference_m }; + float hazeGlareColorR{ model::Haze::initialHazeGlareColor.r }; + float hazeGlareColorG{ model::Haze::initialHazeGlareColor.g }; + float hazeGlareColorB{ model::Haze::initialHazeGlareColor.b }; + float hazeBaseReference_m{ model::Haze::initialHazeBaseReference_m }; bool isHazeActive{ false }; // Setting this to true will set haze to on bool isAltitudeBased{ false }; @@ -144,13 +144,13 @@ public: bool isModulateColorActive{ false }; bool isHazeEnableGlare{ false }; - float hazeRange_m{ model::initialHazeRange_m }; - float hazeHeight_m{ model::initialHazeHeight_m }; + float hazeRange_m{ model::Haze::initialHazeRange_m }; + float hazeHeight_m{ model::Haze::initialHazeHeight_m }; - float hazeKeyLightRange_m{ model::initialHazeKeyLightRange_m }; - float hazeKeyLightAltitude_m{ model::initialHazeKeyLightAltitude_m }; + float hazeKeyLightRange_m{ model::Haze::initialHazeKeyLightRange_m }; + float hazeKeyLightAltitude_m{ model::Haze::initialHazeKeyLightAltitude_m }; - float hazeBackgroundBlend{ model::initialHazeBackgroundBlend }; + float hazeBackgroundBlend{ model::Haze::initialHazeBackgroundBlend }; // methods void setHazeColorR(const float value); diff --git a/libraries/render-utils/src/HazeStage.h b/libraries/render-utils/src/HazeStage.h index e2d09f3011..e3b061dffd 100644 --- a/libraries/render-utils/src/HazeStage.h +++ b/libraries/render-utils/src/HazeStage.h @@ -110,15 +110,15 @@ class FetchHazeConfig : public render::Job::Config { public: FetchHazeConfig() : render::Job::Config() {} - float hazeColorR{ model::initialHazeColor.r }; - float hazeColorG{ model::initialHazeColor.g }; - float hazeColorB{ model::initialHazeColor.b }; - float hazeGlareAngle_degs{ model::initialGlareAngle_degs }; + float hazeColorR{ model::Haze::initialHazeColor.r }; + float hazeColorG{ model::Haze::initialHazeColor.g }; + float hazeColorB{ model::Haze::initialHazeColor.b }; + float hazeGlareAngle_degs{ model::Haze::initialGlareAngle_degs }; - float hazeGlareColorR{ model::initialHazeGlareColor.r }; - float hazeGlareColorG{ model::initialHazeGlareColor.g }; - float hazeGlareColorB{ model::initialHazeGlareColor.b }; - float hazeBaseReference_m{ model::initialHazeBaseReference_m }; + float hazeGlareColorR{ model::Haze::initialHazeGlareColor.r }; + float hazeGlareColorG{ model::Haze::initialHazeGlareColor.g }; + float hazeGlareColorB{ model::Haze::initialHazeGlareColor.b }; + float hazeBaseReference_m{ model::Haze::initialHazeBaseReference_m }; bool isHazeActive{ false }; bool isAltitudeBased{ false }; @@ -126,13 +126,13 @@ public: bool isModulateColorActive{ false }; bool isHazeEnableGlare{ false }; - float hazeRange_m{ model::initialHazeRange_m }; - float hazeHeight_m{ model::initialHazeHeight_m }; + float hazeRange_m{ model::Haze::initialHazeRange_m }; + float hazeHeight_m{ model::Haze::initialHazeHeight_m }; - float hazeKeyLightRange_m{ model::initialHazeKeyLightRange_m }; - float hazeKeyLightAltitude_m{ model::initialHazeKeyLightAltitude_m }; + float hazeKeyLightRange_m{ model::Haze::initialHazeKeyLightRange_m }; + float hazeKeyLightAltitude_m{ model::Haze::initialHazeKeyLightAltitude_m }; - float hazeBackgroundBlend{ model::initialHazeBackgroundBlend }; + float hazeBackgroundBlend{ model::Haze::initialHazeBackgroundBlend }; public slots: void setHazeColorR(const float value) { hazeColorR = value; emit dirty(); }