diff --git a/Build Release.bat b/Build Release.bat index c46d364f27..62a75e0872 100644 --- a/Build Release.bat +++ b/Build Release.bat @@ -2,7 +2,7 @@ RMDIR dist /S /Q -cmake -S . --preset=FLATRIM --check-stamp-file "build\CMakeFiles\generate.stamp" +cmake -S . --preset=ALL --check-stamp-file "build\CMakeFiles\generate.stamp" if %ERRORLEVEL% NEQ 0 exit 1 cmake --build build --config Release if %ERRORLEVEL% NEQ 0 exit 1 diff --git a/extern/CommonLibSSE-NG b/extern/CommonLibSSE-NG index 1abf78d62b..887c11060c 160000 --- a/extern/CommonLibSSE-NG +++ b/extern/CommonLibSSE-NG @@ -1 +1 @@ -Subproject commit 1abf78d62b6e502f4461793a911eca9e1c44175c +Subproject commit 887c11060ce7866e4c6b6c7e749a3b8404d42d2e diff --git a/src/Features/Clustered.cpp b/src/Features/Clustered.cpp index 32942b53cf..9c58c4954a 100644 --- a/src/Features/Clustered.cpp +++ b/src/Features/Clustered.cpp @@ -61,10 +61,10 @@ void Clustered::UpdateLights() RE::NiPoint3 eyePosition{}; if (REL::Module::IsVR()) { // find center of eye position - eyePosition = state->GetVRRuntimeData2().posAdjust.getEye() + state->GetVRRuntimeData2().posAdjust.getEye(1); + eyePosition = state->GetVRRuntimeData().posAdjust.getEye() + state->GetVRRuntimeData().posAdjust.getEye(1); eyePosition /= 2; } else - eyePosition = state->GetRuntimeData2().posAdjust.getEye(); + eyePosition = state->GetRuntimeData().posAdjust.getEye(); worldPos = worldPos - eyePosition; logger::trace("Set {}light {} at ({} {} {}) because of eye ({} {} {})", bsShadowLight ? "shadow" : "", niLight->name, worldPos.x, worldPos.y, worldPos.z, @@ -75,8 +75,10 @@ void Clustered::UpdateLights() position.y = worldPos.y; position.z = worldPos.z; light.positionWS = XMLoadFloat3(&position); - light.positionVS = XMVector3TransformCoord(light.positionWS, state->GetVRRuntimeData2().cameraData.getEye().viewMat); - + if (!REL::Module::IsVR()) + light.positionVS = XMVector3TransformCoord(light.positionWS, state->GetRuntimeData().cameraData.getEye().viewMat); + else + light.positionVS = XMVector3TransformCoord(light.positionWS, state->GetVRRuntimeData().cameraData.getEye().viewMat); light.radius = niLight->GetLightRuntimeData().radius.x; light.active = true; diff --git a/src/Features/DistantTreeLighting.cpp b/src/Features/DistantTreeLighting.cpp index 31cf0f487d..895c913330 100644 --- a/src/Features/DistantTreeLighting.cpp +++ b/src/Features/DistantTreeLighting.cpp @@ -105,15 +105,16 @@ void DistantTreeLighting::ModifyDistantTree(const RE::BSShader*, const uint32_t RE::NiPoint3 eyePosition{}; if (REL::Module::IsVR()) { // find center of eye position - eyePosition = state->GetVRRuntimeData2().posAdjust.getEye() + state->GetVRRuntimeData2().posAdjust.getEye(1); + eyePosition = state->GetVRRuntimeData().posAdjust.getEye() + state->GetVRRuntimeData().posAdjust.getEye(1); eyePosition /= 2; } else - eyePosition = state->GetRuntimeData2().posAdjust.getEye(); + eyePosition = state->GetRuntimeData().posAdjust.getEye(); perPassData.EyePosition.x = position.x - eyePosition.x; perPassData.EyePosition.y = position.y - eyePosition.y; perPassData.EyePosition.z = position.z - eyePosition.z; - if (auto sunLight = (NiDirectionalLight*)accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get()) { + auto sunLight = skyrim_cast(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get()); + if (sunLight) { auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton(); perPassData.DirLightScale = imageSpaceManager->data.baseData.hdr.sunlightScale * sunLight->GetLightRuntimeData().fade; @@ -177,8 +178,10 @@ void DistantTreeLighting::Load(json& o_json) if (auto value = ini.GetValue("Info", "Version")) { enabled = true; version = value; + logger::info("TreeLODLighting.ini successfully loaded"); } else { enabled = false; + logger::warn("TreeLODLighting.ini not successfully loaded"); } } diff --git a/src/Features/GrassCollision.cpp b/src/Features/GrassCollision.cpp index c3391f3c9c..69e9804144 100644 --- a/src/Features/GrassCollision.cpp +++ b/src/Features/GrassCollision.cpp @@ -128,10 +128,10 @@ void GrassCollision::UpdateCollisions() RE::NiPoint3 eyePosition{}; if (REL::Module::IsVR()) { // find center of eye position - eyePosition = state->GetVRRuntimeData2().posAdjust.getEye() + state->GetVRRuntimeData2().posAdjust.getEye(1); + eyePosition = state->GetVRRuntimeData().posAdjust.getEye() + state->GetVRRuntimeData().posAdjust.getEye(1); eyePosition /= 2; } else - eyePosition = state->GetRuntimeData2().posAdjust.getEye(); + eyePosition = state->GetRuntimeData().posAdjust.getEye(); data.centre.x = centerPos.x - eyePosition.x; data.centre.y = centerPos.y - eyePosition.y; data.centre.z = centerPos.z - eyePosition.z; @@ -202,10 +202,10 @@ void GrassCollision::ModifyGrass(const RE::BSShader*, const uint32_t) RE::NiPoint3 eyePosition{}; if (REL::Module::IsVR()) { // find center of eye position - eyePosition = state->GetVRRuntimeData2().posAdjust.getEye() + state->GetVRRuntimeData2().posAdjust.getEye(1); + eyePosition = state->GetVRRuntimeData().posAdjust.getEye() + state->GetVRRuntimeData().posAdjust.getEye(1); eyePosition /= 2; } else - eyePosition = state->GetRuntimeData2().posAdjust.getEye(); + eyePosition = state->GetRuntimeData().posAdjust.getEye(); perFrameData.boundCentre.x = bound.center.x - eyePosition.x; perFrameData.boundCentre.y = bound.center.y - eyePosition.y; perFrameData.boundCentre.z = bound.center.z - eyePosition.z; @@ -257,8 +257,10 @@ void GrassCollision::Load(json& o_json) if (auto value = ini.GetValue("Info", "Version")) { enabledFeature = true; version = value; + logger::info("GrassCollision.ini successfully loaded"); } else { enabledFeature = false; + logger::warn("GrassCollision.ini not successfully loaded"); } } diff --git a/src/Features/GrassLighting.cpp b/src/Features/GrassLighting.cpp index 3de0f0a0fe..bb6d28c917 100644 --- a/src/Features/GrassLighting.cpp +++ b/src/Features/GrassLighting.cpp @@ -64,10 +64,10 @@ void GrassLighting::ModifyGrass(const RE::BSShader*, const uint32_t descriptor) RE::NiPoint3 eyePosition{}; if (REL::Module::IsVR()) { // find center of eye position - eyePosition = state->GetVRRuntimeData2().posAdjust.getEye() + state->GetVRRuntimeData2().posAdjust.getEye(1); + eyePosition = state->GetVRRuntimeData().posAdjust.getEye() + state->GetVRRuntimeData().posAdjust.getEye(1); eyePosition /= 2; } else - eyePosition = state->GetRuntimeData2().posAdjust.getEye(); + eyePosition = state->GetRuntimeData().posAdjust.getEye(); perFrameData.EyePosition.x = position.x - eyePosition.x; perFrameData.EyePosition.y = position.y - eyePosition.y; perFrameData.EyePosition.z = position.z - eyePosition.z; @@ -123,8 +123,10 @@ void GrassLighting::Load(json& o_json) if (auto value = ini.GetValue("Info", "Version")) { enabled = true; version = value; + logger::info("GrassLighting.ini successfully loaded"); } else { enabled = false; + logger::warn("GrassLighting.ini not successfully loaded"); } } diff --git a/src/Features/ScreenSpaceShadows.cpp b/src/Features/ScreenSpaceShadows.cpp index eeb04a81fc..32c013ff1e 100644 --- a/src/Features/ScreenSpaceShadows.cpp +++ b/src/Features/ScreenSpaceShadows.cpp @@ -3,6 +3,8 @@ #include "State.h" #include "Util.h" +using RE::RENDER_TARGETS; + void ScreenSpaceShadows::DrawSettings() { if (ImGui::BeginTabItem("Screen-Space Shadows")) { @@ -115,8 +117,7 @@ class NiDirectionalLight : public RE::NiLight void ScreenSpaceShadows::ClearComputeShader() { - if (raymarchProgram) - { + if (raymarchProgram) { raymarchProgram->Release(); raymarchProgram = nullptr; } @@ -132,22 +133,28 @@ void ScreenSpaceShadows::ClearComputeShader() ID3D11ComputeShader* ScreenSpaceShadows::GetComputeShader() { - if (!raymarchProgram) + if (!raymarchProgram) { + logger::debug("Compiling raymarchProgram"); raymarchProgram = (ID3D11ComputeShader*)Util::CompileShader(L"Data\\Shaders\\ScreenSpaceShadows\\RaymarchCS.hlsl", {}, "cs_5_0"); + } return raymarchProgram; } ID3D11ComputeShader* ScreenSpaceShadows::GetComputeShaderHorizontalBlur() { - if (!horizontalBlurProgram) + if (!horizontalBlurProgram) { + logger::debug("Compiling horizontalBlurProgram"); horizontalBlurProgram = (ID3D11ComputeShader*)Util::CompileShader(L"Data\\Shaders\\ScreenSpaceShadows\\FilterCS.hlsl", { { "HORIZONTAL", "" } }, "cs_5_0"); + } return horizontalBlurProgram; } ID3D11ComputeShader* ScreenSpaceShadows::GetComputeShaderVerticalBlur() { - if (!verticalBlurProgram) + if (!verticalBlurProgram) { verticalBlurProgram = (ID3D11ComputeShader*)Util::CompileShader(L"Data\\Shaders\\ScreenSpaceShadows\\FilterCS.hlsl", { { "VERTICAL", "" } }, "cs_5_0"); + logger::debug("Compiling verticalBlurProgram"); + } return verticalBlurProgram; } @@ -158,14 +165,16 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) auto context = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().context; - auto accumulator = BSGraphics::BSShaderAccumulator::GetCurrentAccumulator(); - - if (auto sunLight = (NiDirectionalLight*)accumulator->m_ActiveShadowSceneNode->sunLight->light.get()) { - auto renderer = BSGraphics::Renderer::QInstance(); + auto accumulator = RE::BSGraphics::BSShaderAccumulator::GetCurrentAccumulator(); + auto sunLight = skyrim_cast(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get()); + if (sunLight) { + auto renderer = RE::BSGraphics::Renderer::GetSingleton(); if (!screenSpaceShadowsTexture) { { - auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + logger::debug("Creating screenSpaceShadowsTexture"); + + auto device = renderer->GetRuntimeData().forwarder; D3D11_SAMPLER_DESC samplerDesc = {}; samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; @@ -179,10 +188,10 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) } { - auto shadowMask = renderer->pRenderTargets[RENDER_TARGET_SHADOW_MASK]; + auto shadowMask = renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kSHADOW_MASK]; D3D11_TEXTURE2D_DESC texDesc{}; - shadowMask.Texture->GetDesc(&texDesc); + shadowMask.texture->GetDesc(&texDesc); texDesc.Format = DXGI_FORMAT_R16_FLOAT; texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_RENDER_TARGET; screenSpaceShadowsTexture = new Texture2D(texDesc); @@ -206,11 +215,11 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) } } - auto shadowState = BSGraphics::RendererShadowState::QInstance(); + auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton(); bool enableSSS = true; - if (shadowState->m_CubeMapRenderTarget == RENDER_TARGET_CUBEMAP_REFLECTIONS) { + if (shadowState->GetRuntimeData().cubeMapRenderTarget == RE::RENDER_TARGETS_CUBEMAP::kREFLECTIONS) { enableSSS = false; } else if (!renderedScreenCamera && enabled) { @@ -249,9 +258,12 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) data.RcpBufferDim.x = 1.0f / data.BufferDim.x; data.RcpBufferDim.y = 1.0f / data.BufferDim.y; + if (REL::Module::IsVR()) + data.ProjMatrix = shadowState->GetVRRuntimeData().cameraData.getEye().projMat; + else + data.ProjMatrix = shadowState->GetRuntimeData().cameraData.getEye().projMat; - data.ProjMatrix = shadowState->m_CameraData.m_ProjMat; - data.InvProjMatrix = XMMatrixInverse(nullptr, shadowState->m_CameraData.m_ProjMat); + data.InvProjMatrix = XMMatrixInverse(nullptr, data.ProjMatrix); data.DynamicRes.x = viewport->GetRuntimeData().dynamicResolutionCurrentWidthScale; data.DynamicRes.y = viewport->GetRuntimeData().dynamicResolutionCurrentHeightScale; @@ -264,12 +276,15 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) position.x = -direction.x; position.y = -direction.y; position.z = -direction.z; + auto viewMatrix = shadowState->GetRuntimeData().cameraData.getEye().viewMat; + if (REL::Module::IsVR()) + viewMatrix = shadowState->GetVRRuntimeData().cameraData.getEye().viewMat; auto invDirLightDirectionWS = XMLoadFloat3(&position); - data.InvDirLightDirectionVS = XMVector3TransformCoord(invDirLightDirectionWS, shadowState->m_CameraData.m_ViewMat); + data.InvDirLightDirectionVS = XMVector3TransformCoord(invDirLightDirectionWS, viewMatrix); data.ShadowDistance = 10000.0f; - + data.Settings = settings; raymarchCB->Update(data); @@ -280,9 +295,9 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) context->CSSetSamplers(0, 1, &computeSampler); - auto depth = renderer->pDepthStencils[DEPTH_STENCIL_POST_ZPREPASS_COPY]; + auto depth = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kPOST_ZPREPASS_COPY]; - ID3D11ShaderResourceView* view = depth.DepthSRV; + ID3D11ShaderResourceView* view = depth.depthSRV; context->CSSetShaderResources(0, 1, &view); ID3D11UnorderedAccessView* uav = screenSpaceShadowsTexture->uav.get(); @@ -357,13 +372,13 @@ void ScreenSpaceShadows::ModifyLighting(const RE::BSShader*, const uint32_t) } PerPass data{}; - data.EnableSSS = enableSSS && shadowState->m_RasterStateCullMode <= 1 && enabled; + data.EnableSSS = enableSSS && shadowState->GetRuntimeData().rasterStateCullMode <= 1 && enabled; perPass->Update(data); if (renderedScreenCamera) { - auto shadowMask = renderer->pDepthStencils[DEPTH_STENCIL_POST_ZPREPASS_COPY]; + auto shadowMask = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGET_DEPTHSTENCIL::kPOST_ZPREPASS_COPY]; ID3D11ShaderResourceView* views[2]{}; - views[0] = shadowMask.DepthSRV; + views[0] = shadowMask.depthSRV; views[1] = screenSpaceShadowsTexture->srv.get(); context->PSSetShaderResources(20, ARRAYSIZE(views), views); } @@ -426,8 +441,10 @@ void ScreenSpaceShadows::Load(json& o_json) if (auto value = ini.GetValue("Info", "Version")) { enabledFeature = true; version = value; + logger::info("ScreenSpaceShadows.ini successfully loaded"); } else { enabledFeature = false; + logger::warn("ScreenSpaceShadows.ini not successfully loaded"); } } diff --git a/src/Menu.cpp b/src/Menu.cpp index aa68cb9936..1d0c05ff56 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -156,7 +156,7 @@ RE::BSEventNotifyControl Menu::ProcessEvent(RE::InputEvent* const* a_event, RE:: IsEnabled = !IsEnabled; if (const auto controlMap = RE::ControlMap::GetSingleton()) { - controlMap->ignoreKeyboardMouse = IsEnabled; + controlMap->GetRuntimeData().ignoreKeyboardMouse = IsEnabled; } } else diff --git a/src/RE/BSGraphics.h b/src/RE/BSGraphics.h index 1c77dba719..4922cb01a8 100644 --- a/src/RE/BSGraphics.h +++ b/src/RE/BSGraphics.h @@ -22,6 +22,19 @@ namespace BSGraphics char _pad0[0x8]; }; static_assert(sizeof(ViewData) == 0x250); + static_assert(offsetof(ViewData, m_ViewUp) == 0); + static_assert(offsetof(ViewData, m_ViewRight) == 0x10); + static_assert(offsetof(ViewData, m_ViewDir) == 0x20); + static_assert(offsetof(ViewData, m_ViewMat) == 0x30); + static_assert(offsetof(ViewData, m_ProjMat) == 0x70); + static_assert(offsetof(ViewData, m_ViewProjMat) == 0xb0); + static_assert(offsetof(ViewData, m_UnknownMat1) == 0xf0); + static_assert(offsetof(ViewData, m_ViewProjMatrixUnjittered) == 0x130); + static_assert(offsetof(ViewData, m_PreviousViewProjMatrixUnjittered) == 0x170); + static_assert(offsetof(ViewData, m_ProjMatrixUnjittered) == 0x1b0); + static_assert(offsetof(ViewData, m_UnknownMat2) == 0x1f0); + static_assert(offsetof(ViewData, m_ViewPort) == 0x230); + static_assert(offsetof(ViewData, m_ViewDepthRange) == 0x240); struct CameraStateData { diff --git a/src/RE/BSGraphicsTypes.h b/src/RE/BSGraphicsTypes.h index fe8410ef85..a4b6df5e90 100644 --- a/src/RE/BSGraphicsTypes.h +++ b/src/RE/BSGraphicsTypes.h @@ -584,17 +584,32 @@ namespace BSGraphics uint64_t m_VertexDesc; VertexShader* m_CurrentVertexShader; PixelShader* m_CurrentPixelShader; - D3D11_PRIMITIVE_TOPOLOGY m_Topology; + D3D11_PRIMITIVE_TOPOLOGY m_Topology; // 358 - RE::NiPoint3 m_PosAdjust; - RE::NiPoint3 m_PreviousPosAdjust; - ViewData m_CameraData; + RE::NiPoint3 m_PosAdjust; // 35c + RE::NiPoint3 m_PreviousPosAdjust; //368 + ViewData m_CameraData; // 380 - uint32_t m_AlphaBlendModeExtra; + uint32_t m_AlphaBlendModeExtra; //5d0 char _pad0[0xC]; static RendererShadowState* QInstance(); }; + static_assert(sizeof(RendererShadowState) == 0x5e0); + static_assert(offsetof(RendererShadowState, m_RenderTargets) == 0x18); + static_assert(offsetof(RendererShadowState, m_ViewPort) == 0x70); + static_assert(offsetof(RendererShadowState, m_AlphaTestEnabled) == 0xb4); + static_assert(offsetof(RendererShadowState, m_PSTextureAddressMode) == 0xbc); + static_assert(offsetof(RendererShadowState, m_PSTextureFilterMode) == 0xfc); + static_assert(offsetof(RendererShadowState, m_PSTexture) == 0x140); + static_assert(offsetof(RendererShadowState, m_CSUAV) == 0x300); + static_assert(offsetof(RendererShadowState, m_VertexDesc) == 0x340); + static_assert(offsetof(RendererShadowState, m_CurrentVertexShader) == 0x348); + static_assert(offsetof(RendererShadowState, m_CurrentPixelShader) == 0x350); + static_assert(offsetof(RendererShadowState, m_Topology) == 0x358); + static_assert(offsetof(RendererShadowState, m_PosAdjust) == 0x35c); + static_assert(offsetof(RendererShadowState, m_PreviousPosAdjust) == 0x368); + static_assert(offsetof(RendererShadowState, m_CameraData) == 0x380); class Renderer {