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
27 changes: 5 additions & 22 deletions package/Shaders/ISWaterBlend.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef VS_OUTPUT PS_INPUT;
struct PS_OUTPUT
{
float3 Color: SV_Target0;
float4 Color1: SV_Target1;
float3 Color1: SV_Target1;
};

#if defined(PSHADER)
Expand All @@ -28,22 +28,6 @@ cbuffer PerGeometry : register(b2)
float4 NearFar_Menu_DistanceFactor : packoffset(c0);
};

float3 LogToLinear(float3 logColor)
{
const float linearRange = 14.0f;
const float linearGrey = 0.18f;
const float exposureGrey = 444.0f;
return exp2((logColor - exposureGrey / 1023.0) * linearRange) * linearGrey;
}

float3 LinearToLog(float3 linearColor)
{
const float linearRange = 14.0f;
const float linearGrey = 0.18f;
const float exposureGrey = 444.0f;
return saturate(log2(linearColor) / linearRange - log2(linearGrey) / linearRange + exposureGrey / 1023.0f);
}

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
Expand All @@ -59,16 +43,15 @@ PS_OUTPUT main(PS_INPUT input)
float2 motionScreenPosition = Stereo::ConvertToStereoUV(Stereo::ConvertFromStereoUV(input.TexCoord, eyeIndex) + motion, eyeIndex);
float2 motionAdjustedScreenPosition =
FrameBuffer::GetPreviousDynamicResolutionAdjustedScreenPosition(motionScreenPosition);
float4 waterHistory =
waterHistoryTex.Sample(waterHistorySampler, motionAdjustedScreenPosition).xyzw;
waterHistory.xyz = LogToLinear(waterHistory.xyz) - LogToLinear(0);
float3 waterHistory =
waterHistoryTex.Sample(waterHistorySampler, motionAdjustedScreenPosition).xyz;
Comment thread
jiayev marked this conversation as resolved.

float3 finalColor = sourceColor;
if (
# ifndef VR
motionScreenPosition.x >= 0 && motionScreenPosition.y >= 0 && motionScreenPosition.x <= 1 &&
# endif
motionScreenPosition.y <= 1 && waterHistory.w == 1) {
motionScreenPosition.y <= 1 && any(waterHistory)) {
float historyFactor = 0.95;
if (NearFar_Menu_DistanceFactor.z == 0) {
float depth = depthBufferTex.Sample(depthBufferSampler, adjustedScreenPosition).x;
Expand All @@ -84,7 +67,7 @@ PS_OUTPUT main(PS_INPUT input)
finalColor = lerp(sourceColor, waterHistory.xyz, historyFactor);
}

psout.Color1 = float4(LinearToLog(finalColor + LogToLinear(0)), 1);
psout.Color1 = finalColor;
psout.Color = finalColor;

return psout;
Expand Down
4 changes: 4 additions & 0 deletions src/Deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ void Deferred::SetupResources()
SetupRenderTarget(NORMALROUGHNESS, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R10G10B10A2_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
// Masks
SetupRenderTarget(MASKS, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R11G11B10_FLOAT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);

// TAA Water Buffers
SetupRenderTarget(RE::RENDER_TARGETS::kWATER_1, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R11G11B10_FLOAT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
SetupRenderTarget(RE::RENDER_TARGETS::kWATER_2, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R11G11B10_FLOAT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
}

{
Expand Down
15 changes: 2 additions & 13 deletions src/Features/Upscaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,22 +1029,11 @@ void Upscaling::ConfigureTAA()
{
auto upscaleMethod = GetUpscaleMethod();

// When no upscaling method is active, leave vanilla TAA state untouched.
// The original UpdateJitter (called after this) manages water TAA and jitter
// correctly for the non-upscaling case. Overriding here disables ISWaterBlend,
// removing the 95% temporal history blend that stabilizes water reflections.
if (upscaleMethod == UpscaleMethod::kNONE)
return;

auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton();
GET_INSTANCE_MEMBER(BSImagespaceShaderISTemporalAA, imageSpaceManager);

// CS TAA replaces vanilla TAA entirely, so disable water TAA (CS handles it).
// For FSR/DLSS, keep water TAA enabled since the upscaler needs the blend data.
bool* enableWaterTAA = reinterpret_cast<bool*>(reinterpret_cast<uintptr_t>(BSImagespaceShaderISTemporalAA) + 0x38LL);
*enableWaterTAA = (upscaleMethod != UpscaleMethod::kTAA);

BSImagespaceShaderISTemporalAA->taaEnabled = true;
// Force enable TAA if needed
BSImagespaceShaderISTemporalAA->taaEnabled = upscaleMethod != UpscaleMethod::kNONE;
}

void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport)
Expand Down
Loading