Skip to content
Merged
16 changes: 4 additions & 12 deletions src/Features/InverseSquareLighting.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
#include "InverseSquareLighting.h"
#include "Features/InverseSquareLighting/Common.h"
#include "LightLimitFix.h"
#include "WeatherEditor/EditorWindow.h"
#include <numbers>

void InverseSquareLighting::DrawSettings()
{
editor.DrawSettings();
}

void InverseSquareLighting::EarlyPrepass()
{
editor.GatherLights();
}

void InverseSquareLighting::PostPostLoad()
{
stl::detour_thunk<CreatePointLight>(REL::RelocationID(17208, 17610));
Expand Down Expand Up @@ -55,13 +46,14 @@ void InverseSquareLighting::ProcessLight(LightLimitFix::LightData& light, RE::BS
runtimeData->flags.set(LightLimitFix::LightFlags::Initialised);
}

editor.ApplyOverrides(niLight, runtimeData);
const auto& editorRef = EditorWindow::GetSingleton()->lightEditor;
editorRef.ApplyOverrides(niLight, runtimeData);

light.lightFlags = runtimeData->flags;
light.color = { runtimeData->diffuse.red, runtimeData->diffuse.green, runtimeData->diffuse.blue };

const bool isInvSq = light.lightFlags.any(LightLimitFix::LightFlags::InverseSquare);
if (bsLight->pointLight && editor.enabled && ((isInvSq && editor.disableInvSqLights) || (!isInvSq && editor.disableRegularLights)))
if (bsLight->pointLight && ((isInvSq && editorRef.disableInvSqLights) || (!isInvSq && editorRef.disableRegularLights)))
light.lightFlags.set(LightLimitFix::LightFlags::Disabled);
Comment thread
SkrubbySkrubInAShrub marked this conversation as resolved.

if (bsLight->pointLight && isInvSq) {
Expand Down
10 changes: 1 addition & 9 deletions src/Features/InverseSquareLighting.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "Features/InverseSquareLighting/LightEditor.h"
#include "LightLimitFix.h"

struct InverseSquareLighting : Feature
Expand All @@ -21,17 +20,12 @@ struct InverseSquareLighting : Feature
"Lights smoothly fade out at a configurable cutoff, solving the infinite distance problem",
"Does not modify any existing lighting",
"Requires the use of mods with lights enabled for inverse square falloff.",
"Full integration with Light Placer",
"Built in Light Editor for mod authors to preview lighting changes in real-time" }
"Full integration with Light Placer" }
};
}

inline bool HasShaderDefine(RE::BSShader::Type) override { return true; };

virtual void DrawSettings() override;

virtual void EarlyPrepass() override;

virtual bool SupportsVR() override { return true; }

virtual void PostPostLoad() override;
Expand All @@ -56,8 +50,6 @@ struct InverseSquareLighting : Feature
virtual bool IsCore() const override { return true; };

private:
LightEditor editor = LightEditor();

static constexpr float DefaultCutoff = 0.05f;
static constexpr float DefaultShadowCasterCutoff = 0.022f;

Expand Down
18 changes: 17 additions & 1 deletion src/WeatherEditor/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ void EditorWindow::ShowObjectsWindow()
ImGui::Spacing();

// List of categories
const char* categories[] = { "Weather", "ImageSpace", "Lighting Template", "Cell Lighting", "Volumetric Lighting", "Shader Particle Geometry", "Lens Flare", "Visual Effect", "Interior Only" };
const char* categories[] = { "Weather", "ImageSpace", "Lighting Template", "Cell Lighting",
"Volumetric Lighting", "Shader Particle Geometry", "Lens Flare", "Visual Effect",
"Interior Only", "Lighting editor" };
for (int i = 0; i < IM_ARRAYSIZE(categories); ++i) {
// Highlight the selected category
if (ImGui::Selectable(categories[i], m_selectedCategory == categories[i])) {
Expand All @@ -238,6 +240,16 @@ void EditorWindow::ShowObjectsWindow()
return;
}

if (m_selectedCategory == "Lighting editor") {
BeginScrollableContent("##LightEditorScroll");
lightEditor.DrawSettings();
EndScrollableContent();
ImGui::EndChild();
ImGui::EndTable();
ImGui::End();
return;
}

// Returns the widget collection for a given category; Cell Lighting and unknown
// categories return an empty collection since they have no standalone widget list.
auto getWidgetsForCategory = [&](const std::string& cat) -> const std::vector<std::unique_ptr<Widget>>& {
Expand Down Expand Up @@ -1402,6 +1414,7 @@ void EditorWindow::UpdateOpenState()
BackgroundBlur::SetWeatherEditorActive(IsViewportActive());

} else if (!open && wasOpen) {
lightEditor.ResetOverrides();
RestoreVanityCamera();
ShowGameMenus();
BackgroundBlur::SetWeatherEditorActive(false);
Expand All @@ -1412,6 +1425,9 @@ void EditorWindow::UpdateOpenState()

void EditorWindow::Draw()
{
if (open)
lightEditor.GatherLights();

Comment thread
coderabbitai[bot] marked this conversation as resolved.
// Keep background blur in sync when HDR toggles while the editor stays open
{
static bool prevViewportActive = false;
Expand Down
3 changes: 3 additions & 0 deletions src/WeatherEditor/EditorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Weather/ReferenceEffectWidget.h"
#include "Weather/VolumetricLightingWidget.h"
#include "Weather/WeatherWidget.h"
#include "LightEditor.h"
#include "WeatherUtils.h"
#include "Widget.h"

Expand Down Expand Up @@ -63,6 +64,8 @@ class EditorWindow
// Owned by EditorWindow, created on demand in ShowObjectsWindow(), released in destructor
std::unique_ptr<CellLightingWidget> currentCellLightingWidget;

LightEditor lightEditor;

// Weather locking for editing
RE::TESWeather* lockedWeather = nullptr;
bool weatherLockActive = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Features/InverseSquareLighting/LightEditor.h"
#include "Features/InverseSquareLighting.h"
#include "Features/LightLimitFix.h"
#include "Menu.h"
#include "LightEditor.h"
#include "../Features/InverseSquareLighting.h"
#include "../Features/LightLimitFix.h"
#include "../Menu.h"

#include <array>
#include <filesystem>
Expand All @@ -10,21 +10,6 @@

void LightEditor::DrawSettings()
{
ImGui::Checkbox("Enable Light Editor", &enabled);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Allows for modifying lights in real-time to preview changes. "
"Light Placer lights can be saved back to their JSON configs. "
"Not intended for gameplay use.");
}

if (!enabled)
return;

ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();

ImGui::Checkbox("Disable Regular Falloff Lights", &disableRegularLights);
ImGui::Checkbox("Disable Inverse Square Falloff Lights", &disableInvSqLights);

Expand Down Expand Up @@ -168,10 +153,8 @@ std::string LightEditor::GetLightName(LightInfo& lightInfo)

void LightEditor::GatherLights()
{
if (!enabled || !Menu::GetSingleton()->ShouldSwallowInput()) {
RestoreOriginal();
selected = {};
previous = {};
if (!Menu::GetSingleton()->ShouldSwallowInput()) {
ResetOverrides();
return;
}

Expand Down Expand Up @@ -287,6 +270,13 @@ void LightEditor::GatherLights()
SortLights();
}

void LightEditor::ResetOverrides()
{
RestoreOriginal();
selected = {};
previous = {};
}

void LightEditor::UpdateSelectedLight(RE::TESObjectREFR* refr, RE::TESObjectLIGH* ligh, RE::NiLight* niLight)
{
const auto runtimeData = ISLCommon::RuntimeLightDataExt::Get(niLight);
Expand Down Expand Up @@ -372,7 +362,7 @@ void LightEditor::UpdateSelectedLight(RE::TESObjectREFR* refr, RE::TESObjectLIGH

bool LightEditor::ApplyOverrides(RE::NiLight* niLight, ISLCommon::RuntimeLightDataExt* runtimeData) const
{
if (!enabled || niLight != activeNiLight.get())
if (niLight != activeNiLight.get())
return false;

runtimeData->diffuse = current.data.diffuse;
Expand Down Expand Up @@ -707,4 +697,4 @@ void LightEditor::SortLights()
default:
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#pragma once
#include "Features/InverseSquareLighting/Common.h"
#pragma once
#include "../Features/InverseSquareLighting/Common.h"

struct LightEditor
{
bool enabled;
bool disableInvSqLights;
bool disableRegularLights;
bool disableInvSqLights = false;
bool disableRegularLights = false;
bool shadowsOnly = false;

void DrawSettings();
void GatherLights();
void ResetOverrides();

bool ApplyOverrides(RE::NiLight* niLight, ISLCommon::RuntimeLightDataExt* runtimeData) const;

Expand Down
Loading