From 0e5633db072d50ceb21bfe8c15678d9d2fc9890f Mon Sep 17 00:00:00 2001 From: pastasfuture Date: Mon, 9 Aug 2021 10:27:04 -0700 Subject: [PATCH] Bugfix: CRT Shader Vertical Flip Logic --- CHANGELOG.md | 5 +++++ Runtime/PostProcessing/Shaders/CRT.shader | 14 +++++--------- Runtime/ShaderLibrary/ShaderFunctions.hlsl | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c40e3..4881e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** --------------------------------------------------------------------------------------------------------------------------- diff --git a/Runtime/PostProcessing/Shaders/CRT.shader b/Runtime/PostProcessing/Shaders/CRT.shader index 9a27592..930bf9b 100644 --- a/Runtime/PostProcessing/Shaders/CRT.shader +++ b/Runtime/PostProcessing/Shaders/CRT.shader @@ -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) diff --git a/Runtime/ShaderLibrary/ShaderFunctions.hlsl b/Runtime/ShaderLibrary/ShaderFunctions.hlsl index be6be22..b9f9d61 100644 --- a/Runtime/ShaderLibrary/ShaderFunctions.hlsl +++ b/Runtime/ShaderLibrary/ShaderFunctions.hlsl @@ -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 \ No newline at end of file