Skip to content
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
25 changes: 24 additions & 1 deletion src/Features/Skylighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ void Skylighting::PostPostLoad()
logger::info("[SKYLIGHTING] Hooking BSLightingShaderProperty::GetPrecipitationOcclusionMapRenderPassesImp");
stl::write_vfunc<0x2D, BSLightingShaderProperty_GetPrecipitationOcclusionMapRenderPassesImpl>(RE::VTABLE_BSLightingShaderProperty[0]);
stl::write_thunk_call<Main_Precipitation_RenderOcclusion>(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x3A1, 0x3A1, 0x2FA));
stl::write_thunk_call<SetViewFrustum>(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC));

if (REL::Module::IsVR())
stl::write_thunk_call<SetViewFrustumVR>(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC));
else
stl::write_thunk_call<SetViewFrustum>(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC));

MenuOpenCloseEventHandler::Register();
}

Expand Down Expand Up @@ -463,6 +468,24 @@ void Skylighting::SetViewFrustum::thunk(RE::NiCamera* a_camera, RE::NiFrustum* a
func(a_camera, a_frustum);
}

void Skylighting::SetViewFrustumVR::thunk(RE::NiCamera* a_camera, RE::NiFrustum* a_frustum, uint a_eyeIndex)
{
auto skylighting = globals::features::skylighting;

if (skylighting->inOcclusion) {
uint corner = skylighting->frameCount % 4;

float frustumSize = a_frustum->fTop;

a_frustum->fBottom = (corner == 0 || corner == 1) ? -frustumSize : 0.0f;
a_frustum->fLeft = (corner == 0 || corner == 2) ? -frustumSize : 0.0f;
a_frustum->fRight = (corner == 1 || corner == 3) ? frustumSize : 0.0f;
a_frustum->fTop = (corner == 2 || corner == 3) ? frustumSize : 0.0f;
}

func(a_camera, a_frustum, a_eyeIndex);
}

void Skylighting::RenderOcclusion()
{
auto shaderCache = globals::shaderCache;
Expand Down
6 changes: 6 additions & 0 deletions src/Features/Skylighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ struct Skylighting : Feature
static inline REL::Relocation<decltype(thunk)> func;
};

struct SetViewFrustumVR
{
static void thunk(RE::NiCamera* a_camera, RE::NiFrustum* a_frustum, uint a_eyeIndex);
static inline REL::Relocation<decltype(thunk)> func;
};

// Event handler
class MenuOpenCloseEventHandler : public RE::BSTEventSink<RE::MenuOpenCloseEvent>
{
Expand Down
68 changes: 33 additions & 35 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,43 +752,41 @@ namespace Hooks
logger::info("Hooking BSEffectShader");
stl::write_vfunc<0x6, EffectExtensions::BSEffectShader_SetupGeometry>(RE::VTABLE_BSEffectShader[0]);

if (!REL::Module::IsVR()) {
const auto renderPassCacheCtor = REL::VariantID(100720, 107500, 0x1340330);
const int32_t passCount = 4194240;
const int32_t passCountSE = 4194240 * 16;

const int32_t passSize = 4194240 * sizeof(RE::BSRenderPass);
const int32_t lightsCount = passCount * 16;
const int32_t lightsSize = lightsCount * sizeof(void*);
const int32_t lastPassIndex = passCount - 1;
const int32_t lastPassOffset =
(passCount - 1) * sizeof(RE::BSRenderPass);
const int32_t lastPassNextOffset =
(passCount - 1) * sizeof(RE::BSRenderPass) + offsetof(RE::BSRenderPass, next);
const auto renderPassCacheCtor = REL::VariantID(100720, 107500, 0x1340330);
const int32_t passCount = 4194240;
const int32_t passCountSE = 4194240 * 16;

const int32_t passSize = 4194240 * sizeof(RE::BSRenderPass);
const int32_t lightsCount = passCount * 16;
const int32_t lightsSize = lightsCount * sizeof(void*);
const int32_t lastPassIndex = passCount - 1;
const int32_t lastPassOffset =
(passCount - 1) * sizeof(RE::BSRenderPass);
const int32_t lastPassNextOffset =
(passCount - 1) * sizeof(RE::BSRenderPass) + offsetof(RE::BSRenderPass, next);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0x76).address(),
reinterpret_cast<const uint8_t*>(&lightsSize), 4);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xAD).address(),
reinterpret_cast<const uint8_t*>(&passSize), 4);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xCB).address(),
reinterpret_cast<const uint8_t*>(&lastPassIndex), 4);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xF0).address(),
reinterpret_cast<const uint8_t*>(&lastPassNextOffset), 4);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xFD).address(),
reinterpret_cast<const uint8_t*>(&lastPassOffset), 4);
if (REL::Module::IsAE()) {
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0x76).address(),
reinterpret_cast<const uint8_t*>(&lightsSize), 4);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xAD).address(),
reinterpret_cast<const uint8_t*>(&passSize), 4);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xCB).address(),
reinterpret_cast<const uint8_t*>(&lastPassIndex), 4);
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xF0).address(),
reinterpret_cast<const uint8_t*>(&lastPassNextOffset), 4);
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0x191).address(),
reinterpret_cast<const uint8_t*>(&passCount), 4);
} else {
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0xFD).address(),
reinterpret_cast<const uint8_t*>(&lastPassOffset), 4);
if (REL::Module::IsAE()) {
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0x191).address(),
reinterpret_cast<const uint8_t*>(&passCount), 4);
} else {
PatchMemory(
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0x191 - 2).address(),
reinterpret_cast<const uint8_t*>(&passCountSE), 4);
}
REL::Relocation<std::uintptr_t>(renderPassCacheCtor, 0x191 - 2).address(),
reinterpret_cast<const uint8_t*>(&passCountSE), 4);
}
}

Expand Down