Skip to content

Commit

Permalink
fix(VR): fix ConvertMonoUVToOtherEye
Browse files Browse the repository at this point in the history
This requires hardcoding a shift based on a q3. This may not be the
scalable solution.
  • Loading branch information
alandtse committed Oct 19, 2024
1 parent cf91120 commit 5a4bf1b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions package/Shaders/Common/VR.hlsli
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __VR_DEPENDENCY_HLSL__
#define __VR_DEPENDENCY_HLSL__
#ifdef VR
# if !defined(COMPUTESHADER) && !defined(CSHADER)
# if (!defined(COMPUTESHADER) && !defined(CSHADER)) || defined(FRAMEBUFFER)
# include "Common\Constants.hlsli"
# include "Common\FrameBuffer.hlsli"
# endif
Expand Down Expand Up @@ -146,7 +146,8 @@ namespace Stereo
return normalizedCoord;
}

#ifdef PSHADER
#if defined(PSHADER) || defined(FRAMEBUFFER)
// These functions require the framebuffer which is typically provided with the PSHADER
/**
Gets the eyeIndex for PSHADER
@returns eyeIndex (0 left, 1 right)
Expand Down Expand Up @@ -209,6 +210,12 @@ namespace Stereo
float4 viewPosCurrentEye = mul(CameraProjInverse[eyeIndex], clipPos);
viewPosCurrentEye /= viewPosCurrentEye.w;

// Adjust for eye position offset
const float2 eyeOffsetScale = float2(-0.50, 0.50);
float eyeOffset = dot(eyeOffsetScale, M_IdentityMatrix[eyeIndex].xy);
float adjustment = eyeOffset * viewPosCurrentEye.w * 8.8; // based on q3 adjustments, may need better conversion
viewPosCurrentEye.x += adjustment;

// Convert View Space to World Space
float4 worldPos = mul(CameraViewInverse[eyeIndex], viewPosCurrentEye);

Expand Down

0 comments on commit 5a4bf1b

Please sign in to comment.