Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VR): fix ghosting for water #477

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
11 changes: 8 additions & 3 deletions package/Shaders/ISWaterBlend.hlsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Common/Constants.hlsli"
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsli"
#include "Common/VR.hlsli"

typedef VS_OUTPUT PS_INPUT;

Expand Down Expand Up @@ -30,7 +32,7 @@ cbuffer PerGeometry : register(b2)
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

uint eyeIndex = GetEyeIndexPS(float4(input.TexCoord, 0, 0));
float2 adjustedScreenPosition = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord);
float waterMask = waterMaskTex.Sample(waterMaskSampler, adjustedScreenPosition).z;
if (waterMask < 1e-4) {
Expand All @@ -39,14 +41,17 @@ PS_OUTPUT main(PS_INPUT input)

float3 sourceColor = sourceTex.Sample(sourceSampler, adjustedScreenPosition).xyz;
float2 motion = motionBufferTex.Sample(motionBufferSampler, adjustedScreenPosition).xy;
float2 motionScreenPosition = input.TexCoord + motion;
float2 motionScreenPosition = ConvertToStereoUV(ConvertFromStereoUV(input.TexCoord, eyeIndex) + motion, eyeIndex);
float2 motionAdjustedScreenPosition =
GetPreviousDynamicResolutionAdjustedScreenPosition(motionScreenPosition);
float4 waterHistory =
waterHistoryTex.Sample(waterHistorySampler, motionAdjustedScreenPosition).xyzw;

float3 finalColor = sourceColor;
if (motionScreenPosition.x >= 0 && motionScreenPosition.y >= 0 && motionScreenPosition.x <= 1 &&
if (
# ifndef VR
motionScreenPosition.x >= 0 && motionScreenPosition.y >= 0 && motionScreenPosition.x <= 1 &&
# endif
motionScreenPosition.y <= 1 && waterHistory.w == 1) {
float historyFactor = 0.95;
if (NearFar_Menu_DistanceFactor.z == 0) {
Expand Down
Loading