more crt-royale work

This commit is contained in:
hunterk 2016-09-01 11:26:09 -05:00
parent abda62a6aa
commit 75c3eb5d1a
15 changed files with 549 additions and 419 deletions

View file

@ -77,7 +77,7 @@ void main()
// (not output pixels), but we avoid this and consistently blur at the
// destination size. Otherwise, combining statically calculated weights
// with bilinear sample exploitation would result in terrible artifacts.
const vec2 dxdy_scale = params.SourceSize.xy * params.OutputSize.zw;
const vec2 dxdy_scale = vec2(1.0);//params.SourceSize.xy * params.OutputSize.zw;
const vec2 dxdy = dxdy_scale * params.SourceSize.zw;
// This blur is horizontal-only, so zero out the vertical offset:
blur_dxdy = vec2(dxdy.x, 0.0);

View file

@ -77,7 +77,7 @@ void main()
// (not output pixels), but we avoid this and consistently blur at the
// destination size. Otherwise, combining statically calculated weights
// with bilinear sample exploitation would result in terrible artifacts.
const vec2 dxdy_scale = params.SourceSize.xy * params.OutputSize.zw;
const vec2 dxdy_scale = vec2(1.0);//params.SourceSize.xy * params.OutputSize.zw;
const vec2 dxdy = dxdy_scale * params.SourceSize.zw;
// This blur is vertical-only, so zero out the vertical offset:
blur_dxdy = vec2(0.0, dxdy.y);

View file

@ -188,8 +188,8 @@ void main()
// "true" too. The blur will be much more accurate if a true 4x4 Gaussian
// resize is used instead of tex2Dblur3x3_resize (which samples between
// texels even for upsizing).
const vec2 dxdy_min_scale = registers.ORIG_LINEARIZEDSize.xy / registers.OutputSize.xy;
texture_size_inv = vec2(1.0) * registers.ORIG_LINEARIZEDSize.zw;
const vec2 dxdy_min_scale = registers.ORIG_LINEARIZEDSize.xy * registers.OutputSize.zw;
texture_size_inv = registers.ORIG_LINEARIZEDSize.zw;
if(bloom_approx_filter > 1.5) // 4x4 true Gaussian resize
{
// For upsizing, we'll snap to texels and sample the nearest 4.
@ -268,7 +268,7 @@ void main()
const vec2 texture_size = registers.ORIG_LINEARIZEDSize.xy;
vec2 tex_uv_r, tex_uv_g, tex_uv_b;
if(beam_misconvergence)
if(beam_misconvergence = true)
{
const vec2 convergence_offsets_r = get_convergence_offsets_r_vector();
const vec2 convergence_offsets_g = get_convergence_offsets_g_vector();
@ -288,7 +288,7 @@ void main()
if(bloom_approx_filter > 1.5)
{
// Use a 4x4 Gaussian resize. This is slower but technically correct.
if(beam_misconvergence)
if(beam_misconvergence = true)
{
color_r = tex2Dresize_gaussian4x4(ORIG_LINEARIZED, tex_uv_r,
blur_dxdy, texture_size, texture_size_inv,
@ -312,7 +312,7 @@ void main()
// Use a 3x3 resize blur. This is the softest option, because we're
// blurring already blurry bilinear samples. It doesn't play quite as
// nicely with convergence offsets, but it has its charms.
if(beam_misconvergence)
if(beam_misconvergence = true)
{
color_r = tex2Dblur3x3resize(ORIG_LINEARIZED, tex_uv_r,
blur_dxdy, bloom_approx_sigma);
@ -334,7 +334,7 @@ void main()
// too sharp above ~400x300, but the blurs break down above that
// resolution too, unless min_allowed_viewport_triads is high enough to
// keep bloom_approx_scale_x/min_allowed_viewport_triads < ~1.1658025.)
if(beam_misconvergence)
if(beam_misconvergence = true)
{
color_r = tex2D_linearize(ORIG_LINEARIZED, tex_uv_r).rgb;
color_g = tex2D_linearize(ORIG_LINEARIZED, tex_uv_g).rgb;
@ -346,7 +346,7 @@ void main()
}
}
// Pack the colors from the red/green/blue beams into a single vector:
if(beam_misconvergence)
if(beam_misconvergence = true)
{
color = vec3(color_r.r, color_g.g, color_b.b);
}

View file

@ -0,0 +1,245 @@
#version 450
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
} registers;
#include "params.inc"
///////////////////////////// GPL LICENSE NOTICE /////////////////////////////
// crt-royale: A full-featured CRT shader, with cheese.
// Copyright (C) 2014 TroggleMonkey <trogglemonkey@gmx.com>
//
// 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 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
///////////////////////////// SETTINGS MANAGEMENT ////////////////////////////
#define LAST_PASS
#define SIMULATE_CRT_ON_LCD
#include "../user-settings.h"
#include "derived-settings-and-constants.h"
#include "bind-shader-params.h"
#ifndef DONT_DEFINE //RUNTIME_GEOMETRY_TILT
// Create a local-to-global rotation matrix for the CRT's coordinate frame
// and its global-to-local inverse. See the vertex shader for details.
// It's faster to compute these statically if possible.
const vec2 sin_tilt = sin(geom_tilt_angle_static);
const vec2 cos_tilt = cos(geom_tilt_angle_static);
const mat3x3 geom_local_to_global_static = mat3x3(
cos_tilt.x, sin_tilt.y*sin_tilt.x, cos_tilt.y*sin_tilt.x,
0.0, cos_tilt.y, -sin_tilt.y,
-sin_tilt.x, sin_tilt.y*cos_tilt.x, cos_tilt.y*cos_tilt.x);
const mat3x3 geom_global_to_local_static = mat3x3(
cos_tilt.x, 0.0, -sin_tilt.x,
sin_tilt.y*sin_tilt.x, cos_tilt.y, sin_tilt.y*cos_tilt.x,
cos_tilt.y*sin_tilt.x, -sin_tilt.y, cos_tilt.y*cos_tilt.x);
#endif
////////////////////////////////// INCLUDES //////////////////////////////////
#include "../../../../include/gamma-management.h"
#include "tex2Dantialias.h"
#include "geometry-functions.h"
/////////////////////////////////// HELPERS //////////////////////////////////
mat2x2 mul_scale(vec2 scale, mat2x2 matrix)
{
//mat2x2 scale_matrix = mat2x2(scale.x, 0.0, 0.0, scale.y);
//return (matrix * scale_matrix);
return mat2x2(vec4(matrix[0].xy, matrix[1].xy) * scale.xxyy);
}
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 tex_uv;
layout(location = 1) out vec4 video_and_texture_size_inv;
layout(location = 2) out vec2 output_size_inv;
layout(location = 3) out vec3 eye_pos_local;
layout(location = 4) out vec4 geom_aspect_and_overscan;
#ifdef RUNTIME_GEOMETRY_TILT
layout(location = 5) out vec3 global_to_local_row0;
layout(location = 6) out vec3 global_to_local_row1;
layout(location = 7) out vec3 global_to_local_row2;
#endif
void main()
{
gl_Position = params.MVP * Position;
tex_uv = TexCoord;
video_and_texture_size_inv = vec4(registers.SourceSize.zw, registers.SourceSize.zw);
output_size_inv = registers.OutputSize.zw;
// Get aspect/overscan vectors from scalar parameters (likely uniforms):
const float viewport_aspect_ratio = registers.OutputSize.x * registers.OutputSize.w;
const vec2 geom_aspect = get_aspect_vector(viewport_aspect_ratio);
const vec2 geom_overscan = get_geom_overscan_vector();
geom_aspect_and_overscan = vec4(geom_aspect, geom_overscan);
#ifdef DONT_DEFINE //RUNTIME_GEOMETRY_TILT
// Create a local-to-global rotation matrix for the CRT's coordinate
// frame and its global-to-local inverse. Rotate around the x axis
// first (pitch) and then the y axis (yaw) with yucky Euler angles.
// Positive angles go clockwise around the right-vec and up-vec.
// Runtime shader parameters prevent us from computing these globally,
// but we can still combine the pitch/yaw matrices by hand to cut a
// few instructions. Note that cg matrices fill row1 first, then row2,
// etc. (row-major order).
const vec2 geom_tilt_angle = get_geom_tilt_angle_vector();
const vec2 sin_tilt = sin(geom_tilt_angle);
const vec2 cos_tilt = cos(geom_tilt_angle);
// Conceptual breakdown:
// const mat3x3 rot_x_matrix = mat3x3(
// 1.0, 0.0, 0.0,
// 0.0, cos_tilt.y, -sin_tilt.y,
// 0.0, sin_tilt.y, cos_tilt.y);
// const mat3x3 rot_y_matrix = mat3x3(
// cos_tilt.x, 0.0, sin_tilt.x,
// 0.0, 1.0, 0.0,
// -sin_tilt.x, 0.0, cos_tilt.x);
// const mat3x3 local_to_global =
// rot_x_matrix * rot_y_matrix;
// const mat3x3 global_to_local =
// transpose(local_to_global);
mat3x3 local_to_global = mat3x3(
cos_tilt.x, sin_tilt.y*sin_tilt.x, cos_tilt.y*sin_tilt.x,
0.0, cos_tilt.y, -sin_tilt.y,
-sin_tilt.x, sin_tilt.y*cos_tilt.x, cos_tilt.y*cos_tilt.x);
// This is a pure rotation, so transpose = inverse:
mat3x3 global_to_local = transpose(local_to_global);
// Decompose the matrix into 3 vec3's for output:
global_to_local_row0 = vec3(global_to_local[0].xyz);
global_to_local_row1 = vec3(global_to_local[1].xyz);
global_to_local_row2 = vec3(global_to_local[2].xyz);
#else
const mat3x3 global_to_local = geom_global_to_local_static;
const mat3x3 local_to_global = geom_local_to_global_static;
#endif
// Get an optimal eye position based on geom_view_dist, viewport_aspect,
// and CRT radius/rotation:
#ifdef RUNTIME_GEOMETRY_MODE
geom_mode = params.geom_mode_runtime;
#else
const float geom_mode = geom_mode_static;
#endif
const vec3 eye_pos_global = get_ideal_global_eye_pos(local_to_global, geom_aspect, geom_mode);
eye_pos_local = eye_pos_global, global_to_local;
}
#pragma stage fragment
layout(location = 0) in vec2 tex_uv;
layout(location = 1) in vec4 video_and_texture_size_inv;
layout(location = 2) in vec2 output_size_inv;
layout(location = 3) in vec3 eye_pos_local;
layout(location = 4) in vec4 geom_aspect_and_overscan;
#ifdef RUNTIME_GEOMETRY_TILT
layout(location = 5) in vec3 global_to_local_row0;
layout(location = 6) in vec3 global_to_local_row1;
layout(location = 7) in vec3 global_to_local_row2;
#endif
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
// Localize some parameters:
const vec2 geom_aspect = geom_aspect_and_overscan.xy;
const vec2 geom_overscan = geom_aspect_and_overscan.zw;
const vec2 video_size_inv = video_and_texture_size_inv.xy;
const vec2 texture_size_inv = video_and_texture_size_inv.zw;
#ifdef RUNTIME_GEOMETRY_TILT
const mat3x3 global_to_local = mat3x3(global_to_local_row0,
global_to_local_row1, global_to_local_row2);
#else
const mat3x3 global_to_local = geom_global_to_local_static;
#endif
#ifdef RUNTIME_GEOMETRY_MODE
geom_mode = params.geom_mode_runtime;
#else
const float geom_mode = geom_mode_static;
#endif
// Get flat and curved texture coords for the current fragment point sample
// and a pixel_to_tangent_video_uv matrix for transforming pixel offsets:
// video_uv = relative position in video frame, mapped to [0.0, 1.0] range
// tex_uv = relative position in padded texture, mapped to [0.0, 1.0] range
const vec2 flat_video_uv = tex_uv * (registers.SourceSize.xy * video_size_inv);
mat2x2 pixel_to_video_uv;
vec2 video_uv_no_geom_overscan;
if(geom_mode > 0.5)
{
video_uv_no_geom_overscan =
get_curved_video_uv_coords_and_tangent_matrix(flat_video_uv,
eye_pos_local, output_size_inv, geom_aspect,
geom_mode, global_to_local, pixel_to_video_uv);
}
else
{
video_uv_no_geom_overscan = flat_video_uv;
pixel_to_video_uv = mat2x2(
output_size_inv.x, 0.0, 0.0, output_size_inv.y);
}
// Correct for overscan here (not in curvature code):
const vec2 video_uv =
(video_uv_no_geom_overscan - vec2(0.5))/geom_overscan + vec2(0.5);
const vec2 tex_uv = video_uv * (registers.SourceSize.xy * texture_size_inv);
// Get a matrix transforming pixel vectors to tex_uv vectors:
const mat2x2 pixel_to_tex_uv =
mul_scale(registers.SourceSize.xy * texture_size_inv /
geom_aspect_and_overscan.zw, pixel_to_video_uv);
// Sample! Skip antialiasing if aa_level < 0.5 or both of these hold:
// 1.) Geometry/curvature isn't used
// 2.) Overscan == vec2(1.0)
// Skipping AA is sharper, but it's only faster with dynamic branches.
const vec2 abs_aa_r_offset = abs(get_aa_subpixel_r_offset());
bool need_subpixel_aa = true;
if(abs_aa_r_offset.x + abs_aa_r_offset.y < 0.0) need_subpixel_aa = false;
vec3 color;
if(aa_level > 0.5 && (geom_mode > 0.5 || any(notEqual(geom_overscan , vec2(1.0)))))
{
// Sample the input with antialiasing (due to sharp phosphors, etc.):
color = tex2Daa(Source, tex_uv, pixel_to_tex_uv, registers.FrameCount);
}
else if(aa_level > 0.5 && need_subpixel_aa == true)
{
// Sample at each subpixel location:
color = tex2Daa_subpixel_weights_only(
Source, tex_uv, pixel_to_tex_uv);
}
else
{
color = tex2D_linearize(Source, tex_uv).rgb;
}
// Dim borders and output the final result:
const float border_dim_factor = get_border_dim_factor(video_uv, geom_aspect);
const vec3 final_color = color * border_dim_factor;
FragColor = encode_output(vec4(final_color, 1.0));
}

View file

@ -6,30 +6,12 @@ layout(push_constant) uniform Push
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
} registers;
} params;
#include "params.inc"
///////////////////////////// GPL LICENSE NOTICE /////////////////////////////
// crt-royale: A full-featured CRT shader, with cheese.
// Copyright (C) 2014 TroggleMonkey <trogglemonkey@gmx.com>
//
// 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 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
///////////////////////////// SETTINGS MANAGEMENT ////////////////////////////
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#define LAST_PASS
#define SIMULATE_CRT_ON_LCD
@ -37,210 +19,25 @@ layout(push_constant) uniform Push
#include "derived-settings-and-constants.h"
#include "bind-shader-params.h"
#ifndef DONT_DEFINE //RUNTIME_GEOMETRY_TILT
// Create a local-to-global rotation matrix for the CRT's coordinate frame
// and its global-to-local inverse. See the vertex shader for details.
// It's faster to compute these statically if possible.
const vec2 sin_tilt = sin(geom_tilt_angle_static);
const vec2 cos_tilt = cos(geom_tilt_angle_static);
const mat3x3 geom_local_to_global_static = mat3x3(
cos_tilt.x, sin_tilt.y*sin_tilt.x, cos_tilt.y*sin_tilt.x,
0.0, cos_tilt.y, -sin_tilt.y,
-sin_tilt.x, sin_tilt.y*cos_tilt.x, cos_tilt.y*cos_tilt.x);
const mat3x3 geom_global_to_local_static = mat3x3(
cos_tilt.x, 0.0, -sin_tilt.x,
sin_tilt.y*sin_tilt.x, cos_tilt.y, sin_tilt.y*cos_tilt.x,
cos_tilt.y*sin_tilt.x, -sin_tilt.y, cos_tilt.y*cos_tilt.x);
#endif
////////////////////////////////// INCLUDES //////////////////////////////////
//#include "../../../../include/gamma-management.h"
#include "tex2Dantialias.h"
#include "geometry-functions.h"
#include "includes.h"
/////////////////////////////////// HELPERS //////////////////////////////////
mat2x2 mul_scale(vec2 scale, mat2x2 matrix)
{
//mat2x2 scale_matrix = mat2x2(scale.x, 0.0, 0.0, scale.y);
//return (matrix * scale_matrix);
return mat2x2(vec4(matrix[0].xy, matrix[1].xy) * scale.xxyy);
}
#include "../../../../include/gamma-management.h"
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 tex_uv;
layout(location = 1) out vec4 video_and_texture_size_inv;
layout(location = 2) out vec2 output_size_inv;
layout(location = 3) out vec3 eye_pos_local;
layout(location = 4) out vec4 geom_aspect_and_overscan;
#ifdef RUNTIME_GEOMETRY_TILT
layout(location = 5) out vec3 global_to_local_row0;
layout(location = 6) out vec3 global_to_local_row1;
layout(location = 7) out vec3 global_to_local_row2;
#endif
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = params.MVP * Position;
tex_uv = TexCoord;
video_and_texture_size_inv = vec4(registers.SourceSize.zw, registers.SourceSize.zw);
output_size_inv = registers.OutputSize.zw;
// Get aspect/overscan vectors from scalar parameters (likely uniforms):
const float viewport_aspect_ratio = registers.OutputSize.x * registers.OutputSize.w;
const vec2 geom_aspect = get_aspect_vector(viewport_aspect_ratio);
const vec2 geom_overscan = get_geom_overscan_vector();
geom_aspect_and_overscan = vec4(geom_aspect, geom_overscan);
#ifdef DONT_DEFINE //RUNTIME_GEOMETRY_TILT
// Create a local-to-global rotation matrix for the CRT's coordinate
// frame and its global-to-local inverse. Rotate around the x axis
// first (pitch) and then the y axis (yaw) with yucky Euler angles.
// Positive angles go clockwise around the right-vec and up-vec.
// Runtime shader parameters prevent us from computing these globally,
// but we can still combine the pitch/yaw matrices by hand to cut a
// few instructions. Note that cg matrices fill row1 first, then row2,
// etc. (row-major order).
const vec2 geom_tilt_angle = get_geom_tilt_angle_vector();
const vec2 sin_tilt = sin(geom_tilt_angle);
const vec2 cos_tilt = cos(geom_tilt_angle);
// Conceptual breakdown:
// const mat3x3 rot_x_matrix = mat3x3(
// 1.0, 0.0, 0.0,
// 0.0, cos_tilt.y, -sin_tilt.y,
// 0.0, sin_tilt.y, cos_tilt.y);
// const mat3x3 rot_y_matrix = mat3x3(
// cos_tilt.x, 0.0, sin_tilt.x,
// 0.0, 1.0, 0.0,
// -sin_tilt.x, 0.0, cos_tilt.x);
// const mat3x3 local_to_global =
// rot_x_matrix * rot_y_matrix;
// const mat3x3 global_to_local =
// transpose(local_to_global);
mat3x3 local_to_global = mat3x3(
cos_tilt.x, sin_tilt.y*sin_tilt.x, cos_tilt.y*sin_tilt.x,
0.0, cos_tilt.y, -sin_tilt.y,
-sin_tilt.x, sin_tilt.y*cos_tilt.x, cos_tilt.y*cos_tilt.x);
// This is a pure rotation, so transpose = inverse:
mat3x3 global_to_local = transpose(local_to_global);
// Decompose the matrix into 3 vec3's for output:
global_to_local_row0 = vec3(global_to_local[0].xyz);
global_to_local_row1 = vec3(global_to_local[1].xyz);
global_to_local_row2 = vec3(global_to_local[2].xyz);
#else
const mat3x3 global_to_local = geom_global_to_local_static;
const mat3x3 local_to_global = geom_local_to_global_static;
#endif
// Get an optimal eye position based on geom_view_dist, viewport_aspect,
// and CRT radius/rotation:
#ifdef RUNTIME_GEOMETRY_MODE
geom_mode = params.geom_mode_runtime;
#else
const float geom_mode = geom_mode_static;
#endif
const vec3 eye_pos_global = get_ideal_global_eye_pos(local_to_global, geom_aspect, geom_mode);
eye_pos_local = eye_pos_global, global_to_local;
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 tex_uv;
layout(location = 1) in vec4 video_and_texture_size_inv;
layout(location = 2) in vec2 output_size_inv;
layout(location = 3) in vec3 eye_pos_local;
layout(location = 4) in vec4 geom_aspect_and_overscan;
#ifdef RUNTIME_GEOMETRY_TILT
layout(location = 5) in vec3 global_to_local_row0;
layout(location = 6) in vec3 global_to_local_row1;
layout(location = 7) in vec3 global_to_local_row2;
#endif
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
// Localize some parameters:
const vec2 geom_aspect = geom_aspect_and_overscan.xy;
const vec2 geom_overscan = geom_aspect_and_overscan.zw;
const vec2 video_size_inv = video_and_texture_size_inv.xy;
const vec2 texture_size_inv = video_and_texture_size_inv.zw;
#ifdef RUNTIME_GEOMETRY_TILT
const mat3x3 global_to_local = mat3x3(global_to_local_row0,
global_to_local_row1, global_to_local_row2);
#else
const mat3x3 global_to_local = geom_global_to_local_static;
#endif
#ifdef RUNTIME_GEOMETRY_MODE
geom_mode = params.geom_mode_runtime;
#else
const float geom_mode = geom_mode_static;
#endif
// Get flat and curved texture coords for the current fragment point sample
// and a pixel_to_tangent_video_uv matrix for transforming pixel offsets:
// video_uv = relative position in video frame, mapped to [0.0, 1.0] range
// tex_uv = relative position in padded texture, mapped to [0.0, 1.0] range
const vec2 flat_video_uv = tex_uv * (registers.SourceSize.xy * video_size_inv);
mat2x2 pixel_to_video_uv;
vec2 video_uv_no_geom_overscan;
if(geom_mode > 0.5)
{
video_uv_no_geom_overscan =
get_curved_video_uv_coords_and_tangent_matrix(flat_video_uv,
eye_pos_local, output_size_inv, geom_aspect,
geom_mode, global_to_local, pixel_to_video_uv);
}
else
{
video_uv_no_geom_overscan = flat_video_uv;
pixel_to_video_uv = mat2x2(
output_size_inv.x, 0.0, 0.0, output_size_inv.y);
}
// Correct for overscan here (not in curvature code):
const vec2 video_uv =
(video_uv_no_geom_overscan - vec2(0.5))/geom_overscan + vec2(0.5);
const vec2 tex_uv = video_uv * (registers.SourceSize.xy * texture_size_inv);
// Get a matrix transforming pixel vectors to tex_uv vectors:
const mat2x2 pixel_to_tex_uv =
mul_scale(registers.SourceSize.xy * texture_size_inv /
geom_aspect_and_overscan.zw, pixel_to_video_uv);
// Sample! Skip antialiasing if aa_level < 0.5 or both of these hold:
// 1.) Geometry/curvature isn't used
// 2.) Overscan == vec2(1.0)
// Skipping AA is sharper, but it's only faster with dynamic branches.
const vec2 abs_aa_r_offset = abs(get_aa_subpixel_r_offset());
bool need_subpixel_aa = true;
if(abs_aa_r_offset.x + abs_aa_r_offset.y < 0.0) need_subpixel_aa = false;
vec3 color;
if(aa_level > 0.5 && (geom_mode > 0.5 || any(notEqual(geom_overscan , vec2(1.0)))))
{
// Sample the input with antialiasing (due to sharp phosphors, etc.):
color = tex2Daa(Source, tex_uv, pixel_to_tex_uv, registers.FrameCount);
}
else if(aa_level > 0.5 && need_subpixel_aa == true)
{
// Sample at each subpixel location:
color = tex2Daa_subpixel_weights_only(
Source, tex_uv, pixel_to_tex_uv);
}
else
{
color = tex2D_linearize(Source, tex_uv).rgb;
}
// Dim borders and output the final result:
const float border_dim_factor = get_border_dim_factor(video_uv, geom_aspect);
const vec3 final_color = color * border_dim_factor;
FragColor = encode_output(vec4(final_color, 1.0));
FragColor = encode_output(vec4(texture(Source, vTexCoord).rgb, 1.0));
}

View file

@ -109,7 +109,7 @@ void main()
#ifdef PHOSPHOR_MASK_MANUALLY_RESIZE
// Discard unneeded fragments in case our profile allows real branches.
const vec2 tile_uv_wrap = tile_uv_wrap;
if(get_mask_sample_mode() < 0.5 &&
if(params.mask_sample_mode_desired < 0.5 &&
max(tile_uv_wrap.x, tile_uv_wrap.y) <= mask_resize_num_tiles)
{
const float src_dx = src_dxdy.x;

View file

@ -108,7 +108,7 @@ void main()
#ifdef PHOSPHOR_MASK_MANUALLY_RESIZE
// Discard unneeded fragments in case our profile allows real branches.
const vec2 tile_uv_wrap = src_tex_uv_wrap;
if(get_mask_sample_mode() < 0.5 &&
if(params.mask_sample_mode_desired < 0.5 &&
tile_uv_wrap.y <= mask_resize_num_tiles)
{
const float src_dy = 1.0/mask_resize_src_lut_size.y;
@ -162,7 +162,7 @@ void main()
#ifdef PHOSPHOR_MASK_MANUALLY_RESIZE
// Discard unneeded fragments in case our profile allows real branches.
const vec2 tile_uv_wrap = src_tex_uv_wrap;
if(get_mask_sample_mode() < 0.5 &&
if(params.mask_sample_mode_desired < 0.5 &&
tile_uv_wrap.y <= mask_resize_num_tiles)
{
const float src_dy = 1.0/mask_resize_src_lut_size.y;

View file

@ -86,7 +86,7 @@ void main()
// Our various input textures use different coords.
video_uv = TexCoord;
const vec2 scanline_texture_size_inv =
scanline_texture_size_inv =
registers.VERTICAL_SCANLINESSize.zw;
scanline_tex_uv = video_uv;// * registers.VERTICAL_SCANLINESSize.xy *
scanline_texture_size_inv;
@ -98,15 +98,16 @@ void main()
// Get a consistent name for the final mask texture size. Sample mode 0
// uses the manually resized mask, but ignore it if we never resized.
#ifdef PHOSPHOR_MASK_MANUALLY_RESIZE
const float mask_sample_mode = get_mask_sample_mode();
const float mask_sample_mode = params.mask_sample_mode_desired;//get_mask_sample_mode();
vec2 mask_resize_texture_size = registers.MASK_RESIZESize.xy;
if(mask_sample_mode < 0.5) mask_resize_texture_size = mask_texture_large_size;
if(mask_sample_mode > 0.5) mask_resize_texture_size = mask_texture_large_size;
vec2 mask_resize_video_size = registers.MASK_RESIZESize.xy;
if(mask_sample_mode < 0.5) mask_resize_video_size = mask_texture_large_size;
if(mask_sample_mode > 0.5) mask_resize_video_size = mask_texture_large_size;
#else
const vec2 mask_resize_texture_size = mask_texture_large_size;
const vec2 mask_resize_video_size = mask_texture_large_size;
#endif
// mask_tiles_per_screen = vec2(1280.0, 480.0);
// Compute mask tile dimensions, starting points, etc.:
mask_tile_start_uv_and_size = get_mask_sampling_parameters(
@ -155,12 +156,12 @@ void main()
vec3 phosphor_mask_sample;
#ifdef PHOSPHOR_MASK_MANUALLY_RESIZE
bool sample_orig_luts = true;
if (get_mask_sample_mode() > 0.5) sample_orig_luts = false;
if (params.mask_sample_mode_desired > 0.5) sample_orig_luts = false;
#else
const bool sample_orig_luts = true;
#endif
if(sample_orig_luts)
if(sample_orig_luts = true)
{
// If mask_type is static, this branch will be resolved statically.
if(params.mask_type < 0.5)

View file

@ -99,7 +99,7 @@ void main()
texture_size_inv, il_step_multiple, frame_count, dist);
// Consider 2, 3, 4, or 6 scanlines numbered 0-5: The previous and next
// scanlines are numbered 2 and 3. Get scanline colors colors (ignore
// horizontal sampling, since since registers.OutputSize.x = video_size.x).
// horizontal sampling, since registers.OutputSize.x = video_size.x).
// NOTE: Anisotropic filtering creates interlacing artifacts, which is why
// ORIG_LINEARIZED bobbed any interlaced input before this pass.
const vec2 v_step = vec2(0.0, uv_step.y);
@ -160,7 +160,7 @@ void main()
// Vertical convergence offsets are in units of current-field scanlines.
// dist2 means "positive sample distance from scanline 2, in scanlines:"
vec3 dist2 = vec3(dist);
if(beam_misconvergence)
if(beam_misconvergence = true)
{
const vec3 convergence_offsets_vert_rgb =
get_convergence_offsets_y_vector();

View file

@ -1,165 +0,0 @@
#ifndef GAMMA_MANAGEMENT_H
#define GAMMA_MANAGEMENT_H
/////////////////////////////// BASE CONSTANTS ///////////////////////////////
// Set standard gamma constants, but allow users to override them:
#ifndef OVERRIDE_STANDARD_GAMMA
// Standard encoding gammas:
const float ntsc_gamma = 2.2; // Best to use NTSC for PAL too?
const float pal_gamma = 2.8; // Never actually 2.8 in practice
// Typical device decoding gammas (only use for emulating devices):
// CRT/LCD reference gammas are higher than NTSC and Rec.709 video standard
// gammas: The standards purposely undercorrected for an analog CRT's
// assumed 2.5 reference display gamma to maintain contrast in assumed
// [dark] viewing conditions: http://www.poynton.com/PDFs/GammaFAQ.pdf
// These unstated assumptions about display gamma and perceptual rendering
// intent caused a lot of confusion, and more modern CRT's seemed to target
// NTSC 2.2 gamma with circuitry. LCD displays seem to have followed suit
// (they struggle near black with 2.5 gamma anyway), especially PC/laptop
// displays designed to view sRGB in bright environments. (Standards are
// also in flux again with BT.1886, but it's underspecified for displays.)
const float crt_reference_gamma_high = 2.5; // In (2.35, 2.55)
const float crt_reference_gamma_low = 2.35; // In (2.35, 2.55)
const float lcd_reference_gamma = 2.5; // To match CRT
const float crt_office_gamma = 2.2; // Circuitry-adjusted for NTSC
const float lcd_office_gamma = 2.2; // Approximates sRGB
#endif // OVERRIDE_STANDARD_GAMMA
// Assuming alpha == 1.0 might make it easier for users to avoid some bugs,
// but only if they're aware of it.
#ifndef OVERRIDE_ALPHA_ASSUMPTIONS
const bool assume_opaque_alpha = false;
#endif
/////////////////////// DERIVED CONSTANTS AS FUNCTIONS ///////////////////////
// gamma-management.h should be compatible with overriding gamma values with
// runtime user parameters, but we can only define other global constants in
// terms of static constants, not uniform user parameters. To get around this
// limitation, we need to define derived constants using functions.
// Set device gamma constants, but allow users to override them:
#ifdef OVERRIDE_DEVICE_GAMMA
// The user promises to globally define the appropriate constants:
float get_crt_gamma() { return crt_gamma; }
float get_gba_gamma() { return gba_gamma; }
float get_lcd_gamma() { return lcd_gamma; }
#else
float get_crt_gamma() { return crt_reference_gamma_high; }
float get_gba_gamma() { return 3.5; } // Game Boy Advance; in (3.0, 4.0)
float get_lcd_gamma() { return lcd_office_gamma; }
#endif // OVERRIDE_DEVICE_GAMMA
// Set decoding/encoding gammas for the first/lass passes, but allow overrides:
#ifdef OVERRIDE_FINAL_GAMMA
// The user promises to globally define the appropriate constants:
float get_intermediate_gamma() { return intermediate_gamma; }
float get_input_gamma() { return input_gamma; }
float get_output_gamma() { return output_gamma; }
#else
// If we gamma-correct every pass, always use ntsc_gamma between passes to
// ensure middle passes don't need to care if anything is being simulated:
float get_intermediate_gamma() { return ntsc_gamma; }
#ifdef SIMULATE_CRT_ON_LCD
float get_input_gamma() { return get_crt_gamma(); }
float get_output_gamma() { return get_lcd_gamma(); }
#else
#ifdef SIMULATE_GBA_ON_LCD
float get_input_gamma() { return get_gba_gamma(); }
float get_output_gamma() { return get_lcd_gamma(); }
#else
#ifdef SIMULATE_LCD_ON_CRT
float get_input_gamma() { return get_lcd_gamma(); }
float get_output_gamma() { return get_crt_gamma(); }
#else
#ifdef SIMULATE_GBA_ON_CRT
float get_input_gamma() { return get_gba_gamma(); }
float get_output_gamma() { return get_crt_gamma(); }
#else // Don't simulate anything:
float get_input_gamma() { return ntsc_gamma; }
float get_output_gamma() { return ntsc_gamma; }
#endif // SIMULATE_GBA_ON_CRT
#endif // SIMULATE_LCD_ON_CRT
#endif // SIMULATE_GBA_ON_LCD
#endif // SIMULATE_CRT_ON_LCD
#endif // OVERRIDE_FINAL_GAMMA
#ifndef GAMMA_ENCODE_EVERY_FBO
#ifdef FIRST_PASS
const bool linearize_input = true;
float get_pass_input_gamma() { return get_input_gamma(); }
#else
const bool linearize_input = false;
float get_pass_input_gamma() { return 1.0; }
#endif
#ifdef LAST_PASS
const bool gamma_encode_output = true;
float get_pass_output_gamma() { return get_output_gamma(); }
#else
const bool gamma_encode_output = false;
float get_pass_output_gamma() { return 1.0; }
#endif
#else
const bool linearize_input = true;
const bool gamma_encode_output = true;
#ifdef FIRST_PASS
float get_pass_input_gamma() { return get_input_gamma(); }
#else
float get_pass_input_gamma() { return get_intermediate_gamma(); }
#endif
#ifdef LAST_PASS
float get_pass_output_gamma() { return get_output_gamma(); }
#else
float get_pass_output_gamma() { return get_intermediate_gamma(); }
#endif
#endif
vec4 decode_input(const vec4 color)
{
if(linearize_input)
{
if(assume_opaque_alpha)
{
return vec4(pow(color.rgb, vec3(get_pass_input_gamma())), 1.0);
}
else
{
return vec4(pow(color.rgb, vec3(get_pass_input_gamma())), color.a);
}
}
else
{
return color;
}
}
vec4 encode_output(const vec4 color)
{
if(gamma_encode_output)
{
if(assume_opaque_alpha)
{
return vec4(pow(color.rgb, vec3(1.0/get_pass_output_gamma())), 1.0);
}
else
{
return vec4(pow(color.rgb, vec3(1.0/get_pass_output_gamma())), color.a);
}
}
else
{
return color;
}
}
#define tex2D_linearize(C, D) decode_input(vec4(texture(C, D)))
//vec4 tex2D_linearize(const sampler2D tex, const vec2 tex_coords)
//{ return decode_input(vec4(texture(tex, tex_coords))); }
//#define tex2D_linearize(C, D, E) decode_input(vec4(texture(C, D, E)))
//vec4 tex2D_linearize(const sampler2D tex, const vec2 tex_coords, const int texel_off)
//{ return decode_input(vec4(texture(tex, tex_coords, texel_off))); }
#endif // GAMMA_MANAGEMENT_H

View file

@ -240,7 +240,7 @@ vec2 get_resized_mask_tile_size(const vec2 estimated_viewport_size,
params.mask_triad_size_desired,
estimated_viewport_size.x / params.mask_num_triads_desired,
params.mask_specify_num_triads);
if(get_mask_sample_mode() > 0.5)
if(params.mask_sample_mode_desired > 0.5)
{
// We don't need constraints unless we're sampling MASK_RESIZE.
return desired_tile_size_x * tile_aspect;
@ -319,7 +319,7 @@ vec4 get_mask_sampling_parameters(const vec2 mask_resize_texture_size,
// (We can better ensure a correct tile aspect ratio if the parameters are
// guaranteed correct in all passes...but if we lie, we'll get inconsistent
// sizes across passes, resulting in broken texture coordinates.)
const float mask_sample_mode = get_mask_sample_mode();
const float mask_sample_mode = params.mask_sample_mode_desired;//get_mask_sample_mode();
const vec2 mask_resize_tile_size = get_resized_mask_tile_size(
true_viewport_size, mask_resize_video_size, false);
if(mask_sample_mode < 0.5)
@ -586,7 +586,7 @@ vec2 convert_phosphor_tile_uv_wrap_to_tex_uv(const vec2 tile_uv_wrap,
// tex_uv size of the embedded tile in the full texture.
// Returns: Return tex_uv coords (used for texture sampling)
// corresponding to tile_uv_wrap.
if(get_mask_sample_mode() < 0.5)
if(params.mask_sample_mode_desired < 0.5)
{
// Manually repeat the resized mask tile to fill the screen:
// First get fracttional tile_uv coords. Using fract/fmod on coords

View file

@ -214,7 +214,7 @@ vec3 sample_single_scanline_horizontal(const sampler2D texture,
bool is_interlaced(float num_lines)
{
// Detect interlacing based on the number of lines in the source.
if(interlace_detect)
if(interlace_detect = true)
{
// NTSC: 525 lines, 262.5/field; 486 active (2 half-lines), 243/field
// NTSC Emulators: Typically 224 or 240 lines
@ -252,7 +252,7 @@ vec3 sample_rgb_scanline_horizontal(const sampler2D tex,
{
// TODO: Add function requirements.
// Rely on a helper to make convergence easier.
if(beam_misconvergence)
if(beam_misconvergence = true)
{
const vec3 convergence_offsets_rgb =
get_convergence_offsets_x_vector();
@ -539,7 +539,7 @@ vec3 scanline_contrib(vec3 dist, vec3 color,
// Returns: Return a scanline's light output over a given pixel, using
// a generalized or pure Gaussian distribution and sampling or
// integrals as desired by user codepath choices.
if(beam_generalized_gaussian)
if(beam_generalized_gaussian = true)
{
if(beam_antialias_level > 1.5)
{

View file

@ -175,7 +175,7 @@
const float beam_num_scanlines = 3.0; // range [2, 6]
// A generalized Gaussian beam varies shape with color too, now just width.
// It's slower but more flexible (static option only for now).
const bool beam_generalized_gaussian = true;
bool beam_generalized_gaussian = true;
// What kind of scanline antialiasing do you want?
// 0: Sample weights at 1x; 1: Sample weights at 3x; 2: Compute an integral
// Integrals are slow (especially for generalized Gaussians) and rarely any
@ -215,14 +215,14 @@
// Simulate scanline misconvergence? This needs 3x horizontal texture
// samples and 3x texture samples of BLOOM_APPROX and HALATION_BLUR in
// later passes (static option only for now).
const bool beam_misconvergence = true;
bool beam_misconvergence = true;
// Convergence offsets in x/y directions for R/G/B scanline beams in units
// of scanlines. Positive offsets go right/down; ranges [-2, 2]
const vec2 convergence_offsets_r_static = vec2(0.1, 0.2);
const vec2 convergence_offsets_g_static = vec2(0.3, 0.4);
const vec2 convergence_offsets_b_static = vec2(0.5, 0.6);
// Detect interlacing (static option only for now)?
const bool interlace_detect = true;
bool interlace_detect = true;
// Assume 1080-line sources are interlaced?
const bool interlace_1080i_static = false;
// For interlaced sources, assume TFF (top-field first) or BFF order?

View file

@ -29,7 +29,7 @@
// Assuming alpha == 1.0 might make it easier for users to avoid some bugs,
// but only if they're aware of it.
#ifndef OVERRIDE_ALPHA_ASSUMPTIONS
const bool assume_opaque_alpha = false;
bool assume_opaque_alpha = false;
#endif
@ -88,22 +88,22 @@
#ifndef GAMMA_ENCODE_EVERY_FBO
#ifdef FIRST_PASS
const bool linearize_input = true;
bool linearize_input = true;
float get_pass_input_gamma() { return get_input_gamma(); }
#else
const bool linearize_input = false;
bool linearize_input = false;
float get_pass_input_gamma() { return 1.0; }
#endif
#ifdef LAST_PASS
const bool gamma_encode_output = true;
bool gamma_encode_output = true;
float get_pass_output_gamma() { return get_output_gamma(); }
#else
const bool gamma_encode_output = false;
bool gamma_encode_output = false;
float get_pass_output_gamma() { return 1.0; }
#endif
#else
const bool linearize_input = true;
const bool gamma_encode_output = true;
bool linearize_input = true;
bool gamma_encode_output = true;
#ifdef FIRST_PASS
float get_pass_input_gamma() { return get_input_gamma(); }
#else
@ -118,9 +118,9 @@
vec4 decode_input(const vec4 color)
{
if(linearize_input)
if(linearize_input = true)
{
if(assume_opaque_alpha)
if(assume_opaque_alpha = true)
{
return vec4(pow(color.rgb, vec3(get_pass_input_gamma())), 1.0);
}
@ -137,9 +137,9 @@ vec4 decode_input(const vec4 color)
vec4 encode_output(const vec4 color)
{
if(gamma_encode_output)
if(gamma_encode_output = true)
{
if(assume_opaque_alpha)
if(assume_opaque_alpha = true)
{
return vec4(pow(color.rgb, vec3(1.0/get_pass_output_gamma())), 1.0);
}

View file

@ -0,0 +1,252 @@
# 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:
# 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:
# 1.) bloom_approx_scale_x = scale_x2
# 2.) mask_resize_viewport_scale = vec2(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)
shaders = "11"//"12"
# Set an identifier, filename, and sampling traits for the phosphor mask texture.
# Load an aperture grille, slot mask, and an EDP shadow mask, and load a small
# non-mipmapped version and a large mipmapped version.
# TODO: Test masks in other directories.
textures = "mask_grille_texture_small;mask_grille_texture_large;mask_slot_texture_small;mask_slot_texture_large;mask_shadow_texture_small;mask_shadow_texture_large"
mask_grille_texture_small = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5SpacingResizeTo64.png"
mask_grille_texture_large = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5Spacing.png"
mask_slot_texture_small = "../crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacingResizeTo64.png"
mask_slot_texture_large = "../crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacing.png"
mask_shadow_texture_small = "../crt/shaders/crt-royale/TileableLinearShadowMaskEDPResizeTo64.png"
mask_shadow_texture_large = "../crt/shaders/crt-royale/TileableLinearShadowMaskEDP.png"
mask_grille_texture_small_wrap_mode = "repeat"
mask_grille_texture_large_wrap_mode = "repeat"
mask_slot_texture_small_wrap_mode = "repeat"
mask_slot_texture_large_wrap_mode = "repeat"
mask_shadow_texture_small_wrap_mode = "repeat"
mask_shadow_texture_large_wrap_mode = "repeat"
mask_grille_texture_small_linear = "true"
mask_grille_texture_large_linear = "true"
mask_slot_texture_small_linear = "true"
mask_slot_texture_large_linear = "true"
mask_shadow_texture_small_linear = "true"
mask_shadow_texture_large_linear = "true"
mask_grille_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod
mask_grille_texture_large_mipmap = "true" # Essential for hardware-resized masks
mask_slot_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod
mask_slot_texture_large_mipmap = "true" # Essential for hardware-resized masks
mask_shadow_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod
mask_shadow_texture_large_mipmap = "true" # Essential for hardware-resized masks
# Pass0: Linearize the input based on CRT gamma and bob interlaced fields.
# (Bobbing ensures we can immediately blur without getting artifacts.)
shader0 = "../crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang"
alias0 = "ORIG_LINEARIZED"
filter_linear0 = "false"
scale_type0 = "source"
scale0 = "1.0"
srgb_framebuffer0 = "true"
# Pass1: Resample interlaced (and misconverged) scanlines vertically.
# Separating vertical/horizontal scanline sampling is faster: It lets us
# consider more scanlines while calculating weights for fewer pixels, and
# it reduces our samples from vertical*horizontal to vertical+horizontal.
# This has to come right after ORIG_LINEARIZED, because there's no
# "original_source" scale_type we can use later.
shader1 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-vertical-interlacing.slang"
alias1 = "VERTICAL_SCANLINES"
filter_linear1 = "true"
scale_type_x1 = "source"
scale_x1 = "1.0"
scale_type_y1 = "viewport"
scale_y1 = "1.0"
#float_framebuffer1 = "true"
srgb_framebuffer1 = "true"
# Pass2: Do a small resize blur of ORIG_LINEARIZED at an absolute size, and
# account for convergence offsets. We want to blur a predictable portion of the
# screen to match the phosphor bloom, and absolute scale works best for
# reliable results with a fixed-size bloom. Picking a scale is tricky:
# a.) 400x300 is a good compromise for the "fake-bloom" version: It's low enough
# to blur high-res/interlaced sources but high enough that resampling
# doesn't smear low-res sources too much.
# b.) 320x240 works well for the "real bloom" version: It's 1-1.5% faster, and
# the only noticeable visual difference is a larger halation spread (which
# may be a good thing for people who like to crank it up).
# Note the 4:3 aspect ratio assumes the input has cropped geom_overscan (so it's
# *intended* for an ~4:3 aspect ratio).
shader2 = "../crt/shaders/crt-royale/src/crt-royale-bloom-approx.slang"
alias2 = "BLOOM_APPROX"
filter_linear2 = "true"
scale_type2 = "absolute"
scale_x2 = "320"
scale_y2 = "240"
srgb_framebuffer2 = "true"
# Pass3: Vertically blur the input for halation and refractive diffusion.
# Base this on BLOOM_APPROX: This blur should be small and fast, and blurring
# a constant portion of the screen is probably physically correct if the
# viewport resolution is proportional to the simulated CRT size.
shader3 = "../blurs/blur9fast-vertical.slang"
filter_linear3 = "true"
scale_type3 = "source"
scale3 = "1.0"
srgb_framebuffer3 = "true"
# Pass4: Horizontally blur the input for halation and refractive diffusion.
# Note: Using a one-pass 9x9 blur is about 1% slower.
shader4 = "../blurs/blur9fast-horizontal.slang"
alias4 = "HALATION_BLUR"
filter_linear4 = "true"
scale_type4 = "source"
scale4 = "1.0"
srgb_framebuffer4 = "true"
# Pass5: Lanczos-resize the phosphor mask vertically. Set the absolute
# scale_x5 == mask_texture_small_size.x (see IMPORTANT above). Larger scales
# will blur, and smaller scales could get nasty. The vertical size must be
# based on the viewport size and calculated carefully to avoid artifacts later.
# First calculate the minimum number of mask tiles we need to draw.
# Since curvature is computed after the scanline masking pass:
# num_resized_mask_tiles = 2.0;
# If curvature were computed in the scanline masking pass (it's not):
# max_mask_texel_border = ~3.0 * (1/3.0 + 4.0*sqrt(2.0) + 0.5 + 1.0);
# max_mask_tile_border = max_mask_texel_border/
# (min_resized_phosphor_triad_size * mask_triads_per_tile);
# num_resized_mask_tiles = max(2.0, 1.0 + max_mask_tile_border * 2.0);
# At typical values (triad_size >= 2.0, mask_triads_per_tile == 8):
# num_resized_mask_tiles = ~3.8
# Triad sizes are given in horizontal terms, so we need geom_max_aspect_ratio
# to relate them to vertical resolution. The widest we expect is:
# geom_max_aspect_ratio = 4.0/3.0 # Note: Shader passes need to know this!
# The fewer triads we tile across the screen, the larger each triad will be as a
# fraction of the viewport size, and the larger scale_y5 must be to draw a full
# num_resized_mask_tiles. Therefore, we must decide the smallest number of
# triads we'll guarantee can be displayed on screen. We'll set this according
# to 3-pixel triads at 768p resolution (the lowest anyone's likely to use):
# min_allowed_viewport_triads = 768.0*geom_max_aspect_ratio / 3.0 = 341.333333
# Now calculate the viewport scale that ensures we can draw resized_mask_tiles:
# min_scale_x = resized_mask_tiles * mask_triads_per_tile /
# min_allowed_viewport_triads
# scale_y5 = geom_max_aspect_ratio * min_scale_x
# # Some code might depend on equal scales:
# scale_x6 = scale_y5
# 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!
shader5 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-vertical.slang"
filter_linear5 = "true"
scale_type_x5 = "absolute"
scale_x5 = "64"
scale_type_y5 = "viewport"
scale_y5 = "0.0625" # Safe for >= 341.333 horizontal triads at viewport size
#srgb_framebuffer5 = "false" # mask_texture is already assumed linear
# Pass6: Lanczos-resize the phosphor mask horizontally. scale_x6 = scale_y5.
# TODO: Check again if the shaders actually require equal scales.
shader6 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-horizontal.slang"
alias6 = "MASK_RESIZE"
filter_linear6 = "false"
scale_type_x6 = "viewport"
scale_x6 = "0.0625"
scale_type_y6 = "source"
scale_y6 = "1.0"
#srgb_framebuffer6 = "false" # mask_texture is already assumed linear
# Pass7: Resample (misconverged) scanlines horizontally, apply halation, and
# apply the phosphor mask.
shader7 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang"
alias7 = "MASKED_SCANLINES"
filter_linear7 = "true" # This could just as easily be nearest neighbor.
scale_type7 = "viewport"
scale7 = "1.0"
#float_framebuffer7 = "true"
srgb_framebuffer7 = "true"
# Pass 8: Compute a brightpass. This will require reading the final mask.
shader8 = "../crt/shaders/crt-royale/src/crt-royale-brightpass.slang"
alias8 = "BRIGHTPASS"
filter_linear8 = "true" # This could just as easily be nearest neighbor.
scale_type8 = "viewport"
scale8 = "1.0"
srgb_framebuffer8 = "true"
# Pass 9: Blur the brightpass vertically
shader9 = "../crt/shaders/crt-royale/src/crt-royale-bloom-vertical.slang"
filter_linear9 = "true" # This could just as easily be nearest neighbor.
scale_type9 = "source"
scale9 = "1.0"
srgb_framebuffer9 = "true"
# Pass 10: Blur the brightpass horizontally and combine it with the dimpass:
shader10 = "../crt/shaders/crt-royale/src/crt-royale-bloom-horizontal-reconstitute.slang"
filter_linear10 = "true"
scale_type10 = "source"
scale10 = "1.0"
srgb_framebuffer10 = "true"
# Pass 11: Compute curvature/AA:
shader11 = "../crt/shaders/crt-royale/src/crt-royale-geometry-aa-last-pass.slang"
filter_linear11 = "true"
scale_type11 = "viewport"
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"
crt_gamma = "2.500000"
lcd_gamma = "2.400000"
levels_contrast = "0.840000"
halation_weight = "0.000000"
diffusion_weight = "0.010000"
bloom_underestimate_levels = "0.800000"
bloom_excess = "0.000000"
beam_min_sigma = "0.02000"
beam_max_sigma = "0.200000"
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.000000"
convergence_offset_x_g = "0.000000"
convergence_offset_x_b = "0.000000"
convergence_offset_y_r = "0.100000"
convergence_offset_y_g = "-0.100000"
convergence_offset_y_b = "0.100000"
mask_type = "0.000000"
mask_sample_mode_desired = "1.000000"
mask_specify_num_triads = "1.000000"
mask_triad_size_desired = "3.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 = "3.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"