Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify json io with nlohmann json macro #10

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 13 additions & 26 deletions src/Features/DistantTreeLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
#include "State.h"
#include "Util.h"

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
DistantTreeLighting::Settings,
EnableComplexTreeLOD,
EnableDirLightFix,
SubsurfaceScatteringAmount,
FogDimmerAmount)

void DistantTreeLighting::DrawSettings()
{
if (ImGui::BeginTabItem("Tree LOD Lighting")) {

if (ImGui::TreeNodeEx("Complex Tree LOD", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("Enables advanced lighting simulation on tree LOD.");
ImGui::Text("Requires DynDOLOD.");
Expand Down Expand Up @@ -37,7 +43,6 @@ void DistantTreeLighting::DrawSettings()
ImGui::SliderFloat("Fog Dimmer Amount", &settings.FogDimmerAmount, 0.0f, 1.0f);

ImGui::TreePop();

}

ImGui::EndTabItem();
Expand All @@ -52,12 +57,9 @@ enum class DistantTreeShaderTechniques

void DistantTreeLighting::ModifyDistantTree(const RE::BSShader*, const uint32_t descriptor)
{
if (auto player = RE::PlayerCharacter::GetSingleton())
{
if (auto worldSpace = player->GetWorldspace())
{
if (lastWorldSpace != worldSpace)
{
if (auto player = RE::PlayerCharacter::GetSingleton()) {
if (auto worldSpace = player->GetWorldspace()) {
if (lastWorldSpace != worldSpace) {
lastWorldSpace = worldSpace;
if (auto name = worldSpace->GetFormEditorID()) {
CSimpleIniA ini;
Expand All @@ -74,7 +76,6 @@ void DistantTreeLighting::ModifyDistantTree(const RE::BSShader*, const uint32_t

const auto technique = descriptor & 1;
if (technique != static_cast<uint32_t>(DistantTreeShaderTechniques::Depth)) {

PerPass perPassData{};
ZeroMemory(&perPassData, sizeof(perPassData));

Expand Down Expand Up @@ -147,17 +148,8 @@ void DistantTreeLighting::Draw(const RE::BSShader* shader, const uint32_t descri

void DistantTreeLighting::Load(json& o_json)
{
if (o_json["Tree LOD Lighting"].is_object()) {
json& distantTreeLighting = o_json["Distant Tree Lighting"];
if (distantTreeLighting["EnableComplexTreeLOD"].is_boolean())
settings.EnableComplexTreeLOD = distantTreeLighting["EnableComplexTreeLOD"];
if (distantTreeLighting["EnableDirLightFix"].is_boolean())
settings.EnableDirLightFix = distantTreeLighting["EnableDirLightFix"];
if (distantTreeLighting["SubsurfaceScatteringAmount"].is_number())
settings.SubsurfaceScatteringAmount = distantTreeLighting["SubsurfaceScatteringAmount"];
if (distantTreeLighting["FogDimmerAmount"].is_number())
settings.FogDimmerAmount = distantTreeLighting["FogDimmerAmount"];
}
settings = o_json["Distant Tree Lighting"];

CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile(L"Data\\Shaders\\Features\\TreeLODLighting.ini");
Expand All @@ -173,12 +165,7 @@ void DistantTreeLighting::Load(json& o_json)

void DistantTreeLighting::Save(json& o_json)
{
json distantTreeLighting;
distantTreeLighting["EnableComplexTreeLOD"] = (bool)settings.EnableComplexTreeLOD;
distantTreeLighting["EnableDirLightFix"] = (bool)settings.EnableDirLightFix;
distantTreeLighting["SubsurfaceScatteringAmount"] = settings.SubsurfaceScatteringAmount;
distantTreeLighting["FogDimmerAmount"] = settings.FogDimmerAmount;
o_json["Tree LOD Lighting"] = distantTreeLighting;
o_json["Tree LOD Lighting"] = settings;
}

void DistantTreeLighting::SetupResources()
Expand Down
29 changes: 12 additions & 17 deletions src/Features/GrassCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#include "Features/Clustered.h"

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
GrassCollision::Settings,
EnableGrassCollision,
RadiusMultiplier,
DisplacementMultiplier)

enum class GrassShaderTechniques
{
RenderDepth = 8,
Expand All @@ -15,14 +21,14 @@ void GrassCollision::DrawSettings()
if (ImGui::BeginTabItem("Grass Collision")) {
if (ImGui::TreeNodeEx("Grass Collision", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("Allows player collision to modify grass position.");

ImGui::Checkbox("Enable Grass Collision", (bool*)&settings.EnableGrassCollision);
ImGui::Text("Distance from collision centres to apply collision");
ImGui::SliderFloat("Radius Multiplier", &settings.RadiusMultiplier, 0.0f, 8.0f);

ImGui::Text("Strength of each collision on grass position.");
ImGui::SliderFloat("Displacement Multiplier", &settings.DisplacementMultiplier, 0.0f, 32.0f);

ImGui::TreePop();
}

Expand Down Expand Up @@ -242,15 +248,8 @@ void GrassCollision::Draw(const RE::BSShader* shader, const uint32_t descriptor)

void GrassCollision::Load(json& o_json)
{
if (o_json["Grass Collision"].is_object()) {
json& grassCollision = o_json["Grass Collision"];
if (grassCollision["EnableGrassCollision"].is_boolean())
settings.EnableGrassCollision = grassCollision["EnableGrassCollision"];
if (grassCollision["RadiusMultiplier"].is_number())
settings.RadiusMultiplier = grassCollision["RadiusMultiplier"];
if (grassCollision["DisplacementMultiplier"].is_number())
settings.DisplacementMultiplier = grassCollision["DisplacementMultiplier"];
}
settings = o_json["Grass Collision"];

CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile(L"Data\\Shaders\\Features\\GrassCollision.ini");
Expand All @@ -266,11 +265,7 @@ void GrassCollision::Load(json& o_json)

void GrassCollision::Save(json& o_json)
{
json grassCollision;
grassCollision["EnableGrassCollision"] = (bool)settings.EnableGrassCollision;
grassCollision["RadiusMultiplier"] = settings.RadiusMultiplier;
grassCollision["DisplacementMultiplier"] = settings.DisplacementMultiplier;
o_json["Grass Collision"] = grassCollision;
o_json["Grass Collision"] = settings;
}

void GrassCollision::SetupResources()
Expand Down
32 changes: 11 additions & 21 deletions src/Features/GrassLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

#include "Features/Clustered.h"

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
GrassLighting::Settings,
Glossiness,
SpecularStrength,
SubsurfaceScatteringAmount,
EnableDirLightFix,
EnablePointLights)

enum class GrassShaderTechniques
{
RenderDepth = 8,
Expand Down Expand Up @@ -104,19 +112,8 @@ void GrassLighting::Draw(const RE::BSShader* shader, const uint32_t descriptor)

void GrassLighting::Load(json& o_json)
{
if (o_json["Grass Lighting"].is_object()) {
json& grassLighting = o_json["Grass Lighting"];
if (grassLighting["Glossiness"].is_number())
settings.Glossiness = grassLighting["Glossiness"];
if (grassLighting["SpecularStrength"].is_number())
settings.SpecularStrength = grassLighting["SpecularStrength"];
if (grassLighting["SubsurfaceScatteringAmount"].is_number())
settings.SubsurfaceScatteringAmount = grassLighting["SubsurfaceScatteringAmount"];
if (grassLighting["EnableDirLightFix"].is_boolean())
settings.EnableDirLightFix = grassLighting["EnableDirLightFix"];
if (grassLighting["EnablePointLights"].is_boolean())
settings.EnablePointLights = grassLighting["EnablePointLights"];
}
settings = o_json["Grass Lighting"];

CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile(L"Data\\Shaders\\Features\\GrassLighting.ini");
Expand All @@ -132,16 +129,9 @@ void GrassLighting::Load(json& o_json)

void GrassLighting::Save(json& o_json)
{
json grassLighting;
grassLighting["Glossiness"] = settings.Glossiness;
grassLighting["SpecularStrength"] = settings.SpecularStrength;
grassLighting["SubsurfaceScatteringAmount"] = settings.SubsurfaceScatteringAmount;
grassLighting["EnableDirLightFix"] = (bool)settings.EnableDirLightFix;
grassLighting["EnablePointLights"] = (bool)settings.EnablePointLights;
o_json["Grass Lighting"] = grassLighting;
o_json["Grass Lighting"] = settings;
}


void GrassLighting::SetupResources()
{
perFrame = new ConstantBuffer(ConstantBufferDesc<PerFrame>());
Expand Down
54 changes: 17 additions & 37 deletions src/Features/ScreenSpaceShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

using RE::RENDER_TARGETS;

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
ScreenSpaceShadows::Settings,
MaxSamples,
FarDistanceScale,
FarThicknessScale,
FarHardness,
NearDistance,
NearThickness,
NearHardness,
BlurRadius,
BlurDropoff)

void ScreenSpaceShadows::DrawSettings()
{
if (ImGui::BeginTabItem("Screen-Space Shadows")) {
Expand Down Expand Up @@ -153,9 +165,9 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t)

auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator();
auto dirLight = skyrim_cast<RE::NiDirectionalLight*>(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get());

bool skyLight = true;
if (auto sky = RE::Sky::GetSingleton())
if (auto sky = RE::Sky::GetSingleton())
skyLight = sky->mode.get() == RE::Sky::Mode::kFull;

if (dirLight && skyLight) {
Expand Down Expand Up @@ -403,29 +415,8 @@ void ScreenSpaceShadows::Draw(const RE::BSShader* shader, const uint32_t descrip

void ScreenSpaceShadows::Load(json& o_json)
{
if (o_json["Screen-Space Shadows"].is_object()) {
json& ssShadows = o_json["Screen-Space Shadows"];
if (ssShadows["EnableScreenSpaceShadows"].is_boolean())
enabled = ssShadows["EnableScreenSpaceShadows"];
if (ssShadows["MaxSamples"].is_number())
settings.MaxSamples = ssShadows["MaxSamples"];
if (ssShadows["FarDistanceScale"].is_number())
settings.FarDistanceScale = ssShadows["FarDistanceScale"];
if (ssShadows["FarThicknessScale"].is_number())
settings.FarThicknessScale = ssShadows["FarThicknessScale"];
if (ssShadows["FarHardness"].is_number())
settings.FarHardness = ssShadows["FarHardness"];
if (ssShadows["NearDistance"].is_number())
settings.NearDistance = ssShadows["NearDistance"];
if (ssShadows["NearThickness"].is_number())
settings.NearThickness = ssShadows["NearThickness"];
if (ssShadows["NearHardness"].is_number())
settings.NearHardness = ssShadows["NearHardness"];
if (ssShadows["BlurRadius"].is_number())
settings.BlurRadius = ssShadows["BlurRadius"];
if (ssShadows["BlurDropoff"].is_number())
settings.BlurDropoff = ssShadows["BlurDropoff"];
}
settings = o_json["Screen-Space Shadows"];

CSimpleIniA ini;
ini.SetUnicode();
ini.LoadFile(L"Data\\Shaders\\Features\\ScreenSpaceShadows.ini");
Expand All @@ -441,18 +432,7 @@ void ScreenSpaceShadows::Load(json& o_json)

void ScreenSpaceShadows::Save(json& o_json)
{
json ssShadows;
ssShadows["EnableScreenSpaceShadows"] = enabled;
ssShadows["MaxSamples"] = settings.MaxSamples;
ssShadows["FarDistanceScale"] = settings.FarDistanceScale;
ssShadows["FarThicknessScale"] = settings.FarThicknessScale;
ssShadows["FarHardness"] = settings.FarHardness;
ssShadows["NearDistance"] = settings.NearDistance;
ssShadows["NearThickness"] = settings.NearThickness;
ssShadows["NearHardness"] = settings.NearHardness;
ssShadows["BlurRadius"] = settings.BlurRadius;
ssShadows["BlurDropoff"] = settings.BlurDropoff;
o_json["Screen-Space Shadows"] = ssShadows;
o_json["Screen-Space Shadows"] = settings;
}

void ScreenSpaceShadows::SetupResources()
Expand Down