crt-royale fixes

This commit is contained in:
hunterk 2017-11-30 09:03:34 -06:00
parent eaf306f550
commit 202d0c7684
5 changed files with 66 additions and 53 deletions

View file

@ -91,8 +91,6 @@ layout(location = 0) out vec2 tex_uv;
layout(location = 1) out vec2 uv_step; // uv size of a texel (x) and scanline (y)
layout(location = 2) out vec2 il_step_multiple; // (1, 1) = progressive, (1, 2) = interlaced
layout(location = 3) out float pixel_height_in_scanlines; // Height of an output pixel in scanlines
layout(location = 4) out float sigma_range;
layout(location = 5) out float shape_range;
void main()
{
@ -111,10 +109,11 @@ void main()
// values. Compute {sigma, shape}_range outside of scanline_contrib() so
// they aren't computed once per scanline (6 times per fragment and up to
// 18 times per vertex):
const float sigma_range = max(beam_max_sigma, beam_min_sigma) -
beam_min_sigma;
const float shape_range = max(beam_max_shape, beam_min_shape) -
beam_min_shape;
// TODO/FIXME: if these aren't used, why are they calculated? commenting for now
// const floatsigma_range = max(beam_max_sigma, beam_min_sigma) -
// beam_min_sigma;
// const float shape_range = max(beam_max_shape, beam_min_shape) -
// beam_min_shape;
// We need the pixel height in scanlines for antialiased/integral sampling:
const float ph = (video_size_.y / IN.output_size.y) /
@ -128,8 +127,6 @@ layout(location = 0) in vec2 tex_uv;
layout(location = 1) in vec2 uv_step; // uv size of a texel (x) and scanline (y)
layout(location = 2) in vec2 il_step_multiple; // (1, 1) = progressive, (1, 2) = interlaced
layout(location = 3) in float pixel_height_in_scanlines; // Height of an output pixel in scanlines
layout(location = 4) in float sigma_range;
layout(location = 5) in float shape_range;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define input_texture Source
@ -224,29 +221,28 @@ void main()
// Calculate {sigma, shape}_range outside of scanline_contrib so it's only
// done once per pixel (not 6 times) with runtime params. Don't reuse the
// vertex shader calculations, so static versions can be constant-folded.
// TODO/FIXME: nvm, use the ones from the vertex /shrug
/* const float sigma_range = max(beam_max_sigma, beam_min_sigma) -
const float sigma_range = max(beam_max_sigma, beam_min_sigma) -
beam_min_sigma;
const float shape_range = max(beam_max_shape, beam_min_shape) -
beam_min_shape;*/
beam_min_shape;
// Calculate and sum final scanline contributions, starting with lines 2/3.
// There is no normalization step, because we're not interpolating a
// continuous signal. Instead, each scanline is an additive light source.
const float3 scanline2_contrib = scanline_contrib(dist2,
scanline2_color, ph, sigma_range, shape_range);
const float3 scanline3_contrib = scanline_contrib(abs(float3(1.0) - dist2),
const float3 scanline3_contrib = scanline_contrib(abs(float3(1.0,1.0,1.0) - dist2),
scanline3_color, ph, sigma_range, shape_range);
float3 scanline_intensity = scanline2_contrib + scanline3_contrib;
if(beam_num_scanlines > 5.5)
{
const float3 scanline0_contrib =
scanline_contrib(dist2 + float3(2.0), scanline0_color,
scanline_contrib(dist2 + float3(2.0,2.0,2.0), scanline0_color,
ph, sigma_range, shape_range);
const float3 scanline1_contrib =
scanline_contrib(dist2 + float3(1.0), scanline1_color,
scanline_contrib(dist2 + float3(1.0,1.0,1.0), scanline1_color,
ph, sigma_range, shape_range);
const float3 scanline4_contrib =
scanline_contrib(abs(float3(2.0) - dist2), scanline4_color,
scanline_contrib(abs(float3(2.0,2.0,2.0) - dist2), scanline4_color,
ph, sigma_range, shape_range);
const float3 scanline5_contrib =
scanline_contrib(abs(float3(3.0) - dist2), scanline5_color,
@ -257,13 +253,13 @@ void main()
else if(beam_num_scanlines > 4.5)
{
const float3 scanline1_contrib =
scanline_contrib(dist2 + float3(1.0), scanline1_color,
scanline_contrib(dist2 + float3(1.0,1.0,1.0), scanline1_color,
ph, sigma_range, shape_range);
const float3 scanline4_contrib =
scanline_contrib(abs(float3(2.0) - dist2), scanline4_color,
scanline_contrib(abs(float3(2.0,2.0,2.0) - dist2), scanline4_color,
ph, sigma_range, shape_range);
const float3 dist0or5 = lerp(
dist2 + float3(2.0), float3(3.0) - dist2, dist_round);
dist2 + float3(2.0,2.0,2.0), float3(3.0,3.0,3.0) - dist2, dist_round);
const float3 scanline0or5_contrib = scanline_contrib(
dist0or5, scanline_outside_color, ph, sigma_range, shape_range);
scanline_intensity += scanline1_contrib + scanline4_contrib +
@ -272,17 +268,17 @@ void main()
else if(beam_num_scanlines > 3.5)
{
const float3 scanline1_contrib =
scanline_contrib(dist2 + float3(1.0), scanline1_color,
scanline_contrib(dist2 + float3(1.0,1.0,1.0), scanline1_color,
ph, sigma_range, shape_range);
const float3 scanline4_contrib =
scanline_contrib(abs(float3(2.0) - dist2), scanline4_color,
scanline_contrib(abs(float3(2.0,2.0,2.0) - dist2), scanline4_color,
ph, sigma_range, shape_range);
scanline_intensity += scanline1_contrib + scanline4_contrib;
}
else if(beam_num_scanlines > 2.5)
{
const float3 dist1or4 = lerp(
dist2 + float3(1.0), float3(2.0) - dist2, dist_round);
dist2 + float3(1.0,1.0,1.0), float3(2.0,2.0,2.0) - dist2, dist_round);
const float3 scanline1or4_contrib = scanline_contrib(
dist1or4, scanline_outside_color, ph, sigma_range, shape_range);
scanline_intensity += scanline1or4_contrib;

View file

@ -13,7 +13,7 @@
#pragma parameter bloom_underestimate_levels "Bloom - Underestimate Levels" 0.8 0.0 5.0 0.01
#define bloom_underestimate_levels global.bloom_underestimate_levels
#pragma parameter bloom_excess "Bloom - Excess" 0.0 0.0 1.0 0.005
#pragma parameter beam_min_sigma "Beam - Min Sigma" 0.15 0.005 1.0 0.005
#pragma parameter beam_min_sigma "Beam - Min Sigma" 0.02 0.005 1.0 0.005
#define beam_min_sigma global.beam_min_sigma
#pragma parameter beam_max_sigma "Beam - Max Sigma" 0.3 0.005 1.0 0.005
#define beam_max_sigma global.beam_max_sigma

View file

@ -153,9 +153,9 @@ float3 scanline_gaussian_integral_contrib(const float3 dist,
return color * 0.5*(integral_high - integral_low)/pixel_height;
}
float3 scanline_generalized_gaussian_integral_contrib(const float3 dist,
const float3 color, const float pixel_height, const float sigma_range,
const float shape_range)
float3 scanline_generalized_gaussian_integral_contrib(float3 dist,
float3 color, float pixel_height, float sigma_range,
float shape_range)
{
// Requires: 1.) Requirements of scanline_gaussian_integral_contrib()
// must be met.
@ -222,9 +222,9 @@ float3 scanline_gaussian_sampled_contrib(const float3 dist, const float3 color,
}
}
float3 scanline_generalized_gaussian_sampled_contrib(const float3 dist,
const float3 color, const float pixel_height, const float sigma_range,
const float shape_range)
float3 scanline_generalized_gaussian_sampled_contrib(float3 dist,
float3 color, float pixel_height, float sigma_range,
float shape_range)
{
// See scanline_generalized_gaussian_integral_contrib() for details!
// generalized sample =

View file

@ -301,7 +301,8 @@ inline float4 decode_gamma_input(const float4 color, const float3 gamma)
}
//TODO/FIXME: I have no idea why replacing the lookup wrappers with this macro fixes the blurs being offset ¯\_(ツ)_/¯
#define tex2D_linearize(C, D) decode_input(vec4(texture(C, D)))
//#define tex2D_linearize(C, D) decode_input(vec4(texture(C, D)))
// EDIT: it's the 'const' in front of the coords that's doing it
/////////////////////////// TEXTURE LOOKUP WRAPPERS //////////////////////////
@ -376,18 +377,18 @@ inline float4 tex1Dproj_linearize(const sampler1D tex, const float2 tex_coords,
inline float4 tex1Dproj_linearize(const sampler1D tex, const float3 tex_coords, const int texel_off)
{ return decode_input(tex1Dproj(tex, tex_coords, texel_off)); }
/////////*
*/
// tex2D:
inline float4 tex2D_linearize(const sampler2D tex, const float2 tex_coords)
inline float4 tex2D_linearize(const sampler2D tex, float2 tex_coords)
{ return decode_input(texture(tex, tex_coords)); }
inline float4 tex2D_linearize(const sampler2D tex, const float3 tex_coords)
inline float4 tex2D_linearize(const sampler2D tex, float3 tex_coords)
{ return decode_input(texture(tex, tex_coords.xy)); }
inline float4 tex2D_linearize(const sampler2D tex, const float2 tex_coords, const int texel_off)
inline float4 tex2D_linearize(const sampler2D tex, float2 tex_coords, int texel_off)
{ return decode_input(textureLod(tex, tex_coords, texel_off)); }
inline float4 tex2D_linearize(const sampler2D tex, const float3 tex_coords, const int texel_off)
inline float4 tex2D_linearize(const sampler2D tex, float3 tex_coords, int texel_off)
{ return decode_input(textureLod(tex, tex_coords.xy, texel_off)); }
//inline float4 tex2D_linearize(const sampler2D tex, const float2 tex_coords, const float2 dx, const float2 dy)
@ -415,12 +416,12 @@ inline float4 tex2D_linearize(const sampler2D tex, const float3 tex_coords, cons
//inline float4 tex2Dfetch_linearize(const sampler2D tex, const int4 tex_coords, const int texel_off)
//{ return decode_input(tex2Dfetch(tex, tex_coords, texel_off)); }
*/
// tex2Dlod:
inline float4 tex2Dlod_linearize(const sampler2D tex, const float4 tex_coords)
inline float4 tex2Dlod_linearize(const sampler2D tex, float4 tex_coords)
{ return decode_input(textureLod(tex, tex_coords.xy, 0.0)); }
inline float4 tex2Dlod_linearize(const sampler2D tex, const float4 tex_coords, const int texel_off)
inline float4 tex2Dlod_linearize(const sampler2D tex, float4 tex_coords, int texel_off)
{ return decode_input(textureLod(tex, tex_coords.xy, texel_off)); }
/*
// tex2Dproj:
@ -533,14 +534,14 @@ inline float4 tex2Dfetch_linearize_gamma(const sampler2D tex, const int4 tex_coo
inline float4 tex2Dfetch_linearize_gamma(const sampler2D tex, const int4 tex_coords, const int texel_off, const float3 gamma)
{ return decode_gamma_input(tex2Dfetch(tex, tex_coords, texel_off), gamma); }
/////////*
*/
// tex2Dlod:
inline float4 tex2Dlod_linearize_gamma(const sampler2D tex, const float4 tex_coords, const float3 gamma)
inline float4 tex2Dlod_linearize_gamma(const sampler2D tex, float4 tex_coords, float3 gamma)
{ return decode_gamma_input(textureLod(tex, tex_coords.xy, 0.0), gamma); }
inline float4 tex2Dlod_linearize_gamma(const sampler2D tex, const float4 tex_coords, const int texel_off, const float3 gamma)
inline float4 tex2Dlod_linearize_gamma(const sampler2D tex, float4 tex_coords, int texel_off, float3 gamma)
{ return decode_gamma_input(textureLod(tex, tex_coords.xy, texel_off), gamma); }
*/
#endif // GAMMA_MANAGEMENT_H

View file

@ -1,17 +1,17 @@
# IMPORTANT:
# Shader passes need to know details about the image in the mask_texture LUT
# files, so set the following constants in user-preset-constants.h accordingly:
# files, so set the following constants in user-cgp-constants.h accordingly:
# 1.) mask_triads_per_tile = (number of horizontal triads in mask texture LUT's)
# 2.) mask_texture_small_size = (texture size of mask*texture_small LUT's)
# 3.) mask_texture_large_size = (texture size of mask*texture_large LUT's)
# 4.) mask_grille_avg_color = (avg. brightness of mask_grille_texture* LUT's, in [0, 1])
# 5.) mask_slot_avg_color = (avg. brightness of mask_slot_texture* LUT's, in [0, 1])
# 6.) mask_shadow_avg_color = (avg. brightness of mask_shadow_texture* LUT's, in [0, 1])
# Shader passes also need to know certain scales set in this preset, but their
# compilation model doesn't currently allow the preset file to tell them. Make
# sure to set the following constants in user-preset-constants.h accordingly too:
# Shader passes also need to know certain scales set in this .slangp, but their
# compilation model doesn't currently allow the .slangp file to tell them. Make
# sure to set the following constants in user-cgp-constants.h accordingly too:
# 1.) bloom_approx_scale_x = scale_x2
# 2.) mask_resize_viewport_scale = vec2(scale_x6, scale_y5)
# 2.) mask_resize_viewport_scale = float2(scale_x6, scale_y5)
# Finally, shader passes need to know the value of geom_max_aspect_ratio used to
# calculate scale_y5 (among other values):
# 1.) geom_max_aspect_ratio = (geom_max_aspect_ratio used to calculate scale_y5)
@ -145,7 +145,7 @@ srgb_framebuffer4 = "true"
# Given our default geom_max_aspect_ratio and min_allowed_viewport_triads:
# scale_y5 = 4.0/3.0 * 2.0/(341.33333 / 8.0) = 0.0625
# IMPORTANT: The scales MUST be calculated in this way. If you wish to change
# geom_max_aspect_ratio, update that constant in user-preset-constants.h!
# geom_max_aspect_ratio, update that constant in user-cgp-constants.h!
shader5 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-vertical.slang"
filter_linear5 = "true"
scale_type_x5 = "absolute"
@ -205,9 +205,9 @@ mipmap_input11 = "true"
texture_wrap_mode11 = "clamp_to_edge"
parameters = "crt_gamma;lcd_gamma;levels_contrast;halation_weight;diffusion_weight;bloom_underestimate_levels;bloom_excess;beam_min_sigma;beam_max_sigma;beam_spot_power;beam_min_shape;beam_max_shape;beam_shape_power;beam_horiz_filter;beam_horiz_sigma;beam_horiz_linear_rgb_weight;convergence_offset_x_r;convergence_offset_x_g;convergence_offset_x_b;convergence_offset_y_r;convergence_offset_y_g;convergence_offset_y_b;mask_type;mask_sample_mode_desired;mask_specify_num_triads;mask_triad_size_desired;mask_num_triads_desired;aa_subpixel_r_offset_x_runtime;aa_subpixel_r_offset_y_runtime;aa_cubic_c;aa_gauss_sigma;geom_mode_runtime;geom_radius;geom_view_dist;geom_tilt_angle_x;geom_tilt_angle_y;geom_aspect_ratio_x;geom_aspect_ratio_y;geom_overscan_x;geom_overscan_y;border_size;border_darkness;border_compress;interlace_bff;interlace_1080i"
interlace_bff = "0.000000"
beam_horiz_filter = "0.000000"
levels_contrast = "0.600000"
crt_gamma = "2.400000"
lcd_gamma = "2.400000"
levels_contrast = "0.740000"
halation_weight = "0.004600"
diffusion_weight = "0.001000"
bloom_underestimate_levels = "0.800000"
@ -218,7 +218,9 @@ beam_spot_power = "0.370000"
beam_min_shape = "2.000000"
beam_max_shape = "4.000000"
beam_shape_power = "0.250000"
beam_horiz_filter = "0.000000"
beam_horiz_sigma = "0.545000"
beam_horiz_linear_rgb_weight = "1.000000"
convergence_offset_x_r = "-0.050000"
convergence_offset_x_g = "0.000000"
convergence_offset_x_b = "0.000000"
@ -226,11 +228,25 @@ convergence_offset_y_r = "0.100000"
convergence_offset_y_g = "-0.050000"
convergence_offset_y_b = "0.100000"
mask_type = "0.000000"
mask_sample_mode_desired = "1.000000"
mask_sample_mode_desired = "0.000000"
mask_specify_num_triads = "0.000000"
mask_triad_size_desired = "1.000000"
mask_num_triads_desired = "900.000000"
aa_subpixel_r_offset_x_runtime = "-0.333333"
aa_subpixel_r_offset_y_runtime = "0.000000"
aa_cubic_c = "0.500000"
aa_gauss_sigma = "0.500000"
geom_mode_runtime = "0.000000"
geom_radius = "3.000000"
geom_view_dist = "2.000000"
geom_tilt_angle_x = "0.000000"
geom_tilt_angle_y = "0.000000"
geom_aspect_ratio_x = "432.000000"
geom_aspect_ratio_y = "329.000000"
geom_overscan_x = "1.000000"
geom_overscan_y = "1.000000"
border_size = "0.005000"
border_darkness = "0.000000"
border_compress = "2.500000"
interlace_bff = "0.000000"
interlace_1080i = "0.000000"
beam_num_scanlines = "4.000000"