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
2 changes: 1 addition & 1 deletion Build Release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/Features/Clustered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/Features/DistantTreeLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RE::NiDirectionalLight*>(accumulator->GetRuntimeData().activeShadowSceneNode->GetRuntimeData().sunLight->light.get());
if (sunLight) {
auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton();

perPassData.DirLightScale = imageSpaceManager->data.baseData.hdr.sunlightScale * sunLight->GetLightRuntimeData().fade;
Expand Down Expand Up @@ -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");
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Features/GrassCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Features/GrassLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

Expand Down
63 changes: 40 additions & 23 deletions src/Features/ScreenSpaceShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "State.h"
#include "Util.h"

using RE::RENDER_TARGETS;

void ScreenSpaceShadows::DrawSettings()
{
if (ImGui::BeginTabItem("Screen-Space Shadows")) {
Expand Down Expand Up @@ -115,8 +117,7 @@ class NiDirectionalLight : public RE::NiLight

void ScreenSpaceShadows::ClearComputeShader()
{
if (raymarchProgram)
{
if (raymarchProgram) {
raymarchProgram->Release();
raymarchProgram = nullptr;
}
Expand All @@ -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;
}

Expand All @@ -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<RE::NiDirectionalLight*>(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;
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/RE/BSGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
25 changes: 20 additions & 5 deletions src/RE/BSGraphicsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down