Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ders into dev
  • Loading branch information
doodlum committed Oct 13, 2024
2 parents 5a6ed29 + c281eb7 commit 33d284d
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 44 deletions.
13 changes: 11 additions & 2 deletions package/Shaders/Effect.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,10 @@ float3 GetLightingColor(float3 msPosition, float3 worldPosition, float4 screenPo
float4 lightFadeMul = 1.0.xxxx - saturate(PLightingRadiusInverseSquared * lightDistanceSquared);

float3 color = DLightColor.xyz;
# if defined(EFFECT_WEATHER)
# if defined(EFFECT_SHADOWS)
if (!InInterior && !InMapMenu && (ExtraShaderDescriptor & _InWorld)) {
float3 viewDirection = normalize(worldPosition);
color = DirLightColorShared * GetEffectShadow(worldPosition, viewDirection, screenPosition, eyeIndex) * 0.5;
color = DirLightColorShared * GetEffectShadow(worldPosition, normalize(worldPosition), screenPosition, eyeIndex) * 0.5;

float3 directionalAmbientColor = DirectionalAmbientShared._14_24_34;
color += directionalAmbientColor;
Expand All @@ -534,6 +535,14 @@ float3 GetLightingColor(float3 msPosition, float3 worldPosition, float4 screenPo
float3 directionalAmbientColor = DirectionalAmbientShared._14_24_34;
color += directionalAmbientColor;
}
# else
color = DirLightColorShared * 0.5;

float3 directionalAmbientColor = DirectionalAmbientShared._14_24_34;
color += directionalAmbientColor;
# endif
# endif

color.x += dot(PLightColorR * lightFadeMul, 1.0.xxxx);
color.y += dot(PLightColorG * lightFadeMul, 1.0.xxxx);
color.z += dot(PLightColorB * lightFadeMul, 1.0.xxxx);
Expand Down
9 changes: 8 additions & 1 deletion src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ HRESULT WINAPI hk_D3D11CreateDeviceAndSwapChainNoStreamline(
D3D_FEATURE_LEVEL* pFeatureLevel,
ID3D11DeviceContext** ppImmediateContext)
{
DXGI_ADAPTER_DESC adapterDesc;
pAdapter->GetDesc(&adapterDesc);
State::GetSingleton()->SetAdapterDescription(adapterDesc.Description);

const D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_1; // Create a device with only the latest feature level
return ptrD3D11CreateDeviceAndSwapChain(pAdapter,
DriverType,
Expand Down Expand Up @@ -240,8 +244,11 @@ HRESULT WINAPI hk_D3D11CreateDeviceAndSwapChain(
D3D_FEATURE_LEVEL* pFeatureLevel,
ID3D11DeviceContext** ppImmediateContext)
{
const D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_1; // Create a device with only the latest feature level
DXGI_ADAPTER_DESC adapterDesc;
pAdapter->GetDesc(&adapterDesc);
State::GetSingleton()->SetAdapterDescription(adapterDesc.Description);

const D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_1; // Create a device with only the latest feature level
auto result = Streamline::GetSingleton()->CreateDeviceAndSwapChain(
pAdapter,
DriverType,
Expand Down
104 changes: 64 additions & 40 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(

namespace ImGui
{
void Spacing(std::uint32_t a_numSpaces)
{
for (std::uint32_t i = 0; i < a_numSpaces; i++) {
Spacing();
}
}

ImVec2 GetNativeViewportSizeScaled(float scale)
{
const auto Size = GetMainViewport()->Size;
Expand Down Expand Up @@ -102,7 +95,7 @@ void Menu::SetupImGuiStyle() const
ImVec4 scrollbarGrabActive{ 0.51f, 0.51f, 0.51f, 1.0f };

style.WindowBorderSize = themeSettings.BorderSize;
style.ChildBorderSize = themeSettings.BorderSize;
style.ChildBorderSize = 0.f;
style.FrameBorderSize = themeSettings.FrameBorderSize;
style.WindowPadding = themeSettings.WindowPadding;
style.WindowRounding = themeSettings.WindowRounding;
Expand All @@ -112,7 +105,7 @@ void Menu::SetupImGuiStyle() const
style.ItemSpacing = themeSettings.ItemSpacing;

colors[ImGuiCol_WindowBg] = themeSettings.BackgroundColor;
colors[ImGuiCol_ChildBg] = colors[ImGuiCol_WindowBg];
colors[ImGuiCol_ChildBg] = ImVec4();
colors[ImGuiCol_ScrollbarBg] = ImVec4();
colors[ImGuiCol_TableHeaderBg] = ImVec4();
colors[ImGuiCol_TableRowBg] = ImVec4();
Expand Down Expand Up @@ -226,22 +219,18 @@ void Menu::DrawSettings()
ImGui::SetNextWindowPos(ImGui::GetNativeViewportSizeScaled(0.5f), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(ImGui::GetNativeViewportSizeScaled(0.8f), ImGuiCond_FirstUseEver);

auto title = std::format("Skyrim Community Shaders {}", Plugin::VERSION.string("."));
auto title = "Community Shaders";

ImGui::Begin(title.c_str(), &IsEnabled, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar);
ImGui::Begin(title, &IsEnabled, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar);
{
if (!ImGui::IsWindowDocked()) {
ImGui::SetWindowFontScale(1.5f);
ImGui::TextUnformatted(title.c_str());
ImGui::TextUnformatted(title);
ImGui::SetWindowFontScale(1.f);
ImGui::SameLine(ImGui::GetWindowWidth() - 70);
if (ImGui::Button("X", ImVec2(50, 0))) {
IsEnabled = false;
}

ImGui::Spacing(2);
ImGui::Spacing();
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal, 3.0f);
ImGui::Spacing(2);
ImGui::Spacing();
}

auto& shaderCache = SIE::ShaderCache::Instance();
Expand Down Expand Up @@ -304,10 +293,14 @@ void Menu::DrawSettings()
ImGui::EndTable();
}

ImGui::Spacing(2);
ImGui::Spacing();
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal, 3.0f);
ImGui::Spacing(2);
ImGui::Spacing();

float footer_height = ImGui::GetTextLineHeightWithSpacing() + 76 - ImGui::GetStyle().WindowPadding.y;
float content_height = ImGui::GetContentRegionAvail().y - footer_height;

ImGui::BeginChild("Menus Table", ImVec2(0, content_height));
if (ImGui::BeginTable("Menus Table", 2, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_Resizable)) {
ImGui::TableSetupColumn("##ListOfMenus", 0, 2);
ImGui::TableSetupColumn("##MenuConfig", 0, 8);
Expand All @@ -319,7 +312,6 @@ void Menu::DrawSettings()
{
std::string name;
std::function<void()> func;
bool supportsVR = true;
};
using MenuFuncInfo = std::variant<BuiltInMenu, std::string, Feature*>;
struct ListMenuVisitor
Expand All @@ -328,9 +320,7 @@ void Menu::DrawSettings()

void operator()(const BuiltInMenu& menu)
{
if (REL::Module::IsVR() && !menu.supportsVR)
return;
if (ImGui::Selectable(menu.name.c_str(), selectedMenu == listId, ImGuiSelectableFlags_SpanAllColumns))
if (ImGui::Selectable(fmt::format(" {} ", menu.name).c_str(), selectedMenu == listId, ImGuiSelectableFlags_SpanAllColumns))
selectedMenu = listId;
}
void operator()(const std::string& label)
Expand All @@ -356,11 +346,7 @@ void Menu::DrawSettings()
{
void operator()(const BuiltInMenu& menu)
{
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4());
if (ImGui::BeginChild("##FeatureConfigFrame", { 0, 0 }, true)) {
ImGui::PopStyleVar();
ImGui::PopStyleColor();
menu.func();
}
ImGui::EndChild();
Expand All @@ -380,32 +366,26 @@ void Menu::DrawSettings()
"Restores the feature's settings back to their default values. "
"You will still need to Save Settings to make these changes permanent. ");
}
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4());
if (ImGui::BeginChild("##FeatureConfigFrame", { 0, 0 }, true)) {
ImGui::PopStyleVar();
ImGui::PopStyleColor();
feat->DrawSettings();
}
ImGui::EndChild();
}
};

auto& featureList = Feature::GetFeatureList();
auto sortedList{ featureList }; // need a copy so the load order is not lost
std::sort(sortedList.begin(), sortedList.end(), [](Feature* a, Feature* b) {
auto sortedFeatureList{ featureList }; // need a copy so the load order is not lost
std::sort(sortedFeatureList.begin(), sortedFeatureList.end(), [](Feature* a, Feature* b) {
return a->GetName() < b->GetName();
});

auto menuList = std::vector<MenuFuncInfo>{
BuiltInMenu{ " General ", [&]() { DrawGeneralSettings(); } },
BuiltInMenu{ " Advanced ", [&]() { DrawAdvancedSettings(); } },
BuiltInMenu{ " True PBR ", []() { TruePBR::GetSingleton()->DrawSettings(); } },
BuiltInMenu{ " Upscaling ", []() { Upscaling::GetSingleton()->DrawSettings(); } },
BuiltInMenu{ " Frame Generation ", []() { Streamline::GetSingleton()->DrawSettings(); }, false },
BuiltInMenu{ "General", [&]() { DrawGeneralSettings(); } },
BuiltInMenu{ "Advanced", [&]() { DrawAdvancedSettings(); } },
BuiltInMenu{ "Display", [&]() { DrawDisplaySettings(); } },
"Features"s
};
std::ranges::copy(sortedList, std::back_inserter(menuList));
std::ranges::copy(sortedFeatureList, std::back_inserter(menuList));

ImGui::TableNextColumn();
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
Expand All @@ -429,6 +409,13 @@ void Menu::DrawSettings()

ImGui::EndTable();
}
ImGui::EndChild();

ImGui::Spacing();
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal, 3.0f);
ImGui::Spacing();

DrawFooter();
}
ImGui::End();
}
Expand Down Expand Up @@ -710,6 +697,43 @@ void Menu::DrawAdvancedSettings()
ImGui::EndTable();
}
}

TruePBR::GetSingleton()->DrawSettings();
}

void Menu::DrawDisplaySettings()
{
if (ImGui::CollapsingHeader("Upscaling", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
Upscaling::GetSingleton()->DrawSettings();
}
if (!REL::Module::IsVR() && ImGui::CollapsingHeader("Frame Generation", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
Streamline::GetSingleton()->DrawSettings();
}
}

static std::string GetFormattedVersion(const REL::Version& version)
{
const auto& v = version.string(".");
return v.substr(0, v.find_last_of("."));
}

void Menu::DrawFooter()
{
if (ImGui::BeginTable("##Footer", 4, ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableNextColumn();
ImGui::TextUnformatted(std::format("CS Version: {}", GetFormattedVersion(Plugin::VERSION).c_str()).c_str());

ImGui::TableNextColumn();
ImGui::TextUnformatted(std::format("Game Version: {} {}", magic_enum::enum_name(REL::Module::GetRuntime()), GetFormattedVersion(REL::Module::get().version()).c_str()).c_str());

ImGui::TableNextColumn();
ImGui::TextUnformatted(std::format("D3D12 Interop: {}", Streamline::GetSingleton()->featureDLSSG && !REL::Module::IsVR() ? "Active" : "Inactive").c_str());

ImGui::TableNextColumn();
ImGui::TextUnformatted(std::format("GPU: {}", State::GetSingleton()->adapterDescription.c_str()).c_str());

ImGui::EndTable();
}
}

void Menu::DrawOverlay()
Expand Down
2 changes: 2 additions & 0 deletions src/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Menu

void DrawGeneralSettings();
void DrawAdvancedSettings();
void DrawDisplaySettings();
void DrawFooter();

class CharEvent : public RE::InputEvent
{
Expand Down
8 changes: 8 additions & 0 deletions src/State.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "State.h"

#include <codecvt>

#include <magic_enum.hpp>
#include <pystring/pystring.h>

Expand Down Expand Up @@ -510,6 +512,12 @@ void State::SetPerfMarker(std::string_view title)
pPerf->SetMarker(std::wstring(title.begin(), title.end()).c_str());
}

void State::SetAdapterDescription(const std::wstring& description)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
adapterDescription = converter.to_bytes(description);
}

void State::UpdateSharedData()
{
{
Expand Down
3 changes: 3 additions & 0 deletions src/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class State
bool updateShader = true;
bool settingCustomShader = false;
RE::BSShader* currentShader = nullptr;
std::string adapterDescription = "";

uint32_t currentVertexDescriptor = 0;
uint32_t currentPixelDescriptor = 0;
Expand Down Expand Up @@ -101,6 +102,8 @@ class State
void EndPerfEvent();
void SetPerfMarker(std::string_view title);

void SetAdapterDescription(const std::wstring& description);

bool extendedFrameAnnotations = false;

uint lastVertexDescriptor = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/TruePBR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void SetupPBRLandscapeTextureParameters(BSLightingShaderMaterialPBRLandscape& ma

void TruePBR::DrawSettings()
{
if (ImGui::TreeNodeEx("PBR", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::CollapsingHeader("PBR", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) {
if (ImGui::TreeNodeEx("Texture Set Settings", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::BeginCombo("Texture Set", selectedPbrTextureSetName.c_str())) {
for (auto& [textureSetName, textureSet] : pbrTextureSets) {
Expand Down
31 changes: 31 additions & 0 deletions src/Upscaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ void Upscaling::DrawSettings()

// Slider for method selection
ImGui::SliderInt("Method", (int*)currentUpscaleMode, 0, availableModes, std::format("{}", upscaleModes[(uint)*currentUpscaleMode]).c_str());
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Disabled:\n"
"Disable all methods. Same as disabling Skyrim's TAA.\n"
"\n"
"Temporal Anti-Aliasing:\n"
"Uses Skyrim's TAA which uses frame history to smooth out jagged edges, reducing flickering and improving image stability.\n"
"\n"
"AMD FSR 3.1:\n"
"AMD's open-source FSR spatial upscaling algorithm designed to enhance performance while maintaining high visual quality.\n"
"\n"
"NVIDIA DLAA:\n"
"NVIDIA's Deep Learning Anti-Aliasing leverages AI to provide high-quality anti-aliasing without sacrificing performance. Requires NVIDIA RTX GPU.");
}

*currentUpscaleMode = std::min(availableModes, (uint)*currentUpscaleMode);
bTAA = *currentUpscaleMode != (uint)UpscaleMethod::kNONE;
Expand All @@ -57,6 +71,23 @@ void Upscaling::DrawSettings()
const char* dlssPresets[] = { "Default", "Preset A", "Preset B", "Preset C", "Preset D", "Preset E", "Preset F" };
ImGui::SliderInt("DLSS Preset", (int*)&settings.dlssPreset, 0, 6, std::format("{}", dlssPresets[(uint)settings.dlssPreset]).c_str());
settings.dlssPreset = std::min(6u, (uint)settings.dlssPreset);
if (auto _tt = Util::HoverTooltipWrapper()) {
ImGui::Text(
"Default:\n"
"Preset E\n\n"
"Preset A (intended for Perf/Balanced/Quality modes):\n"
"An older variant best suited to combat ghosting for elements with missing inputs (such as motion vectors)\n\n"
"Preset B (intended for Ultra Perf mode):\n"
"Similar to Preset A but for Ultra Performance mode\n\n"
"Preset C (intended for Perf/Balanced/Quality modes):\n"
"Preset which generally favors current frame information. Generally well-suited for fast-paced game content\n\n"
"Preset D (intended for Perf/Balanced/Quality modes):\n"
"Similar to Preset E. Preset E is generally recommended over Preset D.\n\n"
"Preset E (intended for Perf/Balanced/Quality modes):\n"
"The CS default preset. Default preset for Perf/Balanced/Quality mode. Generally favors image stability\n\n"
"Preset F (intended for Ultra Perf/DLAA modes):\n"
"The default preset for Ultra Perf and DLAA modes.");
}
}
}

Expand Down

0 comments on commit 33d284d

Please sign in to comment.