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 initial VR support #228

Merged
merged 1 commit into from
Mar 23, 2024
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
26 changes: 15 additions & 11 deletions src/Bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ void Bindings::SetupResources()
// Normal + Roughness
SetupRenderTarget(NORMALROUGHNESS, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R8G8B8A8_UNORM);


{
texDesc.Format = DXGI_FORMAT_R8_UNORM;
srvDesc.Format = texDesc.Format;
Expand Down Expand Up @@ -300,10 +299,13 @@ void Bindings::StartDeferred()
}

auto state = RE::BSGraphics::RendererShadowState::GetSingleton();
GET_INSTANCE_MEMBER(renderTargets, state)
GET_INSTANCE_MEMBER(setRenderTargetMode, state)
GET_INSTANCE_MEMBER(stateUpdateFlags, state)

// Backup original render targets
for (uint i = 0; i < 4; i++) {
forwardRenderTargets[i] = state->GetRuntimeData().renderTargets[i];
forwardRenderTargets[i] = renderTargets[i];
}

RE::RENDER_TARGET targets[6]{
Expand All @@ -316,17 +318,17 @@ void Bindings::StartDeferred()
};

for (uint i = 0; i < 6; i++) {
state->GetRuntimeData().renderTargets[i] = targets[i]; // We must use unused targets to be indexable
state->GetRuntimeData().setRenderTargetMode[i] = RE::BSGraphics::SetRenderTargetMode::SRTM_CLEAR; // Dirty from last frame, this calls ClearRenderTargetView once
renderTargets[i] = targets[i]; // We must use unused targets to be indexable
setRenderTargetMode[i] = RE::BSGraphics::SetRenderTargetMode::SRTM_CLEAR; // Dirty from last frame, this calls ClearRenderTargetView once
}

// Improved snow shader
if (forwardRenderTargets[3] != RE::RENDER_TARGET::kNONE) {
state->GetRuntimeData().renderTargets[6] = forwardRenderTargets[3]; // We must use unused targets to be indexable
state->GetRuntimeData().setRenderTargetMode[6] = RE::BSGraphics::SetRenderTargetMode::SRTM_CLEAR; // Dirty from last frame, this calls ClearRenderTargetView once
renderTargets[6] = forwardRenderTargets[3]; // We must use unused targets to be indexable
setRenderTargetMode[6] = RE::BSGraphics::SetRenderTargetMode::SRTM_CLEAR; // Dirty from last frame, this calls ClearRenderTargetView once
}

state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); // Run OMSetRenderTargets again
stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); // Run OMSetRenderTargets again

static BlendStates* blendStates = (BlendStates*)REL::RelocationID(524749, 411364).address();

Expand All @@ -336,7 +338,7 @@ void Bindings::StartDeferred()
blendStates->a[1][0][1][0] = deferredBlendStates[2];
blendStates->a[1][0][11][0] = deferredBlendStates[3];

state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND);
stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND);

deferredPass = true;
}
Expand Down Expand Up @@ -474,10 +476,12 @@ void Bindings::EndDeferred()
return;

auto state = RE::BSGraphics::RendererShadowState::GetSingleton();
GET_INSTANCE_MEMBER(renderTargets, state)
GET_INSTANCE_MEMBER(stateUpdateFlags, state)

// Do not render to our targets past this point
for (uint i = 0; i < 4; i++) {
state->GetRuntimeData().renderTargets[i] = forwardRenderTargets[i];
renderTargets[i] = forwardRenderTargets[i];
}

for (uint i = 4; i < 8; i++) {
Expand All @@ -489,7 +493,7 @@ void Bindings::EndDeferred()

DeferredPasses(); // Perform deferred passes and composite forward buffers

state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); // Run OMSetRenderTargets again
stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET); // Run OMSetRenderTargets again

static BlendStates* blendStates = (BlendStates*)REL::RelocationID(524749, 411364).address();

Expand All @@ -499,7 +503,7 @@ void Bindings::EndDeferred()
blendStates->a[1][0][1][0] = forwardBlendStates[2];
blendStates->a[1][0][11][0] = forwardBlendStates[3];

state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND);
stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_ALPHA_BLEND);

deferredPass = false;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Bindings
ID3D11BlendState* deferredBlendStates[4];
ID3D11BlendState* forwardBlendStates[4];
RE::RENDER_TARGET forwardRenderTargets[4];

ID3D11ComputeShader* deferredNormalMappingShadowsCS = nullptr;
ID3D11ComputeShader* deferredCompositeCS = nullptr;

Expand Down Expand Up @@ -84,7 +84,7 @@ class Bindings
static void thunk(RE::BSBatchRenderer* This, uint32_t StartRange, uint32_t EndRanges, uint32_t RenderFlags, int GeometryGroup)
{
// Here is where the first opaque objects start rendering
GetSingleton()->StartDeferred();
GetSingleton()->StartDeferred();
func(This, StartRange, EndRanges, RenderFlags, GeometryGroup); // RenderBatches
}
static inline REL::Relocation<decltype(thunk)> func;
Expand All @@ -94,7 +94,7 @@ class Bindings
{
static void thunk(RE::BSShaderAccumulator* This, uint32_t RenderFlags)
{
func(This, RenderFlags);
func(This, RenderFlags);
// After this point, water starts rendering
GetSingleton()->EndDeferred();
}
Expand All @@ -113,13 +113,13 @@ class Bindings

static void Install()
{
stl::write_thunk_call<Main_RenderWorld>(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x831, 0x841));
stl::write_thunk_call<Main_RenderWorld>(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x831, 0x841, 0x791));

stl::write_thunk_call<Main_RenderWorld_Start>(REL::RelocationID(99938, 106583).address() + REL::Relocate(0x8E, 0x84));
stl::write_thunk_call<Main_RenderWorld_End>(REL::RelocationID(99938, 106583).address() + REL::Relocate(0x319, 0x308));
stl::write_thunk_call<Main_RenderWorld_End>(REL::RelocationID(99938, 106583).address() + REL::Relocate(0x319, 0x308, 0x321));

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

logger::info("[Bindings] Installed hooks");
}
};
Expand Down
Loading