Browse Source

Use linear scaling for Light value.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
09c85276d6
3 changed files with 15 additions and 13 deletions
  1. +3
    -3
      include/engine/Light.hpp
  2. +6
    -6
      src/app/ModuleLightWidget.cpp
  3. +6
    -4
      src/engine/Engine.cpp

+ 3
- 3
include/engine/Light.hpp View File

@@ -14,16 +14,16 @@ struct Light {

/** Sets the brightness immediately with no light decay. */
void setBrightness(float brightness) {
value = (brightness > 0.f) ? std::pow(brightness, 2) : 0.f;
value = (brightness > 0.f) ? brightness : 0.f;
}

float getBrightness() {
return std::sqrt(value);
return value;
}

/** Emulates light decay with slow fall but immediate rise. */
void setSmoothBrightness(float brightness, float deltaTime) {
float v = (brightness > 0.f) ? std::pow(brightness, 2) : 0.f;
float v = (brightness > 0.f) ? brightness : 0.f;
if (v < value) {
// Fade out light
const float lambda = 30.f;


+ 6
- 6
src/app/ModuleLightWidget.cpp View File

@@ -12,13 +12,13 @@ void ModuleLightWidget::step() {
assert(module->lights.size() >= firstLightId + baseColors.size());

for (size_t i = 0; i < baseColors.size(); i++) {
float brightness = module->lights[firstLightId + i].getBrightness();
if (!std::isfinite(brightness))
brightness = 0.f;
float b = module->lights[firstLightId + i].getBrightness();
if (!std::isfinite(b))
b = 0.f;
b = math::clamp(b, 0.f, 1.f);
// Because LEDs are nonlinear, this seems to look more natural.
brightness = std::sqrt(brightness);
brightness = math::clamp(brightness, 0.f, 1.f);
brightnesses[i] = brightness;
b = std::sqrt(b);
brightnesses[i] = b;
}
}
else {


+ 6
- 4
src/engine/Engine.cpp View File

@@ -495,6 +495,7 @@ void Engine::addModule(Module *module) {
}
// Add module
internal->modules.push_back(module);
// Trigger Add event
module->onAdd();
// Update ParamHandles
for (ParamHandle *paramHandle : internal->paramHandles) {
@@ -507,6 +508,9 @@ void Engine::removeModule(Module *module) {
assert(module);
VIPLock vipLock(internal->vipMutex);
std::lock_guard<std::recursive_mutex> lock(internal->mutex);
// Check that the module actually exists
auto it = std::find(internal->modules.begin(), internal->modules.end(), module);
assert(it != internal->modules.end());
// If a param is being smoothed on this module, stop smoothing it immediately
if (module == internal->smoothModule) {
internal->smoothModule = NULL;
@@ -532,11 +536,9 @@ void Engine::removeModule(Module *module) {
m->rightModule = NULL;
}
}
// Check that the module actually exists
auto it = std::find(internal->modules.begin(), internal->modules.end(), module);
assert(it != internal->modules.end());
// Remove the module
// Trigger Remove event
module->onRemove();
// Remove module
internal->modules.erase(it);
}



Loading…
Cancel
Save