Pixel AA: Account for vertical subpixel layouts

This commit is contained in:
Isaac 2023-10-14 22:14:44 +02:00
parent 2484762253
commit b230165d12
5 changed files with 15 additions and 12 deletions

View file

@ -75,7 +75,7 @@ layout(push_constant) uniform Push {
// From pixel AA
float PIX_AA_SHARP;
float PIX_AA_SUBPX;
float PIX_AA_SUBPX_BGR;
float PIX_AA_SUBPX_ORIENTATION;
}
param;
@ -247,7 +247,7 @@ void main() {
FragColor = pixel_aa(
Input, tx_per_px, tx_to_uv, tx_coord, param.PIX_AA_SHARP,
/* gamma_correct = */ false, param.PIX_AA_SUBPX > 0.5,
param.PIX_AA_SUBPX_BGR > 0.5, param.Rotation);
uint(param.PIX_AA_SUBPX_ORIENTATION), param.Rotation);
}
} else {
if (extend_fill.y < 0.5) {

View file

@ -77,7 +77,7 @@ layout(push_constant) uniform Push {
// From pixel AA
float PIX_AA_SHARP;
float PIX_AA_SUBPX;
float PIX_AA_SUBPX_BGR;
float PIX_AA_SUBPX_ORIENTATION;
}
param;
@ -159,7 +159,7 @@ void main() {
FragColor = pixel_aa(
Input, tx_per_px, tx_to_uv, tx_coord, param.PIX_AA_SHARP,
/* gamma_correct = */ false, param.PIX_AA_SUBPX > 0.5,
param.PIX_AA_SUBPX_BGR > 0.5, param.Rotation);
uint(param.PIX_AA_SUBPX_ORIENTATION), param.Rotation);
}
}
}

View file

@ -1,9 +1,9 @@
// See pixel_aa.slang for copyright and other information.
// clang-format off
#pragma parameter PIX_AA_SETTINGS "=== Pixel AA v1.3 settings ===" 0.0 0.0 1.0 1.0
#pragma parameter PIX_AA_SETTINGS "=== Pixel AA v1.4 settings ===" 0.0 0.0 1.0 1.0
#pragma parameter PIX_AA_SHARP "Pixel AA sharpening amount" 1.5 0.0 2.0 0.05
#pragma parameter PIX_AA_GAMMA "Enable gamma-correct blending" 1.0 0.0 1.0 1.0
#pragma parameter PIX_AA_SUBPX "Enable subpixel AA" 0.0 0.0 1.0 1.0
#pragma parameter PIX_AA_SUBPX_BGR "Use BGR subpx. instead of RGB" 0.0 0.0 1.0 1.0
#pragma parameter PIX_AA_SUBPX_ORIENTATION "Subpixel layout (0=RGB, 1=RGB vert., 2=BGR, 3=BGR vert.)" 0.0 0.0 3.0 1.0
// clang-format on

View file

@ -1,7 +1,7 @@
#version 450
/*
Pixel AA v1.3 by fishku
Pixel AA v1.4 by fishku
Copyright (C) 2023
Public domain license (CC0)
@ -24,6 +24,8 @@
subpixel anti-aliasing, results are identical to the "pixellate" shader.
Changelog:
v1.4: Enable subpixel sampling for all four pixel layout orientations,
including rotated screens.
v1.3: Account for screen rotation in subpixel sampling.
v1.2: Optimize and simplify algorithm. Enable sharpness < 1.0. Fix subpixel
sampling bug.
@ -41,7 +43,7 @@ layout(push_constant) uniform Push {
float PIX_AA_SHARP;
float PIX_AA_GAMMA;
float PIX_AA_SUBPX;
float PIX_AA_SUBPX_BGR;
float PIX_AA_SUBPX_ORIENTATION;
}
param;
@ -73,5 +75,5 @@ void main() {
FragColor =
pixel_aa(Source, tx_per_px, tx_to_uv, tx_coord, param.PIX_AA_SHARP,
param.PIX_AA_GAMMA > 0.5, param.PIX_AA_SUBPX > 0.5,
param.PIX_AA_SUBPX_BGR > 0.5, param.Rotation);
uint(param.PIX_AA_SUBPX_ORIENTATION), param.Rotation);
}

View file

@ -58,17 +58,18 @@ vec3 sample_aa(sampler2D tex, vec2 tx_per_px, vec2 tx_to_uv, vec2 tx_coord,
// interpolation.
vec4 pixel_aa(sampler2D tex, vec2 tx_per_px, vec2 tx_to_uv, vec2 tx_coord,
float sharpness, bool gamma_correct, bool sample_subpx,
bool subpx_bgr, uint rotation) {
uint subpx_orientation, uint screen_rotation) {
if (sample_subpx) {
// Subpixel sampling: Shift the sampling by 1/3rd of an output pixel for
// each subpixel, assuming that the output size is at monitor
// resolution.
// Compensate for possible rotation of the screen in certain cores.
// Account for different subpixel orientations and also for a possible
// rotation of the screen in certain cores.
const vec2 rotation_correction[] = {vec2(1.0, 0.0), vec2(0.0, 1.0),
vec2(-1.0, 0.0), vec2(0.0, -1.0)};
const vec2 sub_tx_offset =
tx_per_px / 3.0 *
rotation_correction[(rotation + int(subpx_bgr) * 2) % 4];
rotation_correction[(screen_rotation + subpx_orientation) % 4];
vec3 res;
for (int i = -1; i < 2; ++i) {
res[i + 1] = sample_aa(tex, tx_per_px, tx_to_uv,