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: 0 additions & 2 deletions features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace LightFlags
static const uint PortalStrict = (1 << 0);
static const uint Shadow = (1 << 1);
static const uint Simple = (1 << 2);
static const uint Particle = (1 << 3);
static const uint Billboard = (1 << 4);
}

struct ClusterAABB
Expand Down
30 changes: 15 additions & 15 deletions package/Shaders/DeferredCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Common/Color.hlsli"
#include "Common/FrameBuffer.hlsli"
#include "Common/GBuffer.hlsli"
#include "Common/MotionBlur.hlsli"
#include "Common/SharedData.hlsli"
#include "Common/VR.hlsli"

Expand All @@ -13,7 +14,7 @@ Texture2D<unorm half3> Masks2Texture : register(t4);

RWTexture2D<half3> MainRW : register(u0);
RWTexture2D<half4> NormalTAAMaskSpecularMaskRW : register(u1);
RWTexture2D<half2> SnowParametersRW : register(u2);
RWTexture2D<half2> MotionVectorsRW : register(u2);

#if defined(DYNAMIC_CUBEMAPS)
Texture2D<float> DepthTexture : register(t5);
Expand Down Expand Up @@ -42,7 +43,7 @@ Texture2D<half4> SpecularSSGITexture : register(t10);
: SV_DispatchThreadID) {
half2 uv = half2(dispatchID.xy + 0.5) * BufferDim.zw;
uint eyeIndex = Stereo::GetEyeIndexFromTexCoord(uv);
uv *= DynamicResolutionParams2.xy; // adjust for dynamic res
uv *= DynamicResolutionParams2.xy; // Adjust for dynamic res
uv = Stereo::ConvertFromStereoUV(uv, eyeIndex);

half3 normalGlossiness = NormalRoughnessTexture[dispatchID.xy];
Expand All @@ -53,7 +54,15 @@ Texture2D<half4> SpecularSSGITexture : register(t10);
half3 albedo = AlbedoTexture[dispatchID.xy];
half3 masks2 = Masks2Texture[dispatchID.xy];

half2 snowParameters = masks2.xy;
half depth = DepthTexture[dispatchID.xy];
half4 positionWS = half4(2 * half2(uv.x, -uv.y + 1) - 1, depth, 1);
positionWS = mul(CameraViewProjInverse[eyeIndex], positionWS);
positionWS.xyz = positionWS.xyz / positionWS.w;

if (depth == 1.0) {
MotionVectorsRW[dispatchID.xy] = GetSSMotionVector(positionWS, positionWS, eyeIndex); // Apply sky motion vectors
}

half pbrWeight = masks2.z;

half glossiness = normalGlossiness.z;
Expand All @@ -73,15 +82,7 @@ Texture2D<half4> SpecularSSGITexture : register(t10);

color = Color::GammaToLinear(color);

half depth = DepthTexture[dispatchID.xy];

half4 positionCS = half4(2 * half2(uv.x, -uv.y + 1) - 1, depth, 1);
positionCS = mul(CameraViewProjInverse[eyeIndex], positionCS);
positionCS.xyz = positionCS.xyz / positionCS.w;

half3 positionWS = positionCS.xyz;

half3 V = normalize(positionWS);
half3 V = normalize(positionWS.xyz);
half3 R = reflect(V, normalWS);

half roughness = 1.0 - glossiness;
Expand All @@ -96,9 +97,9 @@ Texture2D<half4> SpecularSSGITexture : register(t10);
finalIrradiance += specularIrradiance;
# elif defined(SKYLIGHTING)
# if defined(VR)
float3 positionMS = positionWS + CameraPosAdjust[eyeIndex].xyz - CameraPosAdjust[0].xyz;
float3 positionMS = positionWS.xyz + CameraPosAdjust[eyeIndex].xyz - CameraPosAdjust[0].xyz;
# else
float3 positionMS = positionWS;
float3 positionMS = positionWS.xyz;
# endif

sh2 skylighting = Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMS.xyz, normalWS);
Expand Down Expand Up @@ -172,5 +173,4 @@ Texture2D<half4> SpecularSSGITexture : register(t10);

MainRW[dispatchID.xy] = color;
NormalTAAMaskSpecularMaskRW[dispatchID.xy] = half4(GBuffer::EncodeNormalVanilla(normalVS), 0.0, 0.0);
SnowParametersRW[dispatchID.xy] = snowParameters;
}
2 changes: 1 addition & 1 deletion package/Shaders/Effect.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ PS_OUTPUT main(PS_INPUT input)
float softMul = 1;
# if defined(SOFT)
float depth = TexDepthSamplerEffect.Load(int3(input.Position.xy, 0)).x;
softMul = saturate(-input.TexCoord0.w + LightingInfluence.y / ((1 - depth) * CameraData.z + CameraData.y));
softMul = saturate(-input.TexCoord0.w + LightingInfluence.y / ((1 - depth) * CameraDataEffect.z + CameraDataEffect.y));
# endif

float lightingInfluence = LightingInfluence.x;
Expand Down
10 changes: 1 addition & 9 deletions package/Shaders/Sky.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,7 @@ PS_OUTPUT main(PS_INPUT input)
psout.Color = float4(0, 0, 0, 1.0);
# endif // OCCLUSION

float3 viewPosition = mul(CameraView[eyeIndex], float4(input.WorldPosition.xyz, 1)).xyz;
float2 screenUV = FrameBuffer::ViewToUV(viewPosition, true, eyeIndex);

float4 positionWS = half4(2 * half2(screenUV.x, -screenUV.y + 1) - 1, 1.0, 1);
positionWS = mul(CameraViewProjInverse[eyeIndex], positionWS);
positionWS.xyz = positionWS.xyz / positionWS.w;
positionWS.w = 1;

float2 screenMotionVector = GetSSMotionVector(positionWS, positionWS, eyeIndex);
float2 screenMotionVector = GetSSMotionVector(input.WorldPosition, input.PreviousWorldPosition, eyeIndex);

psout.MotionVectors = float4(screenMotionVector, 0, psout.Color.w);
psout.Normal = float4(0.5, 0.5, 0, psout.Color.w);
Expand Down
6 changes: 3 additions & 3 deletions src/Deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ void Deferred::DeferredPasses()

auto main = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[0]];
auto normals = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[2]];
auto snow = renderer->GetRuntimeData().renderTargets[forwardRenderTargets[3]];

auto depth = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kPOST_ZPREPASS_COPY];
auto reflectance = renderer->GetRuntimeData().renderTargets[REFLECTANCE];

auto motionVectors = renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kMOTION_VECTOR];

bool interior = true;
if (auto sky = RE::Sky::GetSingleton())
interior = sky->mode.get() != RE::Sky::Mode::kFull;
Expand Down Expand Up @@ -455,7 +455,7 @@ void Deferred::DeferredPasses()

context->CSSetShaderResources(0, ARRAYSIZE(srvs), srvs);

ID3D11UnorderedAccessView* uavs[3]{ main.UAV, normals.UAV, snow.UAV };
ID3D11UnorderedAccessView* uavs[3]{ main.UAV, normals.UAV, motionVectors.UAV };
context->CSSetUnorderedAccessViews(0, ARRAYSIZE(uavs), uavs, nullptr);

auto shader = interior ? GetComputeMainCompositeInterior() : GetComputeMainComposite();
Expand Down
3 changes: 0 additions & 3 deletions src/Features/LightLimitFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ void LightLimitFix::UpdateLights()
}

clusteredLight.lightFlags.set(LightFlags::Simple);
clusteredLight.lightFlags.set(LightFlags::Particle);

AddCachedParticleLights(lightsData, clusteredLight);

Expand Down Expand Up @@ -943,7 +942,6 @@ void LightLimitFix::UpdateLights()
SetLightPosition(light, position); // Light is complete for both eyes by now

light.lightFlags.set(LightFlags::Simple);
light.lightFlags.set(LightFlags::Billboard);

AddCachedParticleLights(lightsData, light);
}
Expand All @@ -959,7 +957,6 @@ void LightLimitFix::UpdateLights()
clusteredLight.positionWS[1].data.z += eyePositionOffset.z / (float)clusteredLights;
}
clusteredLight.lightFlags.set(LightFlags::Simple);
clusteredLight.lightFlags.set(LightFlags::Particle);
AddCachedParticleLights(lightsData, clusteredLight);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Features/LightLimitFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ struct LightLimitFix : Feature
{
PortalStrict = (1 << 0),
Shadow = (1 << 1),
Simple = (1 << 2),
Particle = (1 << 3),
Billboard = (1 << 4)
Simple = (1 << 2)
};

struct PositionOpt
Expand Down
9 changes: 4 additions & 5 deletions src/Features/ScreenSpaceShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ void ScreenSpaceShadows::DrawSettings()
{
if (ImGui::TreeNodeEx("General", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Checkbox("Enable", (bool*)&bendSettings.Enable);
ImGui::SliderInt("Sample Count", (int*)&bendSettings.SampleCount, 1, 4);

ImGui::SliderFloat("SurfaceThickness", &bendSettings.SurfaceThickness, 0.005f, 0.05f);
ImGui::SliderFloat("BilinearThreshold", &bendSettings.BilinearThreshold, 0.02f, 1.0f);
ImGui::SliderFloat("ShadowContrast", &bendSettings.ShadowContrast, 0.0f, 4.0f);
ImGui::SliderInt("Sample Count Multiplier", (int*)&bendSettings.SampleCount, 1, 4);
ImGui::SliderFloat("Surface Thickness", &bendSettings.SurfaceThickness, 0.005f, 0.05f);
ImGui::SliderFloat("Bilinear Threshold", &bendSettings.BilinearThreshold, 0.02f, 1.0f);
ImGui::SliderFloat("Shadow Contrast", &bendSettings.ShadowContrast, 0.0f, 4.0f);

ImGui::Spacing();
ImGui::Spacing();
Expand Down
11 changes: 11 additions & 0 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@ namespace Hooks
static inline REL::Relocation<decltype(thunk)> func;
};

struct CreateRenderTarget_MotionVectors
{
static void thunk(RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
{
State::GetSingleton()->ModifyRenderTarget(a_target, a_properties);
func(This, a_target, a_properties);
}
static inline REL::Relocation<decltype(thunk)> func;
};

struct BSShader__BeginTechnique_SetVertexShader
{
static void thunk(RE::BSGraphics::Renderer* This, RE::BSGraphics::VertexShader* a_vertexShader)
Expand Down Expand Up @@ -674,6 +684,7 @@ namespace Hooks
stl::write_thunk_call<CreateRenderTarget_Normals>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x458, 0x45B, 0x5B0));
stl::write_thunk_call<CreateRenderTarget_NormalsSwap>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x46B, 0x46E, 0x5C3));
stl::write_thunk_call<CreateRenderTarget_Snow>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x406, 0x409, 0x55e));
stl::write_thunk_call<CreateRenderTarget_MotionVectors>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x4F0, 0x4EF, 0x64E));
stl::write_thunk_call<CreateDepthStencil_PrecipitationMask>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0x1245, 0x123B, 0x1917));
stl::write_thunk_call<CreateCubemapRenderTarget_Reflections>(REL::RelocationID(100458, 107175).address() + REL::Relocate(0xA25, 0xA25, 0xCD2));

Expand Down
21 changes: 15 additions & 6 deletions src/TruePBR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ void TruePBR::SetupGlintsTexture()

void TruePBR::SetupFrame()
{
SetupDefaultPBRLandTextureSet();
}

void TruePBR::SetupTextureSetData()
Expand Down Expand Up @@ -1089,8 +1090,8 @@ void SetupLandscapeTexture(BSLightingShaderMaterialPBRLandscape& material, RE::T

RE::TESLandTexture* GetDefaultLandTexture()
{
static RE::TESLandTexture* const defaultLandTexture = *REL::Relocation<RE::TESLandTexture**>(RELOCATION_ID(514783, 400936));
return defaultLandTexture;
static const auto defaultLandTextureAddress = REL::Relocation<RE::TESLandTexture**>(RELOCATION_ID(514783, 400936));
return *defaultLandTextureAddress;
}

struct TESObjectLAND_SetupMaterial
Expand Down Expand Up @@ -1132,7 +1133,7 @@ struct TESObjectLAND_SetupMaterial
if (land->loadedData != nullptr && land->loadedData->mesh[0] != nullptr) {
land->data.flags.set(static_cast<RE::OBJ_LAND::Flag>(8));
for (uint32_t quadIndex = 0; quadIndex < 4; ++quadIndex) {
auto shaderProperty = static_cast<RE::BSLightingShaderProperty*>(RE::MemoryManager::GetSingleton()->Allocate(sizeof(RE::BSLightingShaderProperty), 0, false));
auto shaderProperty = static_cast<RE::BSLightingShaderProperty*>(RE::MemoryManager::GetSingleton()->Allocate(REL::Module::IsVR() ? 0x178 : sizeof(RE::BSLightingShaderProperty), 0, false));
shaderProperty->Ctor();

{
Expand Down Expand Up @@ -1601,9 +1602,17 @@ void TruePBR::PostPostLoad()
void TruePBR::DataLoaded()
{
defaultPbrLandTextureSet = RE::TESForm::LookupByEditorID<RE::BGSTextureSet>("DefaultPBRLand");
if (defaultPbrLandTextureSet != nullptr) {
logger::info("[TruePBR] replacing default land texture set record with {}", defaultPbrLandTextureSet->GetFormEditorID());
GetDefaultLandTexture()->textureSet = defaultPbrLandTextureSet;
SetupDefaultPBRLandTextureSet();
}

void TruePBR::SetupDefaultPBRLandTextureSet()
{
if (!defaultLandTextureSetReplaced && defaultPbrLandTextureSet != nullptr) {
if (auto* defaultLandTexture = GetDefaultLandTexture()) {
logger::info("[TruePBR] replacing default land texture set record with {}", defaultPbrLandTextureSet->GetFormEditorID());
defaultLandTexture->textureSet = defaultPbrLandTextureSet;
defaultLandTextureSetReplaced = true;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/TruePBR.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ struct TruePBR
PBRTextureSetData* GetPBRTextureSetData(const RE::TESForm* textureSet);
bool IsPBRTextureSet(const RE::TESForm* textureSet);

void SetupDefaultPBRLandTextureSet();

std::unordered_map<std::string, PBRTextureSetData> pbrTextureSets;
RE::BGSTextureSet* defaultPbrLandTextureSet = nullptr;
bool defaultLandTextureSetReplaced = false;
std::string selectedPbrTextureSetName;
PBRTextureSetData* selectedPbrTextureSet = nullptr;

Expand Down