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

feat: add cloud shadows #172

Merged
merged 13 commits into from
Feb 6, 2024
Prev Previous commit
Next Next commit
chore: use luma for diffuse light saturation
Pentalimbed committed Feb 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5c41e5272e784dd11092a0c3e0b41ad716e82ade
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ float3 getCloudShadowMult(float3 rel_pos, float3 eye_to_sun, SamplerState samp)

float4 cloudCubeSample = cloudShadows.Sample(samp, cloudSampleDir);
float3 cloudDiffuseLight = cloudCubeSample.xyz * perPassCloudShadow[0].DiffuseLightBrightness;
cloudDiffuseLight = saturate(lerp(length(cloudDiffuseLight), cloudDiffuseLight, perPassCloudShadow[0].DiffuseLightSaturation));
cloudDiffuseLight = saturate(lerp(dot(cloudDiffuseLight, float3(0.2125, 0.7154, 0.0721)), cloudDiffuseLight, perPassCloudShadow[0].DiffuseLightSaturation));
float cloudShadowBlend = lerp(0, saturate(cloudCubeSample.w), perPassCloudShadow[0].ShadowBlend);

return lerp(1.0, cloudDiffuseLight, cloudShadowBlend);
53 changes: 27 additions & 26 deletions src/Features/CloudShadows.cpp
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

#include "Util.h"

#include "magic_enum_flags.hpp"

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
CloudShadows::Settings,
EnableCloudShadows,
@@ -27,38 +29,34 @@ class FrameChecker

void CloudShadows::DrawSettings()
{
if (ImGui::TreeNodeEx("Cloud Shadows", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable Cloud Shadows", (bool*)&settings.EnableCloudShadows);

if (ImGui::TreeNodeEx("Mixing", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::SliderFloat("Effect Mix", &settings.ShadowBlend, 0.0f, 1.0f, "%.2f");
ImGui::Checkbox("Enable Cloud Shadows", (bool*)&settings.EnableCloudShadows);

ImGui::SliderFloat("Diffuse Light Brightness", &settings.DiffuseLightBrightness, 0.0f, 1.0f, "%.2f");
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Simulates diffuse light \"filtered\" by the cloud.");
}
if (ImGui::TreeNodeEx("Mixing", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::SliderFloat("Effect Mix", &settings.ShadowBlend, 0.0f, 1.0f, "%.2f");

ImGui::SliderFloat("Diffuse Light Saturation", &settings.DiffuseLightSaturation, 0.0f, 2.0f, "%.2f");

ImGui::TreePop();
ImGui::SliderFloat("Diffuse Light Brightness", &settings.DiffuseLightBrightness, 0.0f, 1.0f, "%.2f");
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text("Simulates diffuse light \"filtered\" by the cloud.");
}

if (ImGui::TreeNodeEx("Geometry")) {
ImGui::SliderFloat("Cloud Height", &settings.CloudHeight, 1e3f / 1.428e-2f, 10e3f / 1.428e-2f, "%.1f units");
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::BulletText(std::format("approx: {:.2f} km / {:.2f} miles", settings.CloudHeight * 1.428e-5f, settings.CloudHeight * 8.877e-6f).data());
ImGui::Text("This setting affects the scale of the cloud movement. Higher clouds casts slightly greater shadow.");
}
ImGui::SliderFloat("Diffuse Light Saturation", &settings.DiffuseLightSaturation, 0.0f, 2.0f, "%.2f");

ImGui::SliderFloat("Planet Radius", &settings.PlanetRadius, 2000e3f / 1.428e-2f, 10000e3f / 1.428e-2f, "%.1f units");
ImGui::TreePop();
}

if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::BulletText(std::format("approx: {:.1f} km / {:.1f} miles", settings.PlanetRadius * 1.428e-5f, settings.PlanetRadius * 8.877e-6f).data());
ImGui::Text("This setting affects distortion of clouds near horizon.");
}
ImGui::TreePop();
if (ImGui::TreeNodeEx("Geometry")) {
ImGui::SliderFloat("Cloud Height", &settings.CloudHeight, 1e3f / 1.428e-2f, 10e3f / 1.428e-2f, "%.1f units");
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::BulletText(std::format("approx: {:.2f} km / {:.2f} miles", settings.CloudHeight * 1.428e-5f, settings.CloudHeight * 8.877e-6f).data());
ImGui::Text("This setting affects the scale of the cloud movement. Higher clouds casts slightly greater shadow.");
}

ImGui::SliderFloat("Planet Radius", &settings.PlanetRadius, 2000e3f / 1.428e-2f, 10000e3f / 1.428e-2f, "%.1f units");

if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::BulletText(std::format("approx: {:.1f} km / {:.1f} miles", settings.PlanetRadius * 1.428e-5f, settings.PlanetRadius * 8.877e-6f).data());
ImGui::Text("This setting affects distortion of clouds near horizon.");
}
ImGui::TreePop();
}
}
@@ -151,8 +149,11 @@ void CloudShadows::ModifySky(const RE::BSShader*, const uint32_t descriptor)
context->OMSetBlendState(blendState, blendFactor, sampleMask);
}

//auto state = RE::BSGraphics::RendererShadowState::GetSingleton();
//state->GetRuntimeData().stateUpdateFlags |= (uint32_t)RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND;
// auto state = RE::BSGraphics::RendererShadowState::GetSingleton();
alandtse marked this conversation as resolved.
Show resolved Hide resolved
// state->GetRuntimeData().stateUpdateFlags = RE::BSGraphics::ShaderFlags(
// (uint32_t)state->GetRuntimeData().stateUpdateFlags |
// (uint32_t)RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND |
// (uint32_t)RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET);
}
}