Skip to content

Commit

Permalink
Bugfix: CRT Shader Vertical Flip Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pastasfuture committed Aug 9, 2021
1 parent 5419a00 commit 0e5633d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---------------------------------------------------------------------------------------------------------------------------
Bugfix: **CRT Shader Vertical Flip Logic**
---------------------------------------------------------------------------------------------------------------------------
Fixed bug where some CameraVolume aspect modes did not render correctly on hardware that requires flipped Y in the CRT shader.

---------------------------------------------------------------------------------------------------------------------------
New Material Feature: **Vertex Color Blend Modes**
---------------------------------------------------------------------------------------------------------------------------
Expand Down
14 changes: 5 additions & 9 deletions Runtime/PostProcessing/Shaders/CRT.shader
Original file line number Diff line number Diff line change
Expand Up @@ -475,26 +475,22 @@ Shader "Hidden/HauntedPS1/CRT"
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

float2 positionFramebufferNDC = input.uvFramebuffer;
float2 positionFramebufferSS = input.uvFramebuffer * _ScreenSize.xy;

float2 positionScreenNDC = input.uvScreen;
float2 positionScreenSS = input.uvScreen * _ScreenSize.xy;


#if UNITY_SINGLE_PASS_STEREO
positionFramebufferNDC.x = (positionFramebufferNDC.x + unity_StereoEyeIndex) * 0.5;
positionScreenNDC.x = (positionScreenNDC.x + unity_StereoEyeIndex) * 0.5;
#endif

// Flip logic
if (ShouldFlipY())
{
positionFramebufferSS.y = _ScreenSize.y - 1.0 - positionFramebufferSS.y;
positionFramebufferNDC.y = 1.0 - positionFramebufferNDC.y;

positionScreenSS.y = _ScreenSize.y - 1.0 - positionScreenSS.y;
positionFramebufferNDC = ComputeRasterizationRTUVFlipVerticallyInBounds(positionFramebufferNDC);
positionScreenNDC.y = 1.0 - positionScreenNDC.y;
}

float2 positionFramebufferSS = input.uvFramebuffer * _ScreenSize.xy;
float2 positionScreenSS = input.uvScreen * _ScreenSize.xy;

if (!_IsPSXQualityEnabled || !_CRTIsEnabled)
{
return ComputeRasterizationRTUVIsInBounds(positionFramebufferNDC.xy)
Expand Down
20 changes: 20 additions & 0 deletions Runtime/ShaderLibrary/ShaderFunctions.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,24 @@ bool ComputeRasterizationRTPositionSSIsInBounds(float2 positionSS)
&& (positionSS.y <= _RasterizationRTScaledMaxSSAndUV.y);
}

float2 ComputeRasterizationRTUVFlipVerticallyInBounds(float2 uv)
{
return ComputeRasterizationRTUVIsInBounds(uv)
? float2(
uv.x,
_RasterizationRTScaledMaxSSAndUV.w - uv.y
)
: uv;
}

float2 ComputeRasterizationRTPositionSSFlipVerticallyInBounds(float2 positionSS)
{
return ComputeRasterizationRTPositionSSIsInBounds(positionSS)
? float2(
positionSS.x,
_RasterizationRTScaledMaxSSAndUV.y - positionSS.y
)
: positionSS;
}

#endif

0 comments on commit 0e5633d

Please sign in to comment.