From fe286aff832807ccaf74d07d29915cf2f0f74891 Mon Sep 17 00:00:00 2001 From: Nissim Date: Wed, 18 Oct 2017 08:42:07 -0700 Subject: [PATCH] Andrew's corrections (per coding standard). --- libraries/model/src/model/Haze.cpp | 15 +++++---------- .../render-utils/src/DeferredGlobalLight.slh | 10 ++++++---- .../render-utils/src/DeferredLightingEffect.cpp | 4 ++-- libraries/render-utils/src/DrawHaze.cpp | 2 +- libraries/render-utils/src/Haze.slf | 17 ++++++++--------- .../src/SceneScriptingInterface.cpp | 3 +-- 6 files changed, 23 insertions(+), 28 deletions(-) diff --git a/libraries/model/src/model/Haze.cpp b/libraries/model/src/model/Haze.cpp index f5fc04f55e..679d4ad3d1 100644 --- a/libraries/model/src/model/Haze.cpp +++ b/libraries/model/src/model/Haze.cpp @@ -50,8 +50,7 @@ void Haze::setHazeEnableGlare(const bool isHazeEnableGlare) { if (((params.hazeMode & HAZE_MODE_IS_ENABLE_LIGHT_BLEND) == HAZE_MODE_IS_ENABLE_LIGHT_BLEND) && !isHazeEnableGlare) { _hazeParametersBuffer.edit().hazeMode &= ~HAZE_MODE_IS_ENABLE_LIGHT_BLEND; - } - else if (((params.hazeMode & HAZE_MODE_IS_ENABLE_LIGHT_BLEND) != HAZE_MODE_IS_ENABLE_LIGHT_BLEND) && isHazeEnableGlare) { + } else if (((params.hazeMode & HAZE_MODE_IS_ENABLE_LIGHT_BLEND) != HAZE_MODE_IS_ENABLE_LIGHT_BLEND) && isHazeEnableGlare) { _hazeParametersBuffer.edit().hazeMode |= HAZE_MODE_IS_ENABLE_LIGHT_BLEND; } } @@ -82,8 +81,7 @@ void Haze::setHazeActive(const bool isHazeActive) { if (((params.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE )&& !isHazeActive) { _hazeParametersBuffer.edit().hazeMode &= ~HAZE_MODE_IS_ACTIVE; - } - else if (((params.hazeMode & HAZE_MODE_IS_ACTIVE) != HAZE_MODE_IS_ACTIVE) && isHazeActive) { + } else if (((params.hazeMode & HAZE_MODE_IS_ACTIVE) != HAZE_MODE_IS_ACTIVE) && isHazeActive) { _hazeParametersBuffer.edit().hazeMode |= HAZE_MODE_IS_ACTIVE; } } @@ -93,8 +91,7 @@ void Haze::setAltitudeBased(const bool isAltitudeBased) { if (((params.hazeMode & HAZE_MODE_IS_ALTITUDE_BASED) == HAZE_MODE_IS_ALTITUDE_BASED )&& !isAltitudeBased) { _hazeParametersBuffer.edit().hazeMode &= ~HAZE_MODE_IS_ALTITUDE_BASED; - } - else if (((params.hazeMode & HAZE_MODE_IS_ALTITUDE_BASED) != HAZE_MODE_IS_ALTITUDE_BASED) && isAltitudeBased) { + } else if (((params.hazeMode & HAZE_MODE_IS_ALTITUDE_BASED) != HAZE_MODE_IS_ALTITUDE_BASED) && isAltitudeBased) { _hazeParametersBuffer.edit().hazeMode |= HAZE_MODE_IS_ALTITUDE_BASED; } } @@ -104,8 +101,7 @@ void Haze::setHazeAttenuateKeyLight(const bool isHazeAttenuateKeyLight) { if (((params.hazeMode & HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED) == HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED ) && !isHazeAttenuateKeyLight) { _hazeParametersBuffer.edit().hazeMode &= ~HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED; - } - else if (((params.hazeMode & HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED) != HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED) && isHazeAttenuateKeyLight) { + } else if (((params.hazeMode & HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED) != HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED) && isHazeAttenuateKeyLight) { _hazeParametersBuffer.edit().hazeMode |= HAZE_MODE_IS_DIRECTIONAL_LIGHT_ATTENUATED; } } @@ -115,8 +111,7 @@ void Haze::setModulateColorActive(const bool isModulateColorActive) { if (((params.hazeMode & HAZE_MODE_IS_MODULATE_COLOR) == HAZE_MODE_IS_MODULATE_COLOR ) && !isModulateColorActive) { _hazeParametersBuffer.edit().hazeMode &= ~HAZE_MODE_IS_MODULATE_COLOR; - } - else if (((params.hazeMode & HAZE_MODE_IS_MODULATE_COLOR) != HAZE_MODE_IS_MODULATE_COLOR) && isModulateColorActive) { + } else if (((params.hazeMode & HAZE_MODE_IS_MODULATE_COLOR) != HAZE_MODE_IS_MODULATE_COLOR) && isModulateColorActive) { _hazeParametersBuffer.edit().hazeMode |= HAZE_MODE_IS_MODULATE_COLOR; } } diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index ae560686e1..cc20f6335e 100644 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -145,8 +145,11 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu Light light = getLight(); vec3 lightDirection = getLightDirection(light); - // Height at which haze density is reduced by 95% - float height_95p = -log(0.05) / hazeParams.hazeAltitudeFactorKeyLight; + // Height at which haze density is reduced by 95% (default set to 2000.0 for safety ,this should never happen) + float height_95p = 2000.0; + if (hazeParams.hazeAltitudeFactorKeyLight > 0.0f) { + height_95p = -log(0.05) / hazeParams.hazeAltitudeFactorKeyLight; + } // Note that the sine will always be positive float sin_pitch = sqrt(1.0 - lightDirection.y * lightDirection.y); @@ -155,8 +158,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu const float minimumSinPitch = 0.001; if (sin_pitch < minimumSinPitch) { distance = height_95p / minimumSinPitch; - } - else { + } else { distance = height_95p / sin_pitch; } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 6cd3cb1dca..e6a33a9911 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -552,7 +552,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, deferredLightingEffect->setupKeyLightBatch(args, batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); // Haze - if (haze != nullptr) { + if (haze) { batch.setUniformBuffer(HAZE_MODEL_BUFFER_SLOT, haze->getHazeParametersBuffer()); } @@ -771,7 +771,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { } } - if (_defaultHaze == nullptr) { + if (!_defaultHaze) { auto hazeStage = renderContext->_scene->getStage(); if (hazeStage) { diff --git a/libraries/render-utils/src/DrawHaze.cpp b/libraries/render-utils/src/DrawHaze.cpp index 369f5df5e2..bf254ce80e 100644 --- a/libraries/render-utils/src/DrawHaze.cpp +++ b/libraries/render-utils/src/DrawHaze.cpp @@ -148,7 +148,7 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu RenderArgs* args = renderContext->args; - if (_hazePipeline == nullptr) { + if (!_hazePipeline) { gpu::ShaderPointer ps = gpu::Shader::createPixel(std::string(Haze_frag)); gpu::ShaderPointer vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); diff --git a/libraries/render-utils/src/Haze.slf b/libraries/render-utils/src/Haze.slf index ee552faf63..f9eca755f2 100644 --- a/libraries/render-utils/src/Haze.slf +++ b/libraries/render-utils/src/Haze.slf @@ -69,8 +69,7 @@ void main(void) { vec4 blendedHazeColor; if ((hazeParams.hazeMode & HAZE_MODE_IS_ENABLE_LIGHT_BLEND) == HAZE_MODE_IS_ENABLE_LIGHT_BLEND) { blendedHazeColor = mix(hazeColor, directionalLightColor, power); - } - else { + } else { blendedHazeColor = hazeColor; } @@ -102,15 +101,13 @@ void main(void) { // Compute color after haze effect potentialFragColor = mix(fragColor, vec4(1.0, 1.0, 1.0, 1.0), vec4(hazeAmount, 1.0)); - } - else if ((hazeParams.hazeMode & HAZE_MODE_IS_ALTITUDE_BASED) != HAZE_MODE_IS_ALTITUDE_BASED) { + } else if ((hazeParams.hazeMode & HAZE_MODE_IS_ALTITUDE_BASED) != HAZE_MODE_IS_ALTITUDE_BASED) { // Haze is based only on range float hazeAmount = 1.0 - exp(-distance * hazeParams.hazeRangeFactor); // Compute color after haze effect potentialFragColor = mix(fragColor, blendedHazeColor, hazeAmount); - } - else { + } else { // Haze is based on both range and altitude // Taken from www.crytek.com/download/GDC2007_RealtimeAtmoFxInGamesRev.ppt @@ -128,7 +125,10 @@ void main(void) { float deltaHeight = worldFragPos.y - worldEyePos.y; if (abs(deltaHeight) > slopeThreshold) { float t = hazeParams.hazeAltitudeFactor * deltaHeight; - hazeIntegral *= (1.0 - exp (-t)) / t; + // Protect from wild values + if (abs(t) > 0.0000001) { + hazeIntegral *= (1.0 - exp (-t)) / t; + } } float hazeAmount = 1.0 - exp(-hazeIntegral); @@ -140,8 +140,7 @@ void main(void) { // Mix with background at far range if (distance > 32000.0) { outFragColor = mix(potentialFragColor, fragColor, hazeParams.backgroundBlendValue); - } - else { + } else { outFragColor = potentialFragColor; } } diff --git a/libraries/script-engine/src/SceneScriptingInterface.cpp b/libraries/script-engine/src/SceneScriptingInterface.cpp index 58741f9271..aa22eaa2d1 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.cpp +++ b/libraries/script-engine/src/SceneScriptingInterface.cpp @@ -132,8 +132,7 @@ QString SceneScripting::Stage::getBackgroundMode() const { void SceneScripting::Stage::setHazeMode(const QString& mode) { if (mode == QString("haze off")) { _skyStage->setHazeMode(model::SunSkyStage::HAZE_OFF); - } - else if (mode == QString("haze on")) { + } else if (mode == QString("haze on")) { _skyStage->setHazeMode(model::SunSkyStage::HAZE_ON); } }