slang-shaders/bezel/Mega_Bezel/shaders/guest/hsm-crt-guest-advanced-ntsc-pass1.inc

184 lines
5.5 KiB
PHP
Raw Permalink Normal View History

2022-06-25 10:06:45 +10:00
/*
CRT - Guest - NTSC - Pass1
Mega Bezel V1.11.0_2023-02-25 Changes: * Guest Advanced updated to crt-guest-advanced-2023-02-25-release1 * Improvements to the new Magic Glow feature * Turn Magic Glow on and Increase the Glow amount to see the effect * New Slot Mask Mitigation option to reduce moire * Added/Restored Guest's Raster Bloom as well as Overscan control * Updated Comments in presets to use # instead of // as per @hunterk's request * Added rotation option for Rotate CRT Tube: * -1 = 90 Degrees Clockwise (or 270 Counter Clockwise) * 0 = No Rotation * 1 = 90 Degrees Counter Clockwise * Added groundwork for the wildcard replacement feature so presets will auto rotate and not flip in the future * Added DREZ presets which keep the horizontal resolution * Helpful for applying to modern games, these two are good to try * `Presets\Base_CRT_Presets_DREZ\MBZ__3__STD__GDV__DREZ_X-VIEWPORT_Y-240p.slangp` * `Presets\Base_CRT_Presets_DREZ\MBZ__3__STD__GDV__DREZ_X-VIEWPORT_Y-480p.slangp` * Also looks good on MVC2, try `Presets\Base_CRT_Presets_DREZ\MBZ__3__STD__GDV__DREZ_X-VIEWPORT_Y-240p.slangp` * Updated preset capability and performance table * Added contrast for signal noise * Added some more Sinden presets for SCREEN-ONLY and POTATO * Added Screen Region to Resolution Debug text * Good for getting the screen region pixel coordinates if you need them * Adjusted Ambient Lighting Scaling when using the Inherit Zoom scale mode * Now when you zoom out it is much less likely to generate a black frame covering the outer parts of the background image * The minimum size of the lighting texture will be close to the height of the current viewport * This reduces the likelihood that we will see the cutoff * ScaleFx: Exposed more of the settings so they can be tweaked * Default Settings changed: * ScaleFx Threshold: now 0.43 (was 0.5) * ScaleFx Filter Corners: now 0 (was 1) * These settings result in a slighly clearer picture and less rounding of square corners * SMOOTH-ADV ntsc presets: ntsc_scale adjusted so it visually matches the regular ADV ntsc presets
2023-03-01 00:02:52 +11:00
Copyright (C) 2018-2023 guest(r) - guest.r@gmail.com
2022-06-25 10:06:45 +10:00
Incorporates many good ideas and suggestions from Dr. Venom.
I would also like give thanks to many Libretro forums members for continuous feedback, suggestions and caring about the shader.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIGMA_HOR;
float HSHARPNESS;
float S_SHARP;
float HARNG;
2022-12-22 16:16:29 +11:00
float HSHARP;
2023-01-26 04:59:48 +11:00
float NTSCspike;
2022-06-25 10:06:45 +10:00
} params;
2023-01-26 04:59:48 +11:00
//---------------------------------------------------------------------------------------------------
// NTSC Filtering
//---------------------------------------------------------------------------------------------------
#pragma parameter HSM_NTSC_FILTERING_EMPTY_LINE " " 0 0 0.001 0.001
#pragma parameter HSM_NTSC_FILTERING_TITLE "[ NTSC FILTERING OPTIONS ]: " 0.0 0.0 1.0 1.0
2022-06-25 10:06:45 +10:00
Mega Bezel V1.11.0_2023-02-25 Changes: * Guest Advanced updated to crt-guest-advanced-2023-02-25-release1 * Improvements to the new Magic Glow feature * Turn Magic Glow on and Increase the Glow amount to see the effect * New Slot Mask Mitigation option to reduce moire * Added/Restored Guest's Raster Bloom as well as Overscan control * Updated Comments in presets to use # instead of // as per @hunterk's request * Added rotation option for Rotate CRT Tube: * -1 = 90 Degrees Clockwise (or 270 Counter Clockwise) * 0 = No Rotation * 1 = 90 Degrees Counter Clockwise * Added groundwork for the wildcard replacement feature so presets will auto rotate and not flip in the future * Added DREZ presets which keep the horizontal resolution * Helpful for applying to modern games, these two are good to try * `Presets\Base_CRT_Presets_DREZ\MBZ__3__STD__GDV__DREZ_X-VIEWPORT_Y-240p.slangp` * `Presets\Base_CRT_Presets_DREZ\MBZ__3__STD__GDV__DREZ_X-VIEWPORT_Y-480p.slangp` * Also looks good on MVC2, try `Presets\Base_CRT_Presets_DREZ\MBZ__3__STD__GDV__DREZ_X-VIEWPORT_Y-240p.slangp` * Updated preset capability and performance table * Added contrast for signal noise * Added some more Sinden presets for SCREEN-ONLY and POTATO * Added Screen Region to Resolution Debug text * Good for getting the screen region pixel coordinates if you need them * Adjusted Ambient Lighting Scaling when using the Inherit Zoom scale mode * Now when you zoom out it is much less likely to generate a black frame covering the outer parts of the background image * The minimum size of the lighting texture will be close to the height of the current viewport * This reduces the likelihood that we will see the cutoff * ScaleFx: Exposed more of the settings so they can be tweaked * Default Settings changed: * ScaleFx Threshold: now 0.43 (was 0.5) * ScaleFx Filter Corners: now 0 (was 1) * These settings result in a slighly clearer picture and less rounding of square corners * SMOOTH-ADV ntsc presets: ntsc_scale adjusted so it visually matches the regular ADV ntsc presets
2023-03-01 00:02:52 +11:00
#pragma parameter HSHARPNESS " NTSC Horizontal Filter Range -- HSHARPNESS" 1.5 1.0 1.5 0.05
2022-06-25 10:06:45 +10:00
#define HSHARPNESS params.HSHARPNESS
2023-01-26 04:59:48 +11:00
#pragma parameter SIGMA_HOR " NTSC Horizontal Blur Sigma -- SIGMA_HOR" 0.90 0.1 7.0 0.05
2022-06-25 10:06:45 +10:00
#define SIGMA_HOR params.SIGMA_HOR
2023-01-26 04:59:48 +11:00
#pragma parameter S_SHARP " NTSC Substractive Sharpness -- S_SHARP" 0.9 0.0 2.0 0.10
2022-06-25 10:06:45 +10:00
#define S_SHARP params.S_SHARP
2023-01-26 04:59:48 +11:00
#pragma parameter HSHARP " NTSC Sharpness Definition -- HSHARP" 1.2 0.0 2.0 0.10
2022-06-25 10:06:45 +10:00
#define HSHARP params.HSHARP
2023-01-26 04:59:48 +11:00
#pragma parameter HARNG " NTSC Substractive Sharpness Ringing -- HARNG" 0.4 0.0 4.0 0.10
#define HARNG params.HARNG
2022-06-25 10:06:45 +10:00
2023-01-26 04:59:48 +11:00
#pragma parameter NTSCspike " NTSC Scanline Spike Removal -- NTSCspike" 1.0 0.0 2.0 0.10
#define spike params.NTSCspike
2022-06-25 10:06:45 +10:00
Mega Bezel update to V1.0.003_2022-07-28_Rev-1 * Updated to the latest guest release: crt-guest-advanced-2022-07-27-release1 * Changed Guest mask size to 1 by default so that there isn't inconsistency using guest settings in the Mega Bezel * Adjusted the default SMOOTH-ADV scaling parameters for a sharper smooth look: * HSM_CORE_RES_SAMPLING_MULT_SCANLINE_DIR = 300 * HSM_CORE_RES_SAMPLING_MULT_OPPOSITE_DIR = 125 * HSM_DOWNSAMPLE_BLUR_SCANLINE_DIR = 0 * HSM_DOWNSAMPLE_BLUR_OPPOSITE_DIR = 0 * Added **Shift Sampling Relative to Scanlines** to shift the image relative to the scanlines * The ScaleFx settings now only appear on the SMOOTH-ADV preset nearer the bottom of the parameter list * Fixed Double image when using cropping in NTSC presets reported by @JHorbach1 * Updated to crt-guest-advanced-2022-07-17-release1 * Includes Scanline Gamma * Tube Gel and Diffuse Fixes * Gel is now mapped to the tube, independent of the black edge * Added a feature to add a bit of tube diffuse shading to the GEL this should make it look a little more natural * [ TUBE COLORED GEL IMAGE ] > Normal Multiply by Tube Diffuse Shading * HSM_TUBE_BLACK_EDGE_LAYERING_MODE has been removed as it's not needed anymore * CRT Multiply blend mode now works better when there is extra tube thickness * Changed HSM_TUBE_DIFFUSE_IMAGE_SCALE to 120 by default to have a less rounded look * If you want a stronger rounded shaded look reset it to 100 * Fixed Scale discrepancy when using the Cab Glass Image * Added Shadow Opacity param to control shadow being applied to the static tube highlight
2022-07-29 11:56:28 +10:00
#define COMPAT_TEXTURE(c,d) texture(c,d)
2022-06-25 10:06:45 +10:00
#define TEX0 vTexCoord
#define OutputSize params.OutputSize
#define gl_FragCoord (vTexCoord * OutputSize.xy)
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord * 1.00001;
2022-06-25 10:06:45 +10:00
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D LinearizePass;
layout(set = 0, binding = 3) uniform sampler2D InfoCachePass;
float invsqrsigma = 1.0/(2.0*SIGMA_HOR*SIGMA_HOR);
float gaussian(float x)
{
return exp(-x*x*invsqrsigma);
}
void main()
{
// HSM Added
vec2 viewportCoordTransformed = HSM_GetViewportCoordWithZoomAndPan(vTexCoord);
2022-10-11 07:26:21 +11:00
HSM_UpdateGlobalScreenValuesFromCache(InfoCachePass, vTexCoord);
2022-06-25 10:06:45 +10:00
// If it's the potato preset render the whole frame
#ifndef IS_POTATO_PRESET
#ifndef IS_NO_REFLECT_PRESET
// Have to get the scale of the coordinates so we can figure out the size of the onscreen rectangle of the area
HSM_GetBezelCoords(TUBE_DIFFUSE_COORD,
TUBE_DIFFUSE_SCALE,
2022-06-25 10:06:45 +10:00
TUBE_SCALE,
SCREEN_ASPECT,
false,
BEZEL_OUTSIDE_SCALE,
BEZEL_OUTSIDE_COORD,
BEZEL_OUTSIDE_CURVED_COORD,
FRAME_OUTSIDE_CURVED_COORD);
#endif
#endif
/* HSM Removed
2022-12-22 16:16:29 +11:00
vec2 prescalex = vec2(textureSize(LinearizePass, 0)) / params.OriginalSize.xy;
vec4 SourceSize = params.OriginalSize * vec4(2.0*prescalex.x, prescalex.y, 0.5/prescalex.x, 1.0/prescalex.y);
2022-06-25 10:06:45 +10:00
*/
2022-12-22 16:16:29 +11:00
vec2 prescalex = global.NegativeCropAddedPassSize.xy / params.OriginalSize.xy;
vec4 SourceSize = global.NegativeCropAddedPassSize * vec4(2.0*prescalex.x, prescalex.y, 0.5/prescalex.x, 1.0/prescalex.y);
2022-06-25 10:06:45 +10:00
float f = fract(SourceSize.x * vTexCoord.x);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec3 color = 0.0.xxx;
float scolor = 0.0;
vec2 dx = vec2(SourceSize.z, 0.0);
float w = 0.0;
float swsum = 0.0;
float wsum = 0.0;
vec3 pixel;
vec3 cmax = 0.0.xxx;
vec3 cmin = 1.0.xxx;
2023-01-26 04:59:48 +11:00
float sharp = gaussian(HSHARPNESS) * S_SHARP;
2022-06-25 10:06:45 +10:00
float maxsharp = 0.20;
2023-01-26 04:59:48 +11:00
float FPR = HSHARPNESS;
2022-06-25 10:06:45 +10:00
float fpx = 0.0;
float sp = 0.0;
float sw = 0.0;
float ts = 0.025;
vec3 luma = vec3(0.2126, 0.7152, 0.0722);
float LOOPSIZE = ceil(2.0*FPR);
float CLAMPSIZE = round(2.0*LOOPSIZE/3.0);
float n = -LOOPSIZE;
do
{
pixel = COMPAT_TEXTURE(LinearizePass, tex + n*dx).rgb;
sp = max(max(pixel.r,pixel.g),pixel.b);
w = gaussian(n+f) - sharp;
fpx = abs(n+f-sign(n)*FPR)/FPR;
if (abs(n) <= CLAMPSIZE) { cmax = max(cmax, pixel); cmin = min(cmin, pixel); }
2022-12-22 16:16:29 +11:00
if (w < 0.0) w = clamp(w, mix(-maxsharp, 0.0, pow(clamp(fpx,0.0,1.0), HSHARP)), 0.0);
2022-06-25 10:06:45 +10:00
color = color + w * pixel;
wsum = wsum + w;
sw = max(w, 0.0) * (dot(pixel,luma) + ts);
scolor = scolor + sw * sp;
swsum = swsum + sw;
n = n + 1.0;
} while (n <= LOOPSIZE);
color = color / wsum;
scolor = scolor / swsum;
color = clamp(mix(clamp(color, cmin, cmax), color, HARNG), 0.0, 1.0);
scolor = clamp(mix(max(max(color.r, color.g),color.b), scolor, spike), 0.0, 1.0);
FragColor = vec4(color, scolor);
}