Skip to content

Commit

Permalink
feat: maintain geometry list
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlum committed Dec 14, 2024
1 parent 2144b89 commit cd8bf2f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Features/LightLimitFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Feature.h"
#include "ShaderCache.h"
#include <Features/LightLimitFix/ParticleLights.h>
#include "Raytracing.h"

struct LightLimitFix : Feature
{
Expand Down Expand Up @@ -311,6 +312,8 @@ struct LightLimitFix : Feature
static void thunk(RE::NiNode* This)
{
GetSingleton()->CleanupParticleLights(This);
Raytracing::GetSingleton()->RemoveGeometry((RE::BSGeometry*)This);

func(This);
}
static inline REL::Relocation<decltype(thunk)> func;
Expand Down
23 changes: 22 additions & 1 deletion src/Raytracing.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Raytracing.h"

#include "Deferred.h"

void Raytracing::InitD3D12()
{
auto manager = RE::BSGraphics::Renderer::GetSingleton();
Expand Down Expand Up @@ -63,4 +65,23 @@ void Raytracing::OpenSharedHandles()
for (int i = 0; i < RE::RENDER_TARGET::kTOTAL; i++) {
renderTargetsD3D12[i] = ConvertD3D11TextureToD3D12(&renderer->GetRuntimeData().renderTargets[i]);
}
}
}

void Raytracing::UpdateGeometry(RE::BSGeometry* a_geometry)
{
if (Deferred::GetSingleton()->inWorld) {
auto it = geometries.find(a_geometry);
if (it == geometries.end()) {
geometries.insert(a_geometry);
// Insert Event
}
}
}

void Raytracing::RemoveGeometry(RE::BSGeometry* a_geometry)
{
if (geometries.erase(a_geometry))
{
// Remove Event
}
}
37 changes: 37 additions & 0 deletions src/Raytracing.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <unordered_set>
#include <eastl/set.h>

#include <d3d12.h>

#include <FidelityFX/host/backends/dx12/ffx_dx12.h>
Expand Down Expand Up @@ -29,6 +32,11 @@ class Raytracing

void OpenSharedHandles();

eastl::hash_set<RE::BSGeometry*> geometries;

void UpdateGeometry(RE::BSGeometry* a_geometry);
void RemoveGeometry(RE::BSGeometry* a_geometry);

struct RenderTargetDataD3D12
{
// D3D12 Resource
Expand All @@ -37,4 +45,33 @@ class Raytracing

RenderTargetDataD3D12 renderTargetsD3D12[RE::RENDER_TARGET::kTOTAL];
RenderTargetDataD3D12 ConvertD3D11TextureToD3D12(RE::BSGraphics::RenderTargetData* rtData);

struct BSLightingShader_SetupGeometry
{
static void thunk(RE::BSShader* This, RE::BSRenderPass* Pass, uint32_t RenderFlags)
{
func(This, Pass, RenderFlags);
GetSingleton()->UpdateGeometry(Pass->geometry);
}
static inline REL::Relocation<decltype(thunk)> func;
};

struct NiNode_Destroy
{
static void thunk(RE::NiNode* This)
{
GetSingleton()->RemoveGeometry((RE::BSGeometry*)This);
func(This);
}
static inline REL::Relocation<decltype(thunk)> func;
};

static void InstallHooks()
{
stl::write_vfunc<0x6, BSLightingShader_SetupGeometry>(RE::VTABLE_BSLightingShader[0]);

// stl::detour_thunk<NiNode_Destroy>(REL::RelocationID(68937, 70288));

logger::info("[Raytracing] Installed hooks");
}
};
2 changes: 2 additions & 0 deletions src/XSEPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "State.h"
#include "TruePBR.h"
#include "Upscaling.h"
#include "Raytracing.h"

#include "ENB/ENBSeriesAPI.h"

Expand Down Expand Up @@ -88,6 +89,7 @@ void MessageHandler(SKSE::MessagingInterface::Message* message)
}
Hooks::Install();
FrameAnnotations::OnPostPostLoad();
Raytracing::InstallHooks();

auto& shaderCache = SIE::ShaderCache::Instance();

Expand Down

0 comments on commit cd8bf2f

Please sign in to comment.