From 5e6351e2c75149e7913b3638d479be936762cfaf Mon Sep 17 00:00:00 2001 From: MajorPainTheCactus Date: Sat, 5 Mar 2022 15:53:41 +0000 Subject: [PATCH] Moved scanline_size out to main shader for easier integration with HSM --- hdr/shaders/crt-hdr.slang | 3 ++- hdr/shaders/include/scanline_generation.h | 10 ++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/hdr/shaders/crt-hdr.slang b/hdr/shaders/crt-hdr.slang index 2bbe0e2..00ddc55 100644 --- a/hdr/shaders/crt-hdr.slang +++ b/hdr/shaders/crt-hdr.slang @@ -417,7 +417,8 @@ vec3 Hdr10Conditional(const vec3 scanline_colour) void main() { - vec3 scanline_colour = GenerateScanline(global.SourceSize.xy); + const float scanline_size = global.OutputSize.y / global.SourceSize.y; + vec3 scanline_colour = GenerateScanline(global.SourceSize.xy, scanline_size); const uint screen_type = uint(HCRT_CRT_SCREEN_TYPE); const uint crt_resolution = uint(HCRT_CRT_RESOLUTION); diff --git a/hdr/shaders/include/scanline_generation.h b/hdr/shaders/include/scanline_generation.h index 3e43e16..d1c0e8f 100644 --- a/hdr/shaders/include/scanline_generation.h +++ b/hdr/shaders/include/scanline_generation.h @@ -46,7 +46,7 @@ vec3 InverseTonemapConditional(const vec3 linear) } } -vec3 ScanlineColour(const vec2 source_size, const vec3 source_tex_coord_x, const vec3 narrowed_source_pixel_offset, inout vec3 next_prev) +vec3 ScanlineColour(const vec2 source_size, const float scanline_size, const vec3 source_tex_coord_x, const vec3 narrowed_source_pixel_offset, inout vec3 next_prev) { const vec3 current_source_position_y = (vec3(vTexCoord.y * source_size.y) - vec3(HCRT_RED_VERTICAL_CONVERGENCE, HCRT_GREEN_VERTICAL_CONVERGENCE, HCRT_BLUE_VERTICAL_CONVERGENCE)) + next_prev; const vec3 current_source_center_y = floor(current_source_position_y) + 0.5f; @@ -55,8 +55,6 @@ vec3 ScanlineColour(const vec2 source_size, const vec3 source_tex_coord_x, const const vec3 scanline_delta = fract(current_source_position_y) - 0.5f; - const float scanline_size = global.OutputSize.y / source_size.y; - // Slightly increase the beam width to get maximum brightness vec3 beam_distance = abs(scanline_delta - next_prev) - (kBeamWidth / scanline_size); beam_distance = vec3(beam_distance.x < 0.0f ? 0.0f : beam_distance.x, @@ -115,7 +113,7 @@ vec3 ScanlineColour(const vec2 source_size, const vec3 source_tex_coord_x, const return luminance * hdr_colour; } -vec3 GenerateScanline(const vec2 source_size) +vec3 GenerateScanline(const vec2 source_size, const float scanline_size) { const vec3 current_source_position_x = vec3(vTexCoord.x * source_size.x) - vec3(HCRT_RED_HORIZONTAL_CONVERGENCE, HCRT_GREEN_HORIZONTAL_CONVERGENCE, HCRT_BLUE_HORIZONTAL_CONVERGENCE); const vec3 current_source_center_x = floor(current_source_position_x) + 0.5f; @@ -129,13 +127,13 @@ vec3 GenerateScanline(const vec2 source_size) vec3 next_prev = vec3(0.0f); - const vec3 scanline_colour0 = ScanlineColour(source_size, source_tex_coord_x, narrowed_source_pixel_offset, next_prev); + const vec3 scanline_colour0 = ScanlineColour(source_size, scanline_size, source_tex_coord_x, narrowed_source_pixel_offset, next_prev); // Optionally sample the neighbouring scanline vec3 scanline_colour1 = vec3(0.0f); if(HCRT_RED_SCANLINE_MAX > 1.0f || HCRT_GREEN_SCANLINE_MAX > 1.0f || HCRT_BLUE_SCANLINE_MAX > 1.0f) { - scanline_colour1 = ScanlineColour(source_size, source_tex_coord_x, narrowed_source_pixel_offset, next_prev); + scanline_colour1 = ScanlineColour(source_size, scanline_size, source_tex_coord_x, narrowed_source_pixel_offset, next_prev); } return scanline_colour0 + scanline_colour1;