diff --git a/src/Features/Skylighting.cpp b/src/Features/Skylighting.cpp index a2c7e5679e..8b9545338b 100644 --- a/src/Features/Skylighting.cpp +++ b/src/Features/Skylighting.cpp @@ -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(REL::RelocationID(35560, 36559).address() + REL::Relocate(0x3A1, 0x3A1, 0x2FA)); - stl::write_thunk_call(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC)); + + if (REL::Module::IsVR()) + stl::write_thunk_call(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC)); + else + stl::write_thunk_call(REL::RelocationID(25643, 26185).address() + REL::Relocate(0x5D9, 0x59D, 0x5DC)); + MenuOpenCloseEventHandler::Register(); } @@ -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; diff --git a/src/Features/Skylighting.h b/src/Features/Skylighting.h index 354c9ff28c..a277d414b9 100644 --- a/src/Features/Skylighting.h +++ b/src/Features/Skylighting.h @@ -109,6 +109,12 @@ struct Skylighting : Feature static inline REL::Relocation func; }; + struct SetViewFrustumVR + { + static void thunk(RE::NiCamera* a_camera, RE::NiFrustum* a_frustum, uint a_eyeIndex); + static inline REL::Relocation func; + }; + // Event handler class MenuOpenCloseEventHandler : public RE::BSTEventSink { diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 7e1f749ebb..fe4c2283c2 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -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(renderPassCacheCtor, 0x76).address(), + reinterpret_cast(&lightsSize), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xAD).address(), + reinterpret_cast(&passSize), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xCB).address(), + reinterpret_cast(&lastPassIndex), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xF0).address(), + reinterpret_cast(&lastPassNextOffset), 4); + PatchMemory( + REL::Relocation(renderPassCacheCtor, 0xFD).address(), + reinterpret_cast(&lastPassOffset), 4); + if (REL::Module::IsAE()) { PatchMemory( - REL::Relocation(renderPassCacheCtor, 0x76).address(), - reinterpret_cast(&lightsSize), 4); - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xAD).address(), - reinterpret_cast(&passSize), 4); - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xCB).address(), - reinterpret_cast(&lastPassIndex), 4); - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xF0).address(), - reinterpret_cast(&lastPassNextOffset), 4); + REL::Relocation(renderPassCacheCtor, 0x191).address(), + reinterpret_cast(&passCount), 4); + } else { PatchMemory( - REL::Relocation(renderPassCacheCtor, 0xFD).address(), - reinterpret_cast(&lastPassOffset), 4); - if (REL::Module::IsAE()) { - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0x191).address(), - reinterpret_cast(&passCount), 4); - } else { - PatchMemory( - REL::Relocation(renderPassCacheCtor, 0x191 - 2).address(), - reinterpret_cast(&passCountSE), 4); - } + REL::Relocation(renderPassCacheCtor, 0x191 - 2).address(), + reinterpret_cast(&passCountSE), 4); } }