Merge pull request #233 from MajorPainTheCactus/hdr_4_2

V4.2 Sony PVM 4K HDR Shader
This commit is contained in:
hizzlekizzle 2022-02-27 08:19:46 -06:00 committed by GitHub
commit 196414fecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 134 additions and 111 deletions

View file

@ -80,24 +80,25 @@ layout(push_constant) uniform Push
#endif // WHITE_BALANCE_CONTROL #endif // WHITE_BALANCE_CONTROL
} params; } params;
#pragma parameter Title "SONY PVM/BVM HDR SHADER" 0.0 0.0 0.0 0.0
#pragma parameter Space0 " " 0.0 0.0 0.0 0.0 #pragma parameter Title "SONY PVM/BVM HDR SHADER" 0.0 0.0 0.0001 0.0
#pragma parameter Support0 "SUPPORTED: RGB/BGR LCD, QD-OLED Displays" 0.0 0.0 0.0 0.0 #pragma parameter Space0 " " 0.0 0.0 0.0001 0.0
#pragma parameter Support1 "NOT SUPPORTED: WRGB OLED Displays" 0.0 0.0 0.0 0.0 #pragma parameter Support0 "SUPPORTED: RGB/BGR LCD, QD-OLED Displays" 0.0 0.0 0.0001 0.0
#pragma parameter Support2 "MIN SPEC: DisplayHDR 600, 4K, RetroArch v1.10" 0.0 0.0 0.0 0.0 #pragma parameter Support1 "NOT SUPPORTED: WRGB OLED Displays" 0.0 0.0 0.0001 0.0
#pragma parameter Support3 "REC SPEC: DisplayHDR 1000, 4K+, RetroArch v1.10" 0.0 0.0 0.0 0.0 #pragma parameter Support2 "MIN SPEC: DisplayHDR 600, 4K, RetroArch v1.10" 0.0 0.0 0.0001 0.0
#pragma parameter Space1 " " 0.0 0.0 0.0 0.0 #pragma parameter Support3 "REC SPEC: DisplayHDR 1000, 4K+, RetroArch v1.10" 0.0 0.0 0.0001 0.0
#pragma parameter Instructions0 "HDR: Enable HDR: On" 0.0 0.0 0.0 0.0 #pragma parameter Space1 " " 0.0 0.0 0.0001 0.0
#pragma parameter Instructions1 "SCALING: Integer Scale: ON" 0.0 0.0 0.0 0.0 #pragma parameter Instructions0 "HDR: Enable HDR: On" 0.0 0.0 0.0001 0.0
#pragma parameter Instructions2 "SCALING: Integer Overscale: ON" 0.0 0.0 0.0 0.0 #pragma parameter Instructions1 "SCALING: Integer Scale: ON" 0.0 0.0 0.0001 0.0
#pragma parameter Instructions3 "SCALING: Apect Ratio: Core Provided" 0.0 0.0 0.0 0.0 #pragma parameter Instructions2 "SCALING: Integer Overscale: ON" 0.0 0.0 0.0001 0.0
#pragma parameter Space2 " " 0.0 0.0 0.0 0.0 #pragma parameter Instructions3 "SCALING: Apect Ratio: Core Provided" 0.0 0.0 0.0001 0.0
#pragma parameter UserSettings "USER SETTINGS:" 0.0 0.0 0.0 0.0 #pragma parameter Space2 " " 0.0 0.0 0.0001 0.0
#pragma parameter HDR " SDR/HDR" 1.0 0.0 1.0 1.0 #pragma parameter UserSettings "USER SETTINGS:" 0.0 0.0 0.0001 0.0
#pragma parameter HDR " SDR | HDR" 1.0 0.0 1.0 1.0
#pragma parameter MaxNits " Display's Peak Luminance" 700.0 0.0 10000.0 10.0 #pragma parameter MaxNits " Display's Peak 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 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 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
@ -108,12 +109,12 @@ layout(push_constant) uniform Push
#pragma parameter GreenHorizontalConvergence " Green Horizontal Convergence" 0.00 -10.0 10.0 0.01 #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.01 #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.0001 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.0001 0.0
#pragma parameter CRTScreenType " CRT Type: Aperture Grille/Shadow Mask/Slot Mask" 0.0 0.0 2.0 1.0 #pragma parameter CRTScreenType " CRT Type: APERTURE GRILLE | SHADOW MASK | SLOT MASK" 0.0 0.0 2.0 1.0
#pragma parameter CRTResolution " CRT Resolution: 600TVL/800TVL/1000TVL" 0.0 0.0 2.0 1.0 #pragma parameter CRTResolution " CRT Resolution: 600TVL | 800TVL | 1000TVL" 0.0 0.0 2.0 1.0
#pragma parameter DeveloperSettings0 " VERTICAL SETTINGS:" 0.0 0.0 0.0 0.0 #pragma parameter DeveloperSettings0 " VERTICAL SETTINGS:" 0.0 0.0 0.0001 0.0
#pragma parameter RedScanlineMin " Red Scanline Min" 0.50 0.0 2.0 0.01 #pragma parameter RedScanlineMin " Red Scanline Min" 0.50 0.0 2.0 0.01
#pragma parameter RedScanlineMax " Red Scanline Max" 1.00 0.0 2.0 0.01 #pragma parameter RedScanlineMax " Red Scanline Max" 1.00 0.0 2.0 0.01
#pragma parameter RedScanlineAttack " Red Scanline Attack" 0.20 0.0 1.0 0.01 #pragma parameter RedScanlineAttack " Red Scanline Attack" 0.20 0.0 1.0 0.01
@ -123,7 +124,7 @@ layout(push_constant) uniform Push
#pragma parameter BlueScanlineMin " Blue Scanline Min" 0.50 0.0 2.0 0.01 #pragma parameter BlueScanlineMin " Blue Scanline Min" 0.50 0.0 2.0 0.01
#pragma parameter BlueScanlineMax " Blue Scanline Max" 1.00 0.0 2.0 0.01 #pragma parameter BlueScanlineMax " Blue Scanline Max" 1.00 0.0 2.0 0.01
#pragma parameter BlueScanlineAttack " Blue Scanline Attack" 0.20 0.0 1.0 0.01 #pragma parameter BlueScanlineAttack " Blue Scanline Attack" 0.20 0.0 1.0 0.01
#pragma parameter DeveloperSettings1 " HORIZONTAL SETTINGS:" 0.0 0.0 0.0 0.0 #pragma parameter DeveloperSettings1 " HORIZONTAL SETTINGS:" 0.0 0.0 0.0001 0.0
#pragma parameter RedBeamSharpness " Red Beam Sharpness" 1.75 0.0 5.0 0.05 #pragma parameter RedBeamSharpness " Red Beam Sharpness" 1.75 0.0 5.0 0.05
#pragma parameter RedBeamAttack " Red Beam Attack" 0.50 0.0 2.0 0.01 #pragma parameter RedBeamAttack " Red Beam Attack" 0.50 0.0 2.0 0.01
#pragma parameter GreenBeamSharpness " Green Beam Sharpness" 1.75 0.0 5.0 0.05 #pragma parameter GreenBeamSharpness " Green Beam Sharpness" 1.75 0.0 5.0 0.05
@ -131,12 +132,49 @@ layout(push_constant) uniform Push
#pragma parameter BlueBeamSharpness " Blue Beam Sharpness" 1.75 0.0 5.0 0.05 #pragma parameter BlueBeamSharpness " Blue Beam Sharpness" 1.75 0.0 5.0 0.05
#pragma parameter BlueBeamAttack " Blue Beam Attack" 0.50 0.0 2.0 0.01 #pragma parameter BlueBeamAttack " Blue Beam Attack" 0.50 0.0 2.0 0.01
#if WHITE_BALANCE_CONTROL #if WHITE_BALANCE_CONTROL
//#pragma parameter WhiteTemperature "White Temperature" 6500.0 0.0 13000.0 50.0 //#pragma parameter WhiteTemperature "White Temperature" 6500.0 0.0 13000.0 50.0
//#pragma parameter WhiteTint "White Tint" 0.0 -1.0 1.0 0.01 //#pragma parameter WhiteTint "White Tint" 0.0 -1.0 1.0 0.01
#endif // WHITE_BALANCE_CONTROL #endif // WHITE_BALANCE_CONTROL
#define HCRT_HDR params.HDR
#define HCRT_MAX_NITS params.MaxNits
#define HCRT_PAPER_WHITE_NITS params.PaperWhiteNits
#define HCRT_LCD_RESOLUTION params.LCDResolution
#define HCRT_LCD_SUBPIXEL params.LCDSubpixel
#define HCRT_BRIGHTNESS params.Brightness
#define HCRT_CONTRAST params.Contrast
#define HCRT_EXPAND_GAMUT params.ExpandGamut
#define HCRT_RED_VERTICAL_CONVERGENCE params.RedVerticalConvergence
#define HCRT_GREEN_VERTICAL_CONVERGENCE params.GreenVerticalConvergence
#define HCRT_BLUE_VERTICAL_CONVERGENCE params.BlueVerticalConvergence
#define HCRT_RED_HORIZONTAL_CONVERGENCE params.RedHorizontalConvergence
#define HCRT_GREEN_HORIZONTAL_CONVERGENCE params.GreenHorizontalConvergence
#define HCRT_BLUE_HORIZONTAL_CONVERGENCE params.BlueHorizontalConvergence
#define HCRT_CRT_SCREEN_TYPE params.CRTScreenType
#define HCRT_CRT_RESOLUTION params.CRTResolution
#define HCRT_RED_SCANLINE_MIN params.RedScanlineMin
#define HCRT_RED_SCANLINE_MAX params.RedScanlineMax
#define HCRT_RED_SCANLINE_ATTACK params.RedScanlineAttack
#define HCRT_GREEN_SCANLINE_MIN params.GreenScanlineMin
#define HCRT_GREEN_SCANLINE_MAX params.GreenScanlineMax
#define HCRT_GREEN_SCANLINE_ATTACK params.GreenScanlineAttack
#define HCRT_BLUE_SCANLINE_MIN params.BlueScanlineMin
#define HCRT_BLUE_SCANLINE_MAX params.BlueScanlineMax
#define HCRT_BLUE_SCANLINE_ATTACK params.BlueScanlineAttack
#define HCRT_RED_BEAM_SHARPNESS params.RedBeamSharpness
#define HCRT_RED_BEAM_ATTACK params.RedBeamAttack
#define HCRT_GREEN_BEAM_SHARPNESS params.GreenBeamSharpness
#define HCRT_GREEN_BEAM_ATTACK params.GreenBeamAttack
#define HCRT_BLUE_BEAM_SHARPNESS params.BlueBeamSharpness
#define HCRT_BLUE_BEAM_ATTACK params.BlueBeamAttack
#define COMPAT_TEXTURE(c, d) texture(c, d)
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
{ {
mat4 MVP; mat4 MVP;
@ -150,29 +188,15 @@ layout(std140, set = 0, binding = 0) uniform UBO
layout(location = 0) in vec4 Position; layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord; layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord; layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out float ScanlineSize;
layout(location = 2) out float InverseScanlineSize;
layout(location = 3) out vec3 VerticalConvergence;
layout(location = 4) out vec3 HorizontalConvergence;
void main() void main()
{ {
gl_Position = global.MVP * Position; gl_Position = global.MVP * Position;
vTexCoord = TexCoord * vec2(1.00001); // To resolve rounding issues when sampling vTexCoord = TexCoord * vec2(1.00001); // To resolve rounding issues when sampling
ScanlineSize = global.OutputSize.y / global.SourceSize.y;
InverseScanlineSize = 1.0f / ScanlineSize;
VerticalConvergence = vec3(params.RedVerticalConvergence, params.GreenVerticalConvergence, params.BlueVerticalConvergence);
HorizontalConvergence = vec3(params.RedHorizontalConvergence, params.GreenHorizontalConvergence, params.BlueHorizontalConvergence);
} }
#pragma stage fragment #pragma stage fragment
layout(location = 0) in vec2 vTexCoord; layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float ScanlineSize;
layout(location = 2) in float InverseScanlineSize;
layout(location = 3) in vec3 VerticalConvergence;
layout(location = 4) in vec3 HorizontalConvergence;
layout(location = 0) out vec4 FragColor; layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source; layout(set = 0, binding = 2) uniform sampler2D Source;
@ -376,9 +400,9 @@ float ModInteger(float a, float b)
vec3 InverseTonemapConditional(const vec3 sdr_balanced) vec3 InverseTonemapConditional(const vec3 sdr_balanced)
{ {
if(params.HDR > 0.0f) if(HCRT_HDR > 0.0f)
{ {
return InverseTonemap(sdr_balanced, params.MaxNits, params.PaperWhiteNits, kLumaRatio); return InverseTonemap(sdr_balanced, HCRT_MAX_NITS, HCRT_PAPER_WHITE_NITS, kLumaRatio);
} }
else else
{ {
@ -388,9 +412,9 @@ vec3 InverseTonemapConditional(const vec3 sdr_balanced)
vec3 Hdr10Conditional(const vec3 scanline_colour) vec3 Hdr10Conditional(const vec3 scanline_colour)
{ {
if(params.HDR > 0.0f) if(HCRT_HDR > 0.0f)
{ {
return Hdr10(scanline_colour, params.PaperWhiteNits, params.ExpandGamut); return Hdr10(scanline_colour, HCRT_PAPER_WHITE_NITS, HCRT_EXPAND_GAMUT);
} }
else else
{ {
@ -404,12 +428,12 @@ void main()
{ {
const vec2 current_position = vTexCoord * global.OutputSize.xy; const vec2 current_position = vTexCoord * global.OutputSize.xy;
vec3 scanline_colour = GenerateScanline(); vec3 scanline_colour = GenerateScanline(global.SourceSize.xy);
uint screen_type = uint(params.CRTScreenType); uint screen_type = uint(HCRT_CRT_SCREEN_TYPE);
uint crt_resolution = uint(params.CRTResolution); uint crt_resolution = uint(HCRT_CRT_RESOLUTION);
uint lcd_resolution = uint(params.LCDResolution); uint lcd_resolution = uint(HCRT_LCD_RESOLUTION);
uint lcd_subpixel_layout = uint(params.LCDSubpixel); uint lcd_subpixel_layout = uint(HCRT_LCD_SUBPIXEL);
switch(screen_type) switch(screen_type)
{ {

View file

@ -16,24 +16,24 @@ const vec4 kAttackControlPoints = vec4(0.0f, 1.0f, 1.0f, 1.0f);
vec4 RedBeamControlPoints(const bool falloff) vec4 RedBeamControlPoints(const bool falloff)
{ {
float inner_attack = clamp(params.RedBeamAttack, 0.0f, 1.0); float inner_attack = clamp(HCRT_RED_BEAM_ATTACK, 0.0f, 1.0);
float outer_attack = clamp(params.RedBeamAttack - 1.0f, 0.0f, 1.0); float outer_attack = clamp(HCRT_RED_BEAM_ATTACK - 1.0f, 0.0f, 1.0);
return falloff ? kFallOffControlPoints + vec4(0.0f, outer_attack, inner_attack, 0.0f) : kAttackControlPoints - vec4(0.0f, inner_attack, outer_attack, 0.0f); return falloff ? kFallOffControlPoints + vec4(0.0f, outer_attack, inner_attack, 0.0f) : kAttackControlPoints - vec4(0.0f, inner_attack, outer_attack, 0.0f);
} }
vec4 GreenBeamControlPoints(const bool falloff) vec4 GreenBeamControlPoints(const bool falloff)
{ {
float inner_attack = clamp(params.GreenBeamAttack, 0.0f, 1.0); float inner_attack = clamp(HCRT_GREEN_BEAM_ATTACK, 0.0f, 1.0);
float outer_attack = clamp(params.GreenBeamAttack - 1.0f, 0.0f, 1.0); float outer_attack = clamp(HCRT_GREEN_BEAM_ATTACK - 1.0f, 0.0f, 1.0);
return falloff ? kFallOffControlPoints + vec4(0.0f, outer_attack, inner_attack, 0.0f) : kAttackControlPoints - vec4(0.0f, inner_attack, outer_attack, 0.0f); return falloff ? kFallOffControlPoints + vec4(0.0f, outer_attack, inner_attack, 0.0f) : kAttackControlPoints - vec4(0.0f, inner_attack, outer_attack, 0.0f);
} }
vec4 BlueBeamControlPoints(const bool falloff) vec4 BlueBeamControlPoints(const bool falloff)
{ {
float inner_attack = clamp(params.BlueBeamAttack, 0.0f, 1.0); float inner_attack = clamp(HCRT_BLUE_BEAM_ATTACK, 0.0f, 1.0);
float outer_attack = clamp(params.BlueBeamAttack - 1.0f, 0.0f, 1.0); float outer_attack = clamp(HCRT_BLUE_BEAM_ATTACK - 1.0f, 0.0f, 1.0);
return falloff ? kFallOffControlPoints + vec4(0.0f, outer_attack, inner_attack, 0.0f) : kAttackControlPoints - vec4(0.0f, inner_attack, outer_attack, 0.0f); return falloff ? kFallOffControlPoints + vec4(0.0f, outer_attack, inner_attack, 0.0f) : kAttackControlPoints - vec4(0.0f, inner_attack, outer_attack, 0.0f);
} }
@ -56,7 +56,7 @@ vec3 ToLinear(vec3 colour)
float Contrast1(float linear, float channel) float Contrast1(float linear, float channel)
{ {
return (channel > 0.04045f) ? linear * pow(abs(channel) * (1.0f / 1.055f) + (0.055f / 1.055f), params.Contrast) : channel * (1.0f / 12.92f); return (channel > 0.04045f) ? linear * pow(abs(channel) * (1.0f / 1.055f) + (0.055f / 1.055f), HCRT_CONTRAST) : channel * (1.0f / 12.92f);
} }
vec3 Contrast(vec3 linear, vec3 colour) vec3 Contrast(vec3 linear, vec3 colour)
@ -69,17 +69,19 @@ 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 vec3 source_tex_coord_x, const vec3 narrowed_source_pixel_offset, inout vec3 next_prev) vec3 ScanlineColour(const vec2 source_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 * global.SourceSize.y) - VerticalConvergence) + 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; const vec3 current_source_center_y = floor(current_source_position_y) + 0.5f;
const vec3 source_tex_coord_y = current_source_center_y / global.SourceSize.y; const vec3 source_tex_coord_y = current_source_center_y / source_size.y;
const vec3 scanline_delta = fract(current_source_position_y) - 0.5f; 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 // Slightly increase the beam width to get maximum brightness
vec3 beam_distance = abs(scanline_delta - next_prev) - (kBeamWidth * InverseScanlineSize); vec3 beam_distance = abs(scanline_delta - next_prev) - (kBeamWidth / scanline_size);
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);
@ -90,29 +92,26 @@ vec3 ScanlineColour(const vec3 source_tex_coord_x, const vec3 narrowed_source_pi
next_prev.z = scanline_delta.z > 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_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 red_tex_coord_1 = vec2(source_tex_coord_x.x + (1.0f / source_size.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_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 green_tex_coord_1 = vec2(source_tex_coord_x.y + (1.0f / source_size.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_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 vec2 blue_tex_coord_1 = vec2(source_tex_coord_x.z + (1.0f / source_size.x), source_tex_coord_y.z);
const float red_0 = texture(Source, red_tex_coord_0).x; const float red_0 = COMPAT_TEXTURE(Source, red_tex_coord_0).x;
const float red_1 = texture(Source, red_tex_coord_1).x; const float red_1 = COMPAT_TEXTURE(Source, red_tex_coord_1).x;
const float green_0 = texture(Source, green_tex_coord_0).y; const float green_0 = COMPAT_TEXTURE(Source, green_tex_coord_0).y;
const float green_1 = texture(Source, green_tex_coord_1).y; const float green_1 = COMPAT_TEXTURE(Source, green_tex_coord_1).y;
const float blue_0 = texture(Source, blue_tex_coord_0).z; const float blue_0 = COMPAT_TEXTURE(Source, blue_tex_coord_0).z;
const float blue_1 = texture(Source, blue_tex_coord_1).z; const float blue_1 = COMPAT_TEXTURE(Source, blue_tex_coord_1).z;
const vec3 sdr_colour_0 = vec3(red_0, green_0, blue_0); const vec3 sdr_colour_0 = vec3(red_0, green_0, blue_0);
const vec3 sdr_colour_1 = vec3(red_1, green_1, blue_1); const vec3 sdr_colour_1 = vec3(red_1, green_1, blue_1);
//const vec3 sdr_colour_0 = texture(Source, source_tex_coord_0).xyz;
//const vec3 sdr_colour_1 = texture(Source, source_tex_coord_1).xyz;
const vec3 sdr_linear_0 = ToLinear(sdr_colour_0); const vec3 sdr_linear_0 = ToLinear(sdr_colour_0);
const vec3 sdr_linear_1 = ToLinear(sdr_colour_1); const vec3 sdr_linear_1 = ToLinear(sdr_colour_1);
@ -120,8 +119,8 @@ vec3 ScanlineColour(const vec3 source_tex_coord_x, const vec3 narrowed_source_pi
const vec3 sdr_constrast_1 = Contrast(sdr_linear_1, sdr_colour_1); const vec3 sdr_constrast_1 = Contrast(sdr_linear_1, sdr_colour_1);
#if WHITE_BALANCE_CONTROL #if WHITE_BALANCE_CONTROL
//const vec3 sdr_balanced_0 = WhiteBalance(sdr_constrast_0, params.WhiteTemperature, params.WhiteTint); //const vec3 sdr_balanced_0 = WhiteBalance(sdr_constrast_0, HCRT_WHITE_TEMPERATURE, HCRT_WHITE_TINT);
//const vec3 sdr_balanced_1 = WhiteBalance(sdr_constrast_1, params.WhiteTemperature, params.WhiteTint); //const vec3 sdr_balanced_1 = WhiteBalance(sdr_constrast_1, HCRT_WHITE_TEMPERATURE, HCRT_WHITE_TINT);
#else #else
const vec3 sdr_balanced_0 = sdr_constrast_0; const vec3 sdr_balanced_0 = sdr_constrast_0;
const vec3 sdr_balanced_1 = sdr_constrast_1; const vec3 sdr_balanced_1 = sdr_constrast_1;
@ -139,13 +138,13 @@ vec3 ScanlineColour(const vec3 source_tex_coord_x, const vec3 narrowed_source_pi
const vec3 hdr_colour = mix(hdr_colour_0, hdr_colour_1, horiz_interp); const vec3 hdr_colour = mix(hdr_colour_0, hdr_colour_1, horiz_interp);
const vec3 sdr_colour = mix(sdr_linear_0, sdr_linear_1, horiz_interp); const vec3 sdr_colour = mix(sdr_linear_0, sdr_linear_1, horiz_interp);
const float red_scanline_distance = clamp(scanline_distance.x / ((sdr_colour.r * (params.RedScanlineMax - params.RedScanlineMin)) + params.RedScanlineMin), 0.0f, 1.0f); const float red_scanline_distance = clamp(scanline_distance.x / ((sdr_colour.r * (HCRT_RED_SCANLINE_MAX - HCRT_RED_SCANLINE_MIN)) + HCRT_RED_SCANLINE_MIN), 0.0f, 1.0f);
const float green_scanline_distance = clamp(scanline_distance.y / ((sdr_colour.g * (params.GreenScanlineMax - params.GreenScanlineMin)) + params.GreenScanlineMin), 0.0f, 1.0f); const float green_scanline_distance = clamp(scanline_distance.y / ((sdr_colour.g * (HCRT_GREEN_SCANLINE_MAX - HCRT_GREEN_SCANLINE_MIN)) + HCRT_GREEN_SCANLINE_MIN), 0.0f, 1.0f);
const float blue_scanline_distance = clamp(scanline_distance.z / ((sdr_colour.b * (params.BlueScanlineMax - params.BlueScanlineMin)) + params.BlueScanlineMin), 0.0f, 1.0f); const float blue_scanline_distance = clamp(scanline_distance.z / ((sdr_colour.b * (HCRT_BLUE_SCANLINE_MAX - HCRT_BLUE_SCANLINE_MIN)) + HCRT_BLUE_SCANLINE_MIN), 0.0f, 1.0f);
const vec4 red_control_points = vec4(1.0f, 1.0f, sdr_colour.r * params.RedScanlineAttack, 0.0f); const vec4 red_control_points = vec4(1.0f, 1.0f, sdr_colour.r * HCRT_RED_SCANLINE_ATTACK, 0.0f);
const vec4 green_control_points = vec4(1.0f, 1.0f, sdr_colour.g * params.GreenScanlineAttack, 0.0f); const vec4 green_control_points = vec4(1.0f, 1.0f, sdr_colour.g * HCRT_GREEN_SCANLINE_ATTACK, 0.0f);
const vec4 blue_control_points = vec4(1.0f, 1.0f, sdr_colour.b * params.BlueScanlineAttack, 0.0f); const vec4 blue_control_points = vec4(1.0f, 1.0f, sdr_colour.b * HCRT_BLUE_SCANLINE_ATTACK, 0.0f);
const vec3 luminance = vec3(Bezier(red_scanline_distance, red_control_points), const vec3 luminance = vec3(Bezier(red_scanline_distance, red_control_points),
Bezier(green_scanline_distance, green_control_points), Bezier(green_scanline_distance, green_control_points),
@ -154,28 +153,28 @@ vec3 ScanlineColour(const vec3 source_tex_coord_x, const vec3 narrowed_source_pi
return luminance * hdr_colour; return luminance * hdr_colour;
} }
vec3 GenerateScanline() vec3 GenerateScanline(const vec2 source_size)
{ {
const vec3 current_source_position_x = vec3(vTexCoord.x * global.SourceSize.x) - HorizontalConvergence; 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; const vec3 current_source_center_x = floor(current_source_position_x) + 0.5f;
const vec3 source_tex_coord_x = current_source_center_x / global.SourceSize.x; const vec3 source_tex_coord_x = current_source_center_x / source_size.x;
const vec3 source_pixel_offset = fract(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(HCRT_RED_BEAM_SHARPNESS, HCRT_GREEN_BEAM_SHARPNESS, HCRT_BLUE_BEAM_SHARPNESS);
const vec3 narrowed_source_pixel_offset = clamp(((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));
vec3 next_prev = vec3(0.0f); vec3 next_prev = vec3(0.0f);
const vec3 scanline_colour0 = ScanlineColour(source_tex_coord_x, narrowed_source_pixel_offset, next_prev); const vec3 scanline_colour0 = ScanlineColour(source_size, source_tex_coord_x, narrowed_source_pixel_offset, next_prev);
// Optionally sample the neighbouring scanline // Optionally sample the neighbouring scanline
vec3 scanline_colour1 = vec3(0.0f); vec3 scanline_colour1 = vec3(0.0f);
if(params.RedScanlineMax > 1.0f || params.GreenScanlineMax > 1.0f || params.BlueScanlineMax > 1.0f) if(HCRT_RED_SCANLINE_MAX > 1.0f || HCRT_GREEN_SCANLINE_MAX > 1.0f || HCRT_BLUE_SCANLINE_MAX > 1.0f)
{ {
scanline_colour1 = ScanlineColour(source_tex_coord_x, narrowed_source_pixel_offset, next_prev); scanline_colour1 = ScanlineColour(source_size, source_tex_coord_x, narrowed_source_pixel_offset, next_prev);
} }
return scanline_colour0 * params.Brightness + scanline_colour1; return scanline_colour0 * HCRT_BRIGHTNESS + scanline_colour1;
} }