-
Notifications
You must be signed in to change notification settings - Fork 133
feat(VR): add DeepDVC dynamic vibrance #2091
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
Open
YtzyFvra
wants to merge
5
commits into
community-shaders:dev
Choose a base branch
from
YtzyFvra:feature/dvc
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d4197a6
feat(VR): add DeepDVC dynamic vibrance post-process
ecffbe4
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] ca52c8e
Merge branch 'dev' into feature/dvc
doodlum cdadf28
fix(DeepDVC): default mode to Off, remove unused featuresToLoadVR
40b1cf9
fix(DeepDVC): add null check for slSetTag before use
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [Info] | ||
| Version = 1-0-0 |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| #include "DeepDVC.h" | ||
|
|
||
| #include "../Globals.h" | ||
| #include "Upscaling.h" | ||
|
|
||
| #include "RE/B/BSShaderRenderTargets.h" | ||
| #include "RE/R/Renderer.h" | ||
|
|
||
| // NVIDIA Deep Learning Video Clarity (DeepDVC) | ||
| // AI-based post-process filter that significantly enhances color vibrance and | ||
| // combats overexposure. Works well alongside traditional post-processing | ||
| // (tested with jiayev/pp branch: greatly improves dark-area detail without | ||
| // blowing out the overall image). | ||
| // Run after tone mapping and before film grain when film grain exists. | ||
| // | ||
| // Currently VR-only due to lack of an SE/AE test client; flat-screen | ||
| // adaptation should be straightforward. | ||
|
|
||
| bool DeepDVC::IsSupported() const | ||
| { | ||
| auto& streamline = globals::features::upscaling.streamline; | ||
| return globals::game::isVR && streamline.featureDeepDVC; | ||
| } | ||
|
|
||
| bool DeepDVC::IsInMenu() const | ||
| { | ||
| return IsSupported(); | ||
| } | ||
|
|
||
| void DeepDVC::RestoreDefaultSettings() | ||
| { | ||
| settings = Settings(); | ||
| } | ||
|
|
||
| void DeepDVC::LoadSettings(json& o_json) | ||
| { | ||
| settings = o_json; | ||
| settings.mode = std::clamp(settings.mode, 0u, 1u); | ||
| settings.intensity = std::clamp(settings.intensity, 0.0f, 1.0f); | ||
| settings.saturationBoost = std::clamp(settings.saturationBoost, 0.0f, 1.0f); | ||
| } | ||
|
|
||
| void DeepDVC::SaveSettings(json& o_json) | ||
| { | ||
| o_json = settings; | ||
| } | ||
|
|
||
| void DeepDVC::DrawSettings() | ||
| { | ||
| if (ImGui::TreeNodeEx("DeepDVC Settings", ImGuiTreeNodeFlags_DefaultOpen)) { | ||
| const char* modes[] = { "Off", "On" }; | ||
| ImGui::SliderInt("Mode", (int*)&settings.mode, 0, 1, modes[settings.mode]); | ||
|
YtzyFvra marked this conversation as resolved.
|
||
|
|
||
| if (settings.mode == 1) { | ||
| if (missingInput) { | ||
| ImGui::TextColored({ 1.0f, 0.4f, 0.4f, 1.0f }, "Input render target not found."); | ||
| } | ||
|
|
||
| ImGui::SliderFloat("Intensity", &settings.intensity, 0.0f, 1.0f, "%.2f"); | ||
| if (ImGui::IsItemHovered()) { | ||
| ImGui::SetTooltip("Controls how strong or subtle the filter effect will be on an image."); | ||
| } | ||
|
|
||
| ImGui::SliderFloat("Saturation Boost", &settings.saturationBoost, 0.0f, 1.0f, "%.2f"); | ||
| if (ImGui::IsItemHovered()) { | ||
| ImGui::SetTooltip("This feature provides RTX Dynamic Vibrance Control, using AI to enhance digital vibrance and adjust color saturation adaptively based on game content, making them more vibrant and eye-catching."); | ||
| } | ||
| } | ||
|
|
||
| ImGui::TreePop(); | ||
| } | ||
| } | ||
|
|
||
| void DeepDVC::Evaluate() | ||
| { | ||
| if (!IsSupported()) | ||
| return; | ||
|
|
||
| auto& upscaling = globals::features::upscaling; | ||
| if (!upscaling.streamline.initialized) | ||
| return; | ||
|
|
||
| if (settings.mode == 0) { | ||
| missingInput = false; | ||
| return; | ||
| } | ||
|
|
||
| auto context = globals::d3d::context; | ||
| auto device = globals::d3d::device; | ||
| auto viewport = upscaling.streamline.viewport; | ||
|
|
||
| if (!context || !device) | ||
| return; | ||
|
|
||
| if (!upscaling.streamline.EnsureFrameToken()) | ||
| return; | ||
|
|
||
| auto* frameToken = upscaling.streamline.frameToken; | ||
| if (!frameToken) | ||
| return; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| ID3D11Texture2D* targetBuffer = nullptr; | ||
|
|
||
| if (auto renderer = globals::game::renderer) { | ||
| auto& rt = renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kIMAGESPACE_TEMP_COPY]; | ||
| targetBuffer = rt.texture; | ||
| } | ||
|
|
||
| if (!targetBuffer) { | ||
| missingInput = true; | ||
| return; | ||
| } | ||
|
|
||
| missingInput = false; | ||
|
|
||
| D3D11_TEXTURE2D_DESC desc; | ||
| targetBuffer->GetDesc(&desc); | ||
|
|
||
| sl::Extent extent{}; | ||
| extent.width = desc.Width; | ||
| extent.height = desc.Height; | ||
|
|
||
| if (proxyBuffer) { | ||
| D3D11_TEXTURE2D_DESC proxyDesc; | ||
| proxyBuffer->GetDesc(&proxyDesc); | ||
| if (proxyDesc.Width != desc.Width || proxyDesc.Height != desc.Height || proxyDesc.Format != desc.Format) { | ||
| proxyBuffer->Release(); | ||
| proxyBuffer = nullptr; | ||
| } | ||
| } | ||
|
YtzyFvra marked this conversation as resolved.
|
||
|
|
||
| if (!proxyBuffer) { | ||
| D3D11_TEXTURE2D_DESC proxyDesc = desc; | ||
| proxyDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS; | ||
| proxyDesc.Usage = D3D11_USAGE_DEFAULT; | ||
| proxyDesc.CPUAccessFlags = 0; | ||
| proxyDesc.MiscFlags = 0; | ||
|
|
||
| HRESULT hr = device->CreateTexture2D(&proxyDesc, nullptr, &proxyBuffer); | ||
| if (FAILED(hr)) { | ||
| logger::error("[DeepDVC] Failed to create proxy buffer. HR = {:x}", (uint32_t)hr); | ||
| return; | ||
| } | ||
| logger::info("[DeepDVC] Created UAV-compatible proxy buffer {}x{}", desc.Width, desc.Height); | ||
| } | ||
|
|
||
| if (!proxyBuffer || !targetBuffer) { | ||
| logger::error("[DeepDVC] Invalid buffer pointers for resource copy"); | ||
| return; | ||
| } | ||
| context->CopyResource(proxyBuffer, targetBuffer); | ||
|
|
||
| sl::Resource colorOut = { sl::ResourceType::eTex2d, proxyBuffer, nullptr, nullptr, 0 }; | ||
| sl::ResourceTag colorOutTag = sl::ResourceTag{ &colorOut, sl::kBufferTypeScalingOutputColor, sl::ResourceLifecycle::eOnlyValidNow, &extent }; | ||
|
|
||
| sl::ResourceTag inputs[] = { colorOutTag }; | ||
| if (!upscaling.streamline.slSetTag) { | ||
| logger::warn("[DeepDVC] slSetTag not available"); | ||
| return; | ||
| } | ||
| upscaling.streamline.slSetTag(viewport, inputs, _countof(inputs), context); | ||
|
|
||
| sl::DeepDVCOptions options{}; | ||
| options.mode = (sl::DeepDVCMode)settings.mode; | ||
| options.intensity = settings.intensity; | ||
| options.saturationBoost = settings.saturationBoost; | ||
|
|
||
| if (upscaling.streamline.slDeepDVCSetOptions) { | ||
| sl::Result res = upscaling.streamline.slDeepDVCSetOptions(viewport, options); | ||
| if (res != sl::Result::eOk) { | ||
| logger::warn("[DeepDVC] slDeepDVCSetOptions failed: {}", magic_enum::enum_name(res)); | ||
| } | ||
| } | ||
|
|
||
| const sl::BaseStructure* inputsEval[] = { &viewport }; | ||
| if (upscaling.streamline.slEvaluateFeature) { | ||
| sl::Result res = upscaling.streamline.slEvaluateFeature(sl::kFeatureDeepDVC, *frameToken, inputsEval, _countof(inputsEval), context); | ||
| if (res != sl::Result::eOk) { | ||
| static int failCount = 0; | ||
| if (failCount < 100) { | ||
| logger::warn("[DeepDVC] slEvaluateFeature failed: {}", magic_enum::enum_name(res)); | ||
| failCount++; | ||
| } | ||
| } | ||
|
YtzyFvra marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if (proxyBuffer && targetBuffer) { | ||
| context->CopyResource(targetBuffer, proxyBuffer); | ||
| } | ||
|
YtzyFvra marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // ── vtable hook: run DeepDVC after tonemap ────────────────────── | ||
|
|
||
| namespace | ||
| { | ||
| template <RE::ImageSpaceManager::ImageSpaceEffectEnum EffectType> | ||
| struct TonemapHook | ||
| { | ||
| static void thunk(void* imageSpaceShader, RE::BSTriShape* shape, RE::ImageSpaceEffectParam* param) | ||
| { | ||
| func(imageSpaceShader, shape, param); | ||
| globals::features::deepDVC.Evaluate(); | ||
| } | ||
| static inline REL::Relocation<decltype(thunk)> func; | ||
| }; | ||
| } | ||
|
|
||
| void DeepDVC::PostPostLoad() | ||
| { | ||
| if (!globals::game::isVR) | ||
| return; | ||
|
|
||
| stl::write_vfunc<0x1, | ||
| TonemapHook<RE::ImageSpaceManager::ISHDRTonemapBlendCinematic>>( | ||
| RE::VTABLE_BSImagespaceShaderHDRTonemapBlendCinematic[3]); | ||
| stl::write_vfunc<0x1, | ||
| TonemapHook<RE::ImageSpaceManager::ISHDRTonemapBlendCinematicFade>>( | ||
| RE::VTABLE_BSImagespaceShaderHDRTonemapBlendCinematicFade[3]); | ||
|
|
||
| logger::info("[DeepDVC] Tonemap hooks installed"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #pragma once | ||
|
|
||
| #include "../Feature.h" | ||
| #include "Upscaling/Streamline.h" | ||
|
|
||
| struct DeepDVC : public Feature | ||
| { | ||
| public: | ||
| virtual inline std::string GetName() override { return "DeepDVC"; } | ||
| virtual inline std::string GetShortName() override { return "DeepDVC"; } | ||
| virtual inline std::string_view GetCategory() const override { return "Display"; } | ||
|
|
||
| virtual inline std::pair<std::string, std::vector<std::string>> GetFeatureSummary() override | ||
| { | ||
| return { | ||
| "RTX Dynamic Vibrance uses AI to enhance digital vibrance in real-time.", | ||
| { "Improves visual clarity", | ||
| "Adjusts color saturation adaptively", | ||
| "Requires NVIDIA RTX GPU" } | ||
| }; | ||
| } | ||
|
|
||
| virtual inline bool SupportsVR() override { return true; } | ||
| virtual inline bool IsCore() const override { return false; } | ||
| virtual bool IsInMenu() const override; | ||
| virtual void PostPostLoad() override; | ||
|
|
||
| struct Settings | ||
| { | ||
| uint32_t mode = 0; | ||
| float intensity = 0.3f; | ||
| float saturationBoost = 0.2f; | ||
|
|
||
| NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Settings, mode, intensity, saturationBoost); | ||
| } settings; | ||
|
|
||
| void Evaluate(); | ||
|
|
||
| virtual void RestoreDefaultSettings() override; | ||
| virtual void LoadSettings(json& o_json) override; | ||
| virtual void SaveSettings(json& o_json) override; | ||
| virtual void DrawSettings() override; | ||
|
|
||
| ~DeepDVC() | ||
| { | ||
| if (proxyBuffer) { | ||
| proxyBuffer->Release(); | ||
| proxyBuffer = nullptr; | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| bool IsSupported() const; | ||
| ID3D11Texture2D* proxyBuffer = nullptr; | ||
| bool missingInput = false; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.