diff --git a/bin/resources/shaders/dx11/present.fx b/bin/resources/shaders/dx11/present.fx index fbc91c5c04501..593a222946657 100644 --- a/bin/resources/shaders/dx11/present.fx +++ b/bin/resources/shaders/dx11/present.fx @@ -142,19 +142,20 @@ PS_OUTPUT ps_filter_complex(PS_INPUT input) // triangular //Lottes CRT #define MaskingType 4 //[1|2|3|4] The type of CRT shadow masking used. 1: compressed TV style, 2: Aperture-grille, 3: Stretched VGA style, 4: VGA style. #define ScanBrightness -8.00 //[-16.0 to 1.0] The overall brightness of the scanline effect. Lower for darker, higher for brighter. -#define FilterCRTAmount -1.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. +#define FilterCRTAmount -3.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. #define HorizontalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the horizontal (x) axis of the screen. Use small increments. #define VerticalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the verticle (y) axis of the screen. Use small increments. -#define MaskAmountDark 0.80 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. +#define MaskAmountDark 0.50 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. #define MaskAmountLight 1.50 //[0.0 to 2.0] The value of the light masking line effect used. Lower for darker higher end masking, higher for brighter. -#define ResolutionScale 2.00 //[0.1 to 4.0] The scale of the image resolution. Lowering this can give off a nice retro TV look. Raising it can clear up the image. -#define MaskResolutionScale 0.80 //[0.1 to 2.0] The scale of the CRT mask resolution. Use this for balancing the scanline mask scale for difference resolution scaling. +#define BloomPixel -1.50 //[-2.0 -0.5] Pixel bloom radius. Higher for increased softness of bloom. +#define BloomScanLine -2.0 //[-4.0 -1.0] Scanline bloom radius. Higher for increased softness of bloom. +#define BloomAmount 0.15 //[0.0 1.0] Bloom intensity. Higher for brighter. +#define Shape 2.0 //[0.0 10.0] Kernal filter shape. Lower values will darken image and introduce moire patterns if used with curvature. #define UseShadowMask 1 //[0 or 1] Enables, or disables the use of the CRT shadow mask. 0 is disabled, 1 is enabled. float ToLinear1(float c) { - c = saturate(c); - return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); + return c <= 0.04045 ? c / 12.92 : pow((abs(c) + 0.055) / 1.055, 2.4); } float3 ToLinear(float3 c) @@ -164,8 +165,7 @@ float3 ToLinear(float3 c) float ToSrgb1(float c) { - c = saturate(c); - return c < 0.0031308 ? c * 12.92 : 1.055 * pow(c, 0.41666) - 0.055; + return c < 0.0031308 ? c * 12.92 : 1.055 * pow(abs(c), 0.41666) - 0.055; } float3 ToSrgb(float3 c) @@ -175,9 +175,7 @@ float3 ToSrgb(float3 c) float3 Fetch(float2 pos, float2 off) { - float2 screenSize = u_source_resolution; - float2 res = (screenSize * ResolutionScale); - pos = round(pos * res + off) / res; + pos = (floor(pos * u_target_size + off) + float2(0.5, 0.5)) / u_target_size; if (max(abs(pos.x - 0.5), abs(pos.y - 0.5)) > 0.5) { return float3(0.0, 0.0, 0.0); @@ -190,9 +188,7 @@ float3 Fetch(float2 pos, float2 off) float2 Dist(float2 pos) { - float2 crtRes = u_rcp_target_resolution; - float2 res = (crtRes * MaskResolutionScale); - pos = (pos * res); + pos = pos * float2(640, 480); return -((pos - floor(pos)) - float2(0.5, 0.5)); } @@ -215,7 +211,7 @@ float3 Horz3(float2 pos, float off) float wc = Gaus(dst + 0.0, scale); float wd = Gaus(dst + 1.0, scale); - return (b * wb) + (c * wc) + (d * wd) / (wb + wc + wd); + return (b * wb + c * wc + d * wd) / (wb + wc + wd); } float3 Horz5(float2 pos, float off) @@ -236,7 +232,32 @@ float3 Horz5(float2 pos, float off) float wd = Gaus(dst + 1.0, scale); float we = Gaus(dst + 2.0, scale); - return (a * wa) + (b * wb) + (c * wc) + (d * wd) + (e * we) / (wa + wb + wc + wd + we); + return (a * wa + b * wb + c * wc + d * wd + e * we) / (wa + wb + wc + wd + we); +} + +float3 Horz7(float2 pos, float off) +{ + float3 a = Fetch(pos, float2(-3.0, off)); + float3 b = Fetch(pos, float2(-2.0, off)); + float3 c = Fetch(pos, float2(-1.0, off)); + float3 d = Fetch(pos, float2( 0.0, off)); + float3 e = Fetch(pos, float2( 1.0, off)); + float3 f = Fetch(pos, float2( 2.0, off)); + float3 g = Fetch(pos, float2( 3.0, off)); + + float dst = Dist(pos).x; + // Convert distance to weight. + float scale = BloomPixel; + float wa = Gaus(dst - 3.0, scale); + float wb = Gaus(dst - 2.0, scale); + float wc = Gaus(dst - 1.0, scale); + float wd = Gaus(dst + 0.0, scale); + float we = Gaus(dst + 1.0, scale); + float wf = Gaus(dst + 2.0, scale); + float wg = Gaus(dst + 3.0, scale); + + // Return filtered sample. + return (a * wa + b * wb + c * wc + d * wd + e * we + f * wf + g * wg) / (wa + wb + wc + wd + we + wf + wg); } // Return scanline weight. @@ -246,6 +267,13 @@ float Scan(float2 pos, float off) return Gaus(dst + off, ScanBrightness); } +float BloomScan(float2 pos, float off) +{ + float dst = Dist(pos).y; + + return Gaus(dst + off, BloomScanLine); +} + float3 Tri(float2 pos) { float3 a = Horz3(pos, -1.0); @@ -259,6 +287,23 @@ float3 Tri(float2 pos) return (a * wa) + (b * wb) + (c * wc); } +float3 Bloom(float2 pos) +{ + float3 a = Horz5(pos,-2.0); + float3 b = Horz7(pos,-1.0); + float3 c = Horz7(pos, 0.0); + float3 d = Horz7(pos, 1.0); + float3 e = Horz5(pos, 2.0); + + float wa = BloomScan(pos,-2.0); + float wb = BloomScan(pos,-1.0); + float wc = BloomScan(pos, 0.0); + float wd = BloomScan(pos, 1.0); + float we = BloomScan(pos, 2.0); + + return a * wa + b * wb + c * wc + d * wd + e * we; +} + float2 Warp(float2 pos) { pos = pos * 2.0 - 1.0; @@ -368,15 +413,15 @@ float3 Mask(float2 pos) float4 LottesCRTPass(float4 fragcoord) { + float4 color; fragcoord -= u_target_rect; float2 inSize = u_target_resolution - (2 * u_target_rect.xy); - float4 color; - float2 pos = Warp(fragcoord.xy / inSize); -#if UseShadowMask == 0 + float2 pos = Warp(fragcoord.xy / inSize); color.rgb = Tri(pos); -#else - color.rgb = Tri(pos) * Mask(fragcoord.xy); + color.rgb += Bloom(pos) * BloomAmount; +#if UseShadowMask + color.rgb *= Mask(fragcoord.xy); #endif color.rgb = ToSrgb(color.rgb); color.a = 1.0; diff --git a/bin/resources/shaders/opengl/present.glsl b/bin/resources/shaders/opengl/present.glsl index abf9f5f4a04ce..301f158368d0a 100644 --- a/bin/resources/shaders/opengl/present.glsl +++ b/bin/resources/shaders/opengl/present.glsl @@ -139,20 +139,19 @@ void ps_filter_complex() #define MaskingType 4 //[1|2|3|4] The type of CRT shadow masking used. 1: compressed TV style, 2: Aperture-grille, 3: Stretched VGA style, 4: VGA style. #define ScanBrightness -8.00 //[-16.0 to 1.0] The overall brightness of the scanline effect. Lower for darker, higher for brighter. -#define FilterCRTAmount -1.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. +#define FilterCRTAmount -3.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. #define HorizontalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the horizontal (x) axis of the screen. Use small increments. #define VerticalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the verticle (y) axis of the screen. Use small increments. -#define MaskAmountDark 0.80 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. +#define MaskAmountDark 0.50 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. #define MaskAmountLight 1.50 //[0.0 to 2.0] The value of the light masking line effect used. Lower for darker higher end masking, higher for brighter. -#define ResolutionScale 2.00 //[0.1 to 4.0] The scale of the image resolution. Lowering this can give off a nice retro TV look. Raising it can clear up the image. -#define MaskResolutionScale 0.80 //[0.1 to 2.0] The scale of the CRT mask resolution. Use this for balancing the scanline mask scale for difference resolution scaling. +#define BloomPixel -1.50 //[-2.0 -0.5] Pixel bloom radius. Higher for increased softness of bloom. +#define BloomScanLine -2.0 //[-4.0 -1.0] Scanline bloom radius. Higher for increased softness of bloom. +#define BloomAmount 0.15 //[0.0 1.0] Bloom intensity. Higher for brighter. +#define Shape 2.0 //[0.0 10.0] Kernal filter shape. Lower values will darken image and introduce moire patterns if used with curvature. #define UseShadowMask 1 //[0 or 1] Enables, or disables the use of the CRT shadow mask. 0 is disabled, 1 is enabled. -#define saturate(x) clamp(x, 0.0, 1.0) - float ToLinear1(float c) { - c = saturate(c); return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); } @@ -163,7 +162,6 @@ vec3 ToLinear(vec3 c) float ToSrgb1(float c) { - c = saturate(c); return c < 0.0031308 ? c * 12.92 : 1.055 * pow(c, 0.41666) - 0.055; } @@ -174,9 +172,7 @@ vec3 ToSrgb(vec3 c) vec3 Fetch(vec2 pos, vec2 off) { - vec2 screenSize = u_source_resolution; - vec2 res = (screenSize * ResolutionScale); - pos = round(pos * res + off) / res; + pos = (floor(pos * u_target_size + off) + vec2(0.5, 0.5)) / u_target_size; if (max(abs(pos.x - 0.5), abs(pos.y - 0.5)) > 0.5) { return vec3(0.0, 0.0, 0.0); @@ -189,16 +185,14 @@ vec3 Fetch(vec2 pos, vec2 off) vec2 Dist(vec2 pos) { - vec2 crtRes = u_rcp_target_resolution; - vec2 res = (crtRes * MaskResolutionScale); - pos = (pos * res); + pos = pos * vec2(640, 480); return -((pos - floor(pos)) - vec2(0.5, 0.5)); } float Gaus(float pos, float scale) { - return exp2(scale * pos * pos); + return exp2(scale * pow(abs(pos), Shape)); } vec3 Horz3(vec2 pos, float off) @@ -214,7 +208,7 @@ vec3 Horz3(vec2 pos, float off) float wc = Gaus(dst + 0.0, scale); float wd = Gaus(dst + 1.0, scale); - return (b * wb) + (c * wc) + (d * wd) / (wb + wc + wd); + return (b * wb + c * wc + d * wd) / (wb + wc + wd); } vec3 Horz5(vec2 pos, float off) @@ -235,7 +229,32 @@ vec3 Horz5(vec2 pos, float off) float wd = Gaus(dst + 1.0, scale); float we = Gaus(dst + 2.0, scale); - return (a * wa) + (b * wb) + (c * wc) + (d * wd) + (e * we) / (wa + wb + wc + wd + we); + return (a * wa + b * wb + c * wc + d * wd + e * we) / (wa + wb + wc + wd + we); +} + +vec3 Horz7(vec2 pos, float off) +{ + vec3 a = Fetch(pos, vec2(-3.0, off)); + vec3 b = Fetch(pos, vec2(-2.0, off)); + vec3 c = Fetch(pos, vec2(-1.0, off)); + vec3 d = Fetch(pos, vec2( 0.0, off)); + vec3 e = Fetch(pos, vec2( 1.0, off)); + vec3 f = Fetch(pos, vec2( 2.0, off)); + vec3 g = Fetch(pos, vec2( 3.0, off)); + + float dst = Dist(pos).x; + // Convert distance to weight. + float scale = BloomPixel; + float wa = Gaus(dst - 3.0, scale); + float wb = Gaus(dst - 2.0, scale); + float wc = Gaus(dst - 1.0, scale); + float wd = Gaus(dst + 0.0, scale); + float we = Gaus(dst + 1.0, scale); + float wf = Gaus(dst + 2.0, scale); + float wg = Gaus(dst + 3.0, scale); + + // Return filtered sample. + return (a * wa + b * wb + c * wc + d * wd + e * we + f * wf + g * wg) / (wa + wb + wc + wd + we + wf + wg); } // Return scanline weight. @@ -245,6 +264,13 @@ float Scan(vec2 pos, float off) return Gaus(dst + off, ScanBrightness); } +float BloomScan(vec2 pos, float off) +{ + float dst = Dist(pos).y; + + return Gaus(dst + off, BloomScanLine); +} + vec3 Tri(vec2 pos) { vec3 a = Horz3(pos, -1.0); @@ -258,6 +284,23 @@ vec3 Tri(vec2 pos) return (a * wa) + (b * wb) + (c * wc); } +vec3 Bloom(vec2 pos) +{ + vec3 a = Horz5(pos,-2.0); + vec3 b = Horz7(pos,-1.0); + vec3 c = Horz7(pos, 0.0); + vec3 d = Horz7(pos, 1.0); + vec3 e = Horz5(pos, 2.0); + + float wa = BloomScan(pos,-2.0); + float wb = BloomScan(pos,-1.0); + float wc = BloomScan(pos, 0.0); + float wd = BloomScan(pos, 1.0); + float we = BloomScan(pos, 2.0); + + return a * wa + b * wb + c * wc + d * wd + e * we; +} + vec2 Warp(vec2 pos) { pos = pos * 2.0 - 1.0; @@ -373,14 +416,12 @@ vec4 LottesCRTPass() vec2 inSize = u_target_resolution - (2.0 * u_target_rect.xy); vec2 pos = Warp(fragcoord.xy / inSize); - -#if UseShadowMask == 0 color.rgb = Tri(pos); -#else - color.rgb = Tri(pos) * Mask(fragcoord.xy); + color.rgb += Bloom(pos) * BloomAmount; +#if UseShadowMask + color.rgb *= Mask(fragcoord.xy); #endif color.rgb = ToSrgb(color.rgb); - color.a = 1.0; return color; } diff --git a/bin/resources/shaders/vulkan/present.glsl b/bin/resources/shaders/vulkan/present.glsl index 578c5f0b5a229..c5de89afb4d39 100644 --- a/bin/resources/shaders/vulkan/present.glsl +++ b/bin/resources/shaders/vulkan/present.glsl @@ -110,20 +110,19 @@ void ps_filter_complex() // triangular #define MaskingType 4 //[1|2|3|4] The type of CRT shadow masking used. 1: compressed TV style, 2: Aperture-grille, 3: Stretched VGA style, 4: VGA style. #define ScanBrightness -8.00 //[-16.0 to 1.0] The overall brightness of the scanline effect. Lower for darker, higher for brighter. -#define FilterCRTAmount -1.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. +#define FilterCRTAmount -3.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. #define HorizontalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the horizontal (x) axis of the screen. Use small increments. #define VerticalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the verticle (y) axis of the screen. Use small increments. -#define MaskAmountDark 0.80 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. +#define MaskAmountDark 0.50 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. #define MaskAmountLight 1.50 //[0.0 to 2.0] The value of the light masking line effect used. Lower for darker higher end masking, higher for brighter. -#define ResolutionScale 2.00 //[0.1 to 4.0] The scale of the image resolution. Lowering this can give off a nice retro TV look. Raising it can clear up the image. -#define MaskResolutionScale 0.80 //[0.1 to 2.0] The scale of the CRT mask resolution. Use this for balancing the scanline mask scale for difference resolution scaling. +#define BloomPixel -1.50 //[-2.0 -0.5] Pixel bloom radius. Higher for increased softness of bloom. +#define BloomScanLine -2.0 //[-4.0 -1.0] Scanline bloom radius. Higher for increased softness of bloom. +#define BloomAmount 0.15 //[0.0 1.0] Bloom intensity. Higher for brighter. +#define Shape 2.0 //[0.0 10.0] Kernal filter shape. Lower values will darken image and introduce moire patterns if used with curvature. #define UseShadowMask 1 //[0 or 1] Enables, or disables the use of the CRT shadow mask. 0 is disabled, 1 is enabled. -#define saturate(x) clamp(x, 0.0, 1.0) - float ToLinear1(float c) { - c = saturate(c); return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); } @@ -134,7 +133,6 @@ vec3 ToLinear(vec3 c) float ToSrgb1(float c) { - c = saturate(c); return c < 0.0031308 ? c * 12.92 : 1.055 * pow(c, 0.41666) - 0.055; } @@ -145,9 +143,7 @@ vec3 ToSrgb(vec3 c) vec3 Fetch(vec2 pos, vec2 off) { - vec2 screenSize = u_source_resolution; - vec2 res = (screenSize * ResolutionScale); - pos = round(pos * res + off) / res; + pos = (floor(pos * u_target_size + off) + vec2(0.5, 0.5)) / u_target_size; if (max(abs(pos.x - 0.5), abs(pos.y - 0.5)) > 0.5) { return vec3(0.0, 0.0, 0.0); @@ -160,16 +156,14 @@ vec3 Fetch(vec2 pos, vec2 off) vec2 Dist(vec2 pos) { - vec2 crtRes = u_rcp_target_resolution; - vec2 res = (crtRes * MaskResolutionScale); - pos = (pos * res); + pos = pos * vec2(640, 480); return -((pos - floor(pos)) - vec2(0.5, 0.5)); } float Gaus(float pos, float scale) { - return exp2(scale * pos * pos); + return exp2(scale * pow(abs(pos), Shape)); } vec3 Horz3(vec2 pos, float off) @@ -185,7 +179,7 @@ vec3 Horz3(vec2 pos, float off) float wc = Gaus(dst + 0.0, scale); float wd = Gaus(dst + 1.0, scale); - return (b * wb) + (c * wc) + (d * wd) / (wb + wc + wd); + return (b * wb + c * wc + d * wd) / (wb + wc + wd); } vec3 Horz5(vec2 pos, float off) @@ -206,7 +200,32 @@ vec3 Horz5(vec2 pos, float off) float wd = Gaus(dst + 1.0, scale); float we = Gaus(dst + 2.0, scale); - return (a * wa) + (b * wb) + (c * wc) + (d * wd) + (e * we) / (wa + wb + wc + wd + we); + return (a * wa + b * wb + c * wc + d * wd + e * we) / (wa + wb + wc + wd + we); +} + +vec3 Horz7(vec2 pos, float off) +{ + vec3 a = Fetch(pos, vec2(-3.0, off)); + vec3 b = Fetch(pos, vec2(-2.0, off)); + vec3 c = Fetch(pos, vec2(-1.0, off)); + vec3 d = Fetch(pos, vec2( 0.0, off)); + vec3 e = Fetch(pos, vec2( 1.0, off)); + vec3 f = Fetch(pos, vec2( 2.0, off)); + vec3 g = Fetch(pos, vec2( 3.0, off)); + + float dst = Dist(pos).x; + // Convert distance to weight. + float scale = BloomPixel; + float wa = Gaus(dst - 3.0, scale); + float wb = Gaus(dst - 2.0, scale); + float wc = Gaus(dst - 1.0, scale); + float wd = Gaus(dst + 0.0, scale); + float we = Gaus(dst + 1.0, scale); + float wf = Gaus(dst + 2.0, scale); + float wg = Gaus(dst + 3.0, scale); + + // Return filtered sample. + return (a * wa + b * wb + c * wc + d * wd + e * we + f * wf + g * wg) / (wa + wb + wc + wd + we + wf + wg); } // Return scanline weight. @@ -216,6 +235,13 @@ float Scan(vec2 pos, float off) return Gaus(dst + off, ScanBrightness); } +float BloomScan(vec2 pos, float off) +{ + float dst = Dist(pos).y; + + return Gaus(dst + off, BloomScanLine); +} + vec3 Tri(vec2 pos) { vec3 a = Horz3(pos, -1.0); @@ -229,6 +255,23 @@ vec3 Tri(vec2 pos) return (a * wa) + (b * wb) + (c * wc); } +vec3 Bloom(vec2 pos) +{ + vec3 a = Horz5(pos,-2.0); + vec3 b = Horz7(pos,-1.0); + vec3 c = Horz7(pos, 0.0); + vec3 d = Horz7(pos, 1.0); + vec3 e = Horz5(pos, 2.0); + + float wa = BloomScan(pos,-2.0); + float wb = BloomScan(pos,-1.0); + float wc = BloomScan(pos, 0.0); + float wd = BloomScan(pos, 1.0); + float we = BloomScan(pos, 2.0); + + return a * wa + b * wb + c * wc + d * wd + e * we; +} + vec2 Warp(vec2 pos) { pos = pos * 2.0 - 1.0; @@ -338,19 +381,17 @@ vec3 Mask(vec2 pos) vec4 LottesCRTPass() { - vec4 fragcoord = gl_FragCoord - u_target_rect; vec4 color; + vec4 fragcoord = gl_FragCoord - u_target_rect; vec2 inSize = u_target_resolution - (2 * u_target_rect.xy); vec2 pos = Warp(fragcoord.xy / inSize); - -#if UseShadowMask == 0 color.rgb = Tri(pos); -#else - color.rgb = Tri(pos) * Mask(fragcoord.xy); + color.rgb += Bloom(pos) * BloomAmount; +#if UseShadowMask + color.rgb *= Mask(fragcoord.xy); #endif color.rgb = ToSrgb(color.rgb); - color.a = 1.0; return color; } diff --git a/pcsx2/GS/Renderers/Metal/present.metal b/pcsx2/GS/Renderers/Metal/present.metal index 0f48d5c029a88..b8ddb071f0a6f 100644 --- a/pcsx2/GS/Renderers/Metal/present.metal +++ b/pcsx2/GS/Renderers/Metal/present.metal @@ -62,13 +62,15 @@ fragment float4 ps_filter_complex(ConvertShaderData data [[stage_in]], ConvertPS #define MaskingType 4 //[1|2|3|4] The type of CRT shadow masking used. 1: compressed TV style, 2: Aperture-grille, 3: Stretched VGA style, 4: VGA style. #define ScanBrightness -8.00 //[-16.0 to 1.0] The overall brightness of the scanline effect. Lower for darker, higher for brighter. -#define FilterCRTAmount -1.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. +#define FilterCRTAmount -3.00 //[-4.0 to 1.0] The amount of filtering used, to replicate the TV CRT look. Lower for less, higher for more. #define HorizontalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the horizontal (x) axis of the screen. Use small increments. #define VerticalWarp 0.00 //[0.0 to 0.1] The distortion warping effect for the verticle (y) axis of the screen. Use small increments. -#define MaskAmountDark 0.80 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. +#define MaskAmountDark 0.50 //[0.0 to 1.0] The value of the dark masking line effect used. Lower for darker lower end masking, higher for brighter. #define MaskAmountLight 1.50 //[0.0 to 2.0] The value of the light masking line effect used. Lower for darker higher end masking, higher for brighter. -#define ResolutionScale 2.00 //[0.1 to 4.0] The scale of the image resolution. Lowering this can give off a nice retro TV look. Raising it can clear up the image. -#define MaskResolutionScale 0.80 //[0.1 to 2.0] The scale of the CRT mask resolution. Use this for balancing the scanline mask scale for difference resolution scaling. +#define BloomPixel -1.50 //[-2.0 -0.5] Pixel bloom radius. Higher for increased softness of bloom. +#define BloomScanLine -2.0 //[-4.0 -1.0] Scanline bloom radius. Higher for increased softness of bloom. +#define BloomAmount 0.15 //[0.0 1.0] Bloom intensity. Higher for brighter. +#define Shape 2.0 //[0.0 10.0] Kernal filter shape. Lower values will darken image and introduce moire patterns if used with curvature. #define UseShadowMask 1 //[0 or 1] Enables, or disables the use of the CRT shadow mask. 0 is disabled, 1 is enabled. struct LottesCRTPass @@ -79,7 +81,6 @@ struct LottesCRTPass float ToLinear1(float c) { - c = saturate(c); return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); } @@ -90,7 +91,6 @@ struct LottesCRTPass float ToSrgb1(float c) { - c = saturate(c); return c < 0.0031308 ? c * 12.92 : 1.055 * pow(c, 0.41666) - 0.055; } @@ -101,9 +101,7 @@ struct LottesCRTPass float3 Fetch(float2 pos, float2 off) { - float2 screenSize = uniform.source_resolution; - float2 scaledRes = (screenSize * ResolutionScale); - pos = round(pos * scaledRes + off) / scaledRes; + pos = (floor(pos * uniform.target_size + off) + float2(0.5, 0.5)) / uniform.target_size; if (max(abs(pos.x - 0.5), abs(pos.y - 0.5)) > 0.5) { return float3(0.0, 0.0, 0.0); @@ -116,16 +114,14 @@ struct LottesCRTPass float2 Dist(float2 pos) { - float2 crtRes = uniform.rcp_target_resolution; - float2 res = (crtRes * MaskResolutionScale); - pos = (pos * res); + pos = pos * float2(640, 480); return -((pos - floor(pos)) - float2(0.5, 0.5)); } float Gaus(float pos, float scale) { - return exp2(scale * pos * pos); + return exp2(scale * pow(abs(pos), Shape)); } float3 Horz3(float2 pos, float off) @@ -141,7 +137,7 @@ struct LottesCRTPass float wc = Gaus(dst + 0.0, scale); float wd = Gaus(dst + 1.0, scale); - return (b * wb) + (c * wc) + (d * wd) / (wb + wc + wd); + return (b * wb + c * wc + d * wd) / (wb + wc + wd); } float3 Horz5(float2 pos, float off) @@ -162,7 +158,32 @@ struct LottesCRTPass float wd = Gaus(dst + 1.0, scale); float we = Gaus(dst + 2.0, scale); - return (a * wa) + (b * wb) + (c * wc) + (d * wd) + (e * we) / (wa + wb + wc + wd + we); + return (a * wa + b * wb + c * wc + d * wd + e * we) / (wa + wb + wc + wd + we); + } + + float3 Horz7(float2 pos, float off) + { + float3 a = Fetch(pos, float2(-3.0, off)); + float3 b = Fetch(pos, float2(-2.0, off)); + float3 c = Fetch(pos, float2(-1.0, off)); + float3 d = Fetch(pos, float2( 0.0, off)); + float3 e = Fetch(pos, float2( 1.0, off)); + float3 f = Fetch(pos, float2( 2.0, off)); + float3 g = Fetch(pos, float2( 3.0, off)); + + float dst = Dist(pos).x; + // Convert distance to weight. + float scale = BloomPixel; + float wa = Gaus(dst - 3.0, scale); + float wb = Gaus(dst - 2.0, scale); + float wc = Gaus(dst - 1.0, scale); + float wd = Gaus(dst + 0.0, scale); + float we = Gaus(dst + 1.0, scale); + float wf = Gaus(dst + 2.0, scale); + float wg = Gaus(dst + 3.0, scale); + + // Return filtered sample. + return (a * wa + b * wb + c * wc + d * wd + e * we + f * wf + g * wg) / (wa + wb + wc + wd + we + wf + wg); } // Return scanline weight. @@ -172,6 +193,13 @@ struct LottesCRTPass return Gaus(dst + off, ScanBrightness); } + float BloomScan(float2 pos, float off) + { + float dst = Dist(pos).y; + + return Gaus(dst + off, BloomScanLine); + } + float3 Tri(float2 pos) { float3 a = Horz3(pos, -1.0); @@ -185,6 +213,23 @@ struct LottesCRTPass return (a * wa) + (b * wb) + (c * wc); } + float3 Bloom(float2 pos) + { + float3 a = Horz5(pos,-2.0); + float3 b = Horz7(pos,-1.0); + float3 c = Horz7(pos, 0.0); + float3 d = Horz7(pos, 1.0); + float3 e = Horz5(pos, 2.0); + + float wa = BloomScan(pos,-2.0); + float wb = BloomScan(pos,-1.0); + float wc = BloomScan(pos, 0.0); + float wd = BloomScan(pos, 1.0); + float we = BloomScan(pos, 2.0); + + return a * wa + b * wb + c * wc + d * wd + e * we; + } + float2 Warp(float2 pos) { pos = pos * 2.0 - 1.0; @@ -294,18 +339,17 @@ struct LottesCRTPass float4 Run(float4 fragcoord) { + float4 color; fragcoord -= uniform.target_rect; float2 inSize = uniform.target_resolution - (2 * uniform.target_rect.xy); - float4 color; - float2 pos = Warp(fragcoord.xy / inSize); -#if UseShadowMask == 0 + float2 pos = Warp(fragcoord.xy / inSize); color.rgb = Tri(pos); -#else - color.rgb = Tri(pos) * Mask(fragcoord.xy); -#endif + color.rgb += Bloom(pos) * BloomAmount; + #if UseShadowMask + color.rgb *= Mask(fragcoord.xy); + #endif color.rgb = ToSrgb(color.rgb); - color.a = 1.0; return color; } diff --git a/pcsx2/ShaderCacheVersion.h b/pcsx2/ShaderCacheVersion.h index f33b0e6bb6dcc..e60f18e20bfcd 100644 --- a/pcsx2/ShaderCacheVersion.h +++ b/pcsx2/ShaderCacheVersion.h @@ -3,4 +3,4 @@ /// Version number for GS and other shaders. Increment whenever any of the contents of the /// shaders change, to invalidate the cache. -static constexpr u32 SHADER_CACHE_VERSION = 57; +static constexpr u32 SHADER_CACHE_VERSION = 58;