Fixed a load of bugs with vertical and horizontal convergence

This commit is contained in:
MajorPainTheCactus 2022-02-26 13:01:00 +00:00
parent b49011c93e
commit ced4c91384
8 changed files with 48 additions and 55 deletions

View file

@ -38,9 +38,6 @@ CRTScreenType = "2.000000"
PaperWhiteNits = "600.000000" PaperWhiteNits = "600.000000"
Contrast = "0.000000" Contrast = "0.000000"
ExpandGamut = "1.000000" ExpandGamut = "1.000000"
RedVerticalConvergence = "0.000000"
GreenVerticalConvergence = "0.000000"
BlueVerticalConvergence = "0.000000"
RedScanlineMin = "0.8900000" RedScanlineMin = "0.8900000"
RedScanlineMax = "1.000000" RedScanlineMax = "1.000000"
RedScanlineAttack = "0.300000" RedScanlineAttack = "0.300000"

View file

@ -35,9 +35,6 @@ alias0 = ""
float_framebuffer0 = "false" float_framebuffer0 = "false"
srgb_framebuffer0 = "false" srgb_framebuffer0 = "false"
CRTScreenType = "2.000000" CRTScreenType = "2.000000"
RedVerticalConvergence = "0.000000"
GreenVerticalConvergence = "0.000000"
BlueVerticalConvergence = "0.000000"
RedScanlineMin = "0.650000" RedScanlineMin = "0.650000"
RedScanlineMax = "0.900000" RedScanlineMax = "0.900000"
RedScanlineAttack = "0.500000" RedScanlineAttack = "0.500000"

View file

@ -37,9 +37,6 @@ srgb_framebuffer0 = "false"
CRTScreenType = "1.000000" CRTScreenType = "1.000000"
CRTResolution = "2.000000" CRTResolution = "2.000000"
PaperWhiteNits = "400.000000" PaperWhiteNits = "400.000000"
RedVerticalConvergence = "0.000000"
GreenVerticalConvergence = "0.000000"
BlueVerticalConvergence = "0.000000"
RedScanlineMin = "0.550000" RedScanlineMin = "0.550000"
RedScanlineMax = "0.800000" RedScanlineMax = "0.800000"
RedScanlineAttack = "1.000000" RedScanlineAttack = "1.000000"

View file

@ -1,6 +1,6 @@
#reference "crt-sony-pvm-4k-hdr.slangp" #reference "crt-sony-pvm-4k-hdr.slangp"
CRTResolution = "1.000000" CRTResolution = "1.000000"
RedVerticalConvergence = "0.500000" RedVerticalConvergence = "0.250000"
GreenVerticalConvergence = "0.000000" GreenVerticalConvergence = "0.000000"
BlueVerticalConvergence = "0.000000" BlueVerticalConvergence = "0.000000"
RedScanlineMin = "0.250000" RedScanlineMin = "0.250000"

View file

@ -34,7 +34,7 @@ mipmap_input0 = "false"
alias0 = "" alias0 = ""
float_framebuffer0 = "false" float_framebuffer0 = "false"
srgb_framebuffer0 = "false" srgb_framebuffer0 = "false"
RedVerticalConvergence = "-0.500000" RedVerticalConvergence = "-0.200000"
GreenVerticalConvergence = "0.000000" GreenVerticalConvergence = "0.000000"
BlueVerticalConvergence = "0.000000" BlueVerticalConvergence = "0.000000"
RedScanlineMin = "0.550000" RedScanlineMin = "0.550000"

View file

@ -37,9 +37,6 @@ srgb_framebuffer0 = "false"
CRTScreenType = "1.000000" CRTScreenType = "1.000000"
CRTResolution = "2.000000" CRTResolution = "2.000000"
PaperWhiteNits = "400.000000" PaperWhiteNits = "400.000000"
RedVerticalConvergence = "0.000000"
GreenVerticalConvergence = "0.000000"
BlueVerticalConvergence = "0.000000"
RedScanlineMin = "0.5000000" RedScanlineMin = "0.5000000"
RedScanlineMax = "1.000000" RedScanlineMax = "1.000000"
RedScanlineAttack = "0.350000" RedScanlineAttack = "0.350000"

View file

@ -41,6 +41,7 @@ layout(push_constant) uniform Push
float PaperWhiteNits; float PaperWhiteNits;
float LCDResolution; float LCDResolution;
float LCDSubpixel; float LCDSubpixel;
float Brightness;
float Contrast; float Contrast;
float ExpandGamut; float ExpandGamut;
float RedVerticalConvergence; float RedVerticalConvergence;
@ -97,14 +98,15 @@ layout(push_constant) uniform Push
#pragma parameter PaperWhiteNits " Display's Paper White Luminance" 700.0 0.0 10000.0 10.0 #pragma parameter PaperWhiteNits " Display's Paper White Luminance" 700.0 0.0 10000.0 10.0
#pragma parameter LCDResolution " Display's Resolution: 4K/8K" 0.0 0.0 1.0 1.0 #pragma parameter LCDResolution " Display's Resolution: 4K/8K" 0.0 0.0 1.0 1.0
#pragma parameter LCDSubpixel " Display's Subpixel Layout: RGB/BGR" 0.0 0.0 1.0 1.0 #pragma parameter LCDSubpixel " Display's Subpixel Layout: RGB/BGR" 0.0 0.0 1.0 1.0
#pragma parameter Brightness " Brightness" 1.0 0.0 2.0 0.01
#pragma parameter Contrast " Contrast" -0.3 -3.0 3.0 0.05 #pragma parameter Contrast " Contrast" -0.3 -3.0 3.0 0.05
#pragma parameter ExpandGamut " Original/Vivid" 0.0 0.0 1.0 1.0 #pragma parameter ExpandGamut " Original/Vivid" 0.0 0.0 1.0 1.0
#pragma parameter RedVerticalConvergence " Red Vertical Convergence" 0.00 -10.0 10.0 0.05 #pragma parameter RedVerticalConvergence " Red Vertical Convergence" 0.00 -10.0 10.0 0.01
#pragma parameter GreenVerticalConvergence " Green Vertical Convergence" 0.00 -10.0 10.0 0.05 #pragma parameter GreenVerticalConvergence " Green Vertical Convergence" 0.00 -10.0 10.0 0.01
#pragma parameter BlueVerticalConvergence " Blue Vertical Convergence" 0.00 -10.0 10.0 0.05 #pragma parameter BlueVerticalConvergence " Blue Vertical Convergence" 0.00 -10.0 10.0 0.01
#pragma parameter RedHorizontalConvergence " Red Horizontal Convergence" 0.00 -10.0 10.0 0.05 #pragma parameter RedHorizontalConvergence " Red Horizontal Convergence" 0.00 -10.0 10.0 0.01
#pragma parameter GreenHorizontalConvergence " Green Horizontal Convergence" 0.00 -10.0 10.0 0.05 #pragma parameter GreenHorizontalConvergence " Green Horizontal Convergence" 0.00 -10.0 10.0 0.01
#pragma parameter BlueHorizontalConvergence " Blue Horizontal Convergence" 0.00 -10.0 10.0 0.05 #pragma parameter BlueHorizontalConvergence " Blue Horizontal Convergence" 0.00 -10.0 10.0 0.01
#pragma parameter Space3 " " 0.0 0.0 0.0 0.0 #pragma parameter Space3 " " 0.0 0.0 0.0 0.0
#pragma parameter DeveloperSettings "DEVELOPER SETTINGS:" 0.0 0.0 0.0 0.0 #pragma parameter DeveloperSettings "DEVELOPER SETTINGS:" 0.0 0.0 0.0 0.0
@ -162,7 +164,7 @@ void main()
InverseScanlineSize = 1.0f / ScanlineSize; InverseScanlineSize = 1.0f / ScanlineSize;
VerticalConvergence = vec3(params.RedVerticalConvergence, params.GreenVerticalConvergence, params.BlueVerticalConvergence); VerticalConvergence = vec3(params.RedVerticalConvergence, params.GreenVerticalConvergence, params.BlueVerticalConvergence);
HorizontalConvergence = vec3(params.RedHorizontalConvergence, params.GreenHorizontalConvergence, params.BlueHorizontalConvergence) / global.SourceSize.x; HorizontalConvergence = vec3(params.RedHorizontalConvergence, params.GreenHorizontalConvergence, params.BlueHorizontalConvergence);
} }
#pragma stage fragment #pragma stage fragment
@ -402,7 +404,7 @@ void main()
{ {
const vec2 current_position = vTexCoord * global.OutputSize.xy; const vec2 current_position = vTexCoord * global.OutputSize.xy;
vec3 scanline_colour = GenerateScanline(current_position); vec3 scanline_colour = GenerateScanline();
uint screen_type = uint(params.CRTScreenType); uint screen_type = uint(params.CRTScreenType);
uint crt_resolution = uint(params.CRTResolution); uint crt_resolution = uint(params.CRTResolution);

View file

@ -69,35 +69,34 @@ vec3 Ramp(const vec3 luminance, const vec3 colour)
return clamp(luminance * colour, 0.0, 1.0); return clamp(luminance * colour, 0.0, 1.0);
} }
vec3 ScanlineColour(const float current_position, const float current_center, const float source_tex_coord_x, const vec3 narrowed_source_pixel_offset, inout float next_prev ) vec3 ScanlineColour(const vec3 source_tex_coord_x, const vec3 narrowed_source_pixel_offset, inout vec3 next_prev)
{ {
const float current_source_position_y = (vTexCoord.y * global.SourceSize.y) - next_prev; const vec3 current_source_position_y = (vec3(vTexCoord.y * global.SourceSize.y) - VerticalConvergence) + next_prev;
const float current_source_center_y = floor(current_source_position_y) + 0.5f; const vec3 current_source_center_y = floor(current_source_position_y) + 0.5f;
const float source_tex_coord_y = current_source_center_y / global.SourceSize.y; const vec3 source_tex_coord_y = current_source_center_y / global.SourceSize.y;
const vec2 source_tex_coord_0 = vec2(source_tex_coord_x, source_tex_coord_y); const vec3 scanline_delta = fract(current_source_position_y) - 0.5f;
const vec2 source_tex_coord_1 = vec2(source_tex_coord_x + (1.0f / global.SourceSize.x), source_tex_coord_y);
const vec2 red_tex_coord_0 = source_tex_coord_0 + vec2(HorizontalConvergence.x, 0.0f); // Slightly increase the beam width to get maximum brightness
const vec2 red_tex_coord_1 = source_tex_coord_1 + vec2(HorizontalConvergence.x, 0.0f); vec3 beam_distance = abs(scanline_delta - next_prev) - (kBeamWidth * InverseScanlineSize);
const vec2 green_tex_coord_0 = source_tex_coord_0 + vec2(HorizontalConvergence.y, 0.0f);
const vec2 green_tex_coord_1 = source_tex_coord_1 + vec2(HorizontalConvergence.y, 0.0f);
const vec2 blue_tex_coord_0 = source_tex_coord_0 + vec2(HorizontalConvergence.z, 0.0f);
const vec2 blue_tex_coord_1 = source_tex_coord_1 + vec2(HorizontalConvergence.z, 0.0f);
const float scanline_position = current_source_center_y * ScanlineSize;
const vec3 scanline_delta = vec3(scanline_position) - (vec3(current_center) - VerticalConvergence);
vec3 beam_distance = abs(scanline_delta) - kBeamWidth;
beam_distance = vec3(beam_distance.x < 0.0f ? 0.0f : beam_distance.x, beam_distance = vec3(beam_distance.x < 0.0f ? 0.0f : beam_distance.x,
beam_distance.y < 0.0f ? 0.0f : beam_distance.y, beam_distance.y < 0.0f ? 0.0f : beam_distance.y,
beam_distance.z < 0.0f ? 0.0f : beam_distance.z); beam_distance.z < 0.0f ? 0.0f : beam_distance.z);
const vec3 scanline_distance = beam_distance * InverseScanlineSize * 2.0f; const vec3 scanline_distance = beam_distance * 2.0f;
next_prev = scanline_delta.x > 0.0f ? 1.0f : -1.0f; next_prev.x = scanline_delta.x > 0.0f ? 1.0f : -1.0f;
next_prev.y = scanline_delta.y > 0.0f ? 1.0f : -1.0f;
next_prev.z = scanline_delta.z > 0.0f ? 1.0f : -1.0f;
const vec2 red_tex_coord_0 = vec2(source_tex_coord_x.x, source_tex_coord_y.x);
const vec2 red_tex_coord_1 = vec2(source_tex_coord_x.x + (1.0f / global.SourceSize.x), source_tex_coord_y.x);
const vec2 green_tex_coord_0 = vec2(source_tex_coord_x.y, source_tex_coord_y.y);
const vec2 green_tex_coord_1 = vec2(source_tex_coord_x.y + (1.0f / global.SourceSize.x), source_tex_coord_y.y);
const vec2 blue_tex_coord_0 = vec2(source_tex_coord_x.z, source_tex_coord_y.z);
const vec2 blue_tex_coord_1 = vec2(source_tex_coord_x.z + (1.0f / global.SourceSize.x), source_tex_coord_y.z);
const float red_0 = texture(Source, red_tex_coord_0).x; const float red_0 = texture(Source, red_tex_coord_0).x;
const float red_1 = texture(Source, red_tex_coord_1).x; const float red_1 = texture(Source, red_tex_coord_1).x;
@ -155,24 +154,28 @@ vec3 ScanlineColour(const float current_position, const float current_center, co
return luminance * hdr_colour; return luminance * hdr_colour;
} }
vec3 GenerateScanline(const vec2 current_position) vec3 GenerateScanline()
{ {
const float current_center = floor(current_position.y) + 0.5f; const vec3 current_source_position_x = vec3(vTexCoord.x * global.SourceSize.x) - HorizontalConvergence;
const vec3 current_source_center_x = floor(current_source_position_x) + 0.5f;
const float current_source_position_x = vTexCoord.x * global.SourceSize.x;
const float current_source_center_x = floor(current_source_position_x) + 0.5f;
const float source_tex_coord_x = current_source_center_x / global.SourceSize.x; const vec3 source_tex_coord_x = current_source_center_x / global.SourceSize.x;
const float source_pixel_offset = current_source_position_x - floor(current_source_position_x); const vec3 source_pixel_offset = fract(current_source_position_x);
const vec3 beam_sharpness = vec3(params.RedBeamSharpness, params.GreenBeamSharpness, params.BlueBeamSharpness); const vec3 beam_sharpness = vec3(params.RedBeamSharpness, params.GreenBeamSharpness, params.BlueBeamSharpness);
const vec3 narrowed_source_pixel_offset = clamp(((vec3(source_pixel_offset) - vec3(0.5f)) * beam_sharpness) + vec3(0.5f), vec3(0.0f), vec3(1.0f)); const vec3 narrowed_source_pixel_offset = clamp(((source_pixel_offset - vec3(0.5f)) * beam_sharpness) + vec3(0.5f), vec3(0.0f), vec3(1.0f));
float next_prev = 0.0f; vec3 next_prev = vec3(0.0f);
const vec3 scanline_colour0 = ScanlineColour(current_position.y, current_center, source_tex_coord_x, narrowed_source_pixel_offset, next_prev); const vec3 scanline_colour0 = ScanlineColour(source_tex_coord_x, narrowed_source_pixel_offset, next_prev);
const vec3 scanline_colour1 = ScanlineColour(current_position.y, current_center, source_tex_coord_x, narrowed_source_pixel_offset, next_prev);
return scanline_colour0 + scanline_colour1; // Optionally sample the neighbouring scanline
vec3 scanline_colour1 = vec3(0.0f);
if(params.RedScanlineMax > 1.0f || params.GreenScanlineMax > 1.0f || params.BlueScanlineMax > 1.0f)
{
scanline_colour1 = ScanlineColour(source_tex_coord_x, narrowed_source_pixel_offset, next_prev);
}
return scanline_colour0 * params.Brightness + scanline_colour1;
} }