mirror of
https://github.com/libretro/slang-shaders.git
synced 2025-02-20 01:57:49 +00:00
Add input translation option to blur fill and average fill
This commit is contained in:
parent
5fdf662cb4
commit
fd0539a477
@ -1,7 +1,7 @@
|
||||
#version 450
|
||||
|
||||
/*
|
||||
Average fill v1.7 by fishku
|
||||
Average fill v1.8 by fishku
|
||||
Copyright (C) 2023
|
||||
Public domain license (CC0)
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
3 = Smooth angle-based blending
|
||||
|
||||
Changelog:
|
||||
v1.8: Add shift option from input transform library.
|
||||
v1.7: Add overscale option from crop and scale library.
|
||||
v1.6: Refactor for new scaling library. Add rotation support.
|
||||
v1.5: Optimize. Update to new Pixel AA version.
|
||||
@ -42,7 +43,7 @@
|
||||
#include "../../../pixel-art-scaling/shaders/pixel_aa/parameters.slang"
|
||||
// clang-format on
|
||||
|
||||
#include "../../../misc/shaders/crop_and_scale/crop_and_scale.slang"
|
||||
#include "../../../misc/shaders/input_transform/input_transform.slang"
|
||||
#include "../../../pixel-art-scaling/shaders/pixel_aa/shared.slang"
|
||||
|
||||
layout(push_constant) uniform Push {
|
||||
@ -55,18 +56,21 @@ layout(push_constant) uniform Push {
|
||||
float CORNER_BLEND_MODE;
|
||||
float FILL_GAMMA;
|
||||
float SAMPLE_SIZE;
|
||||
// From crop and scale, scaling section
|
||||
// From input transform library, scaling section
|
||||
float FORCE_ASPECT_RATIO;
|
||||
float ASPECT_H;
|
||||
float ASPECT_V;
|
||||
float FORCE_INTEGER_SCALING_H;
|
||||
float FORCE_INTEGER_SCALING_V;
|
||||
float OVERSCALE;
|
||||
// From crop and scale, cropping section
|
||||
// From input transform library, cropping section
|
||||
float OS_CROP_TOP;
|
||||
float OS_CROP_BOTTOM;
|
||||
float OS_CROP_LEFT;
|
||||
float OS_CROP_RIGHT;
|
||||
// From input transform library, moving section
|
||||
float SHIFT_H;
|
||||
float SHIFT_V;
|
||||
float CENTER_AFTER_CROPPING;
|
||||
// From pixel AA
|
||||
float PIX_AA_SHARP;
|
||||
@ -84,11 +88,12 @@ layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out vec2 scale_o2i;
|
||||
layout(location = 2) out vec4 crop;
|
||||
layout(location = 3) out vec2 tx_coord;
|
||||
layout(location = 4) out vec2 tx_per_px;
|
||||
layout(location = 5) out vec2 tx_to_uv;
|
||||
layout(location = 6) out vec4 input_corners;
|
||||
layout(location = 7) out vec2 cropped_input_size;
|
||||
layout(location = 3) out vec2 shift;
|
||||
layout(location = 4) out vec2 tx_coord;
|
||||
layout(location = 5) out vec2 tx_per_px;
|
||||
layout(location = 6) out vec2 tx_to_uv;
|
||||
layout(location = 7) out vec4 input_corners;
|
||||
layout(location = 8) out vec2 cropped_input_size;
|
||||
|
||||
void main() {
|
||||
gl_Position = global.MVP * Position;
|
||||
@ -102,7 +107,8 @@ void main() {
|
||||
vec2(param.FORCE_INTEGER_SCALING_H, param.FORCE_INTEGER_SCALING_V),
|
||||
param.OVERSCALE,
|
||||
/* output_size_is_final_viewport_size = */ false);
|
||||
tx_coord = o2i(vTexCoord, param.InputSize.xy, crop, param.Rotation,
|
||||
shift = vec2(param.SHIFT_H, param.SHIFT_V);
|
||||
tx_coord = o2i(vTexCoord, param.InputSize.xy, crop, shift, param.Rotation,
|
||||
param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
tx_per_px = scale_o2i * param.OutputSize.zw;
|
||||
tx_to_uv = param.InputSize.zw;
|
||||
@ -118,11 +124,12 @@ void main() {
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec2 scale_o2i;
|
||||
layout(location = 2) in vec4 crop;
|
||||
layout(location = 3) in vec2 tx_coord;
|
||||
layout(location = 4) in vec2 tx_per_px;
|
||||
layout(location = 5) in vec2 tx_to_uv;
|
||||
layout(location = 6) in vec4 input_corners;
|
||||
layout(location = 7) in vec2 cropped_input_size;
|
||||
layout(location = 3) in vec2 shift;
|
||||
layout(location = 4) in vec2 tx_coord;
|
||||
layout(location = 5) in vec2 tx_per_px;
|
||||
layout(location = 6) in vec2 tx_to_uv;
|
||||
layout(location = 7) in vec4 input_corners;
|
||||
layout(location = 8) in vec2 cropped_input_size;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Input;
|
||||
layout(set = 0, binding = 3) uniform sampler2D Top;
|
||||
@ -185,8 +192,8 @@ void main() {
|
||||
// Top left corner
|
||||
const vec3 top = textureLod(Top, vec2(0.5), BIG_NUMBER).rgb;
|
||||
const vec2 content_corner =
|
||||
i2o(input_corners.xy, param.InputSize.xy, crop, param.Rotation,
|
||||
param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
i2o(input_corners.xy, param.InputSize.xy, crop, shift,
|
||||
param.Rotation, param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
const vec2 viewport_corner = vec2(0.0, 0.0);
|
||||
FragColor = vec4(
|
||||
blend_corner(left, top, cropped_input_size.y,
|
||||
@ -205,8 +212,8 @@ void main() {
|
||||
// Bottom left corner
|
||||
const vec3 bottom = textureLod(Bottom, vec2(0.5), BIG_NUMBER).rgb;
|
||||
const vec2 content_corner =
|
||||
i2o(input_corners.xw, param.InputSize.xy, crop, param.Rotation,
|
||||
param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
i2o(input_corners.xw, param.InputSize.xy, crop, shift,
|
||||
param.Rotation, param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
const vec2 viewport_corner = vec2(0.0, 1.0);
|
||||
FragColor = vec4(
|
||||
blend_corner(left, bottom, cropped_input_size.y,
|
||||
@ -266,8 +273,8 @@ void main() {
|
||||
// Top right corner
|
||||
const vec3 top = textureLod(Top, vec2(0.5), BIG_NUMBER).rgb;
|
||||
const vec2 content_corner =
|
||||
i2o(input_corners.zy, param.InputSize.xy, crop, param.Rotation,
|
||||
param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
i2o(input_corners.zy, param.InputSize.xy, crop, shift,
|
||||
param.Rotation, param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
const vec2 viewport_corner = vec2(1.0, 0.0);
|
||||
FragColor = vec4(
|
||||
blend_corner(right, top, cropped_input_size.y,
|
||||
@ -286,8 +293,8 @@ void main() {
|
||||
// Bottom right corner
|
||||
const vec3 bottom = textureLod(Bottom, vec2(0.5), BIG_NUMBER).rgb;
|
||||
const vec2 content_corner =
|
||||
i2o(input_corners.zw, param.InputSize.xy, crop, param.Rotation,
|
||||
param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
i2o(input_corners.zw, param.InputSize.xy, crop, shift,
|
||||
param.Rotation, param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
const vec2 viewport_corner = vec2(1.0, 1.0);
|
||||
FragColor = vec4(
|
||||
blend_corner(right, bottom, cropped_input_size.y,
|
||||
|
@ -1,6 +1,6 @@
|
||||
// See compose.slang for copyright and other information.
|
||||
|
||||
#include "../../../misc/shaders/crop_and_scale/crop_and_scale.slang"
|
||||
#include "../../../misc/shaders/input_transform/input_transform.slang"
|
||||
#include "parameters.slang"
|
||||
|
||||
layout(push_constant) uniform Push {
|
||||
@ -8,7 +8,7 @@ layout(push_constant) uniform Push {
|
||||
uint Rotation;
|
||||
// Own settings
|
||||
float SAMPLE_SIZE;
|
||||
// From crop and scale, cropping section
|
||||
// From input transform library, cropping section
|
||||
float OS_CROP_TOP;
|
||||
float OS_CROP_BOTTOM;
|
||||
float OS_CROP_LEFT;
|
||||
|
@ -1,9 +1,9 @@
|
||||
// See compose.slang for copyright and other information.
|
||||
|
||||
// clang-format off
|
||||
#pragma parameter AVERAGE_FILL_SETTINGS "=== Average fill v1.7 settings ===" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter AVERAGE_FILL_SETTINGS "=== Average fill v1.8 settings ===" 0.0 0.0 1.0 1.0
|
||||
|
||||
#include "../../../misc/shaders/crop_and_scale/parameters.slang"
|
||||
#include "../../../misc/shaders/input_transform/parameters.slang"
|
||||
|
||||
#pragma parameter OTHER_SETTINGS "= Other parameters =" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter EXTEND_H "Extend the fill horizontally" 1.0 0.0 1.0 1.0
|
||||
|
@ -27,6 +27,7 @@
|
||||
strength of the blur.
|
||||
|
||||
Changelog:
|
||||
v1.9: Add shift option from input transform library.
|
||||
v1.8: Add overscale option from crop and scale library.
|
||||
v1.7: Refactor for new scaling library. Add rotation support.
|
||||
v1.6: Optimize. Update to new Pixel AA version. Tune default blur strength.
|
||||
@ -44,7 +45,7 @@
|
||||
#include "../../../pixel-art-scaling/shaders/pixel_aa/parameters.slang"
|
||||
// clang-format on
|
||||
|
||||
#include "../../../misc/shaders/crop_and_scale/crop_and_scale.slang"
|
||||
#include "../../../misc/shaders/input_transform/input_transform.slang"
|
||||
#include "../../../pixel-art-scaling/shaders/pixel_aa/shared.slang"
|
||||
|
||||
layout(push_constant) uniform Push {
|
||||
@ -55,18 +56,21 @@ layout(push_constant) uniform Push {
|
||||
// Own settings
|
||||
float FILL_GAMMA;
|
||||
float SAMPLE_SIZE;
|
||||
// From crop and scale, scaling section
|
||||
// From input transform library, scaling section
|
||||
float FORCE_ASPECT_RATIO;
|
||||
float ASPECT_H;
|
||||
float ASPECT_V;
|
||||
float FORCE_INTEGER_SCALING_H;
|
||||
float FORCE_INTEGER_SCALING_V;
|
||||
float OVERSCALE;
|
||||
// From crop and scale, cropping section
|
||||
// From input transform library, cropping section
|
||||
float OS_CROP_TOP;
|
||||
float OS_CROP_BOTTOM;
|
||||
float OS_CROP_LEFT;
|
||||
float OS_CROP_RIGHT;
|
||||
// From input transform library, moving section
|
||||
float SHIFT_H;
|
||||
float SHIFT_V;
|
||||
float CENTER_AFTER_CROPPING;
|
||||
// From dual filter blur
|
||||
float BLUR_RADIUS;
|
||||
@ -101,7 +105,8 @@ void main() {
|
||||
vec2(param.FORCE_INTEGER_SCALING_H, param.FORCE_INTEGER_SCALING_V),
|
||||
param.OVERSCALE,
|
||||
/* output_size_is_final_viewport_size = */ false);
|
||||
tx_coord = o2i(vTexCoord, param.InputSize.xy, crop, param.Rotation,
|
||||
vec2 shift = vec2(param.SHIFT_H, param.SHIFT_V);
|
||||
tx_coord = o2i(vTexCoord, param.InputSize.xy, crop, shift, param.Rotation,
|
||||
param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
tx_per_px = scale_o2i * param.OutputSize.zw;
|
||||
tx_to_uv = param.InputSize.zw;
|
||||
|
@ -1,9 +1,9 @@
|
||||
// See compose.slang for copyright and other information.
|
||||
|
||||
// clang-format off
|
||||
#pragma parameter BLUR_FILL_SETTINGS "=== Blur fill v1.8 settings ===" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter BLUR_FILL_SETTINGS "=== Blur fill v1.9 settings ===" 0.0 0.0 1.0 1.0
|
||||
|
||||
#include "../../../misc/shaders/crop_and_scale/parameters.slang"
|
||||
#include "../../../misc/shaders/input_transform/parameters.slang"
|
||||
|
||||
#pragma parameter OTHER_SETTINGS "= Other parameters =" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter EXTEND_H "Extend the fill horizontally" 0.0 0.0 1.0 1.0
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
// See compose.slang for copyright and other information.
|
||||
|
||||
#include "../../../misc/shaders/crop_and_scale/crop_and_scale.slang"
|
||||
#include "../../../misc/shaders/input_transform/input_transform.slang"
|
||||
#include "parameters.slang"
|
||||
|
||||
layout(push_constant) uniform Push {
|
||||
@ -14,18 +14,21 @@ layout(push_constant) uniform Push {
|
||||
float EXTEND_V;
|
||||
float MIRROR_BLUR;
|
||||
float SAMPLE_SIZE;
|
||||
// From crop and scale, scaling section
|
||||
// From input transform library, scaling section
|
||||
float FORCE_ASPECT_RATIO;
|
||||
float ASPECT_H;
|
||||
float ASPECT_V;
|
||||
float FORCE_INTEGER_SCALING_H;
|
||||
float FORCE_INTEGER_SCALING_V;
|
||||
float OVERSCALE;
|
||||
// From crop and scale, cropping section
|
||||
// From input transform library, cropping section
|
||||
float OS_CROP_TOP;
|
||||
float OS_CROP_BOTTOM;
|
||||
float OS_CROP_LEFT;
|
||||
float OS_CROP_RIGHT;
|
||||
// From input transform library, moving section
|
||||
float SHIFT_H;
|
||||
float SHIFT_V;
|
||||
float CENTER_AFTER_CROPPING;
|
||||
}
|
||||
param;
|
||||
@ -51,7 +54,8 @@ void main() {
|
||||
vec2(param.ASPECT_H, param.ASPECT_V),
|
||||
vec2(param.FORCE_INTEGER_SCALING_H, param.FORCE_INTEGER_SCALING_V), param.OVERSCALE,
|
||||
/* output_size_is_final_viewport_size = */ true);
|
||||
tx_coord = o2i(vTexCoord, param.InputSize.xy, crop, param.Rotation,
|
||||
vec2 shift = vec2(param.SHIFT_H, param.SHIFT_V);
|
||||
tx_coord = o2i(vTexCoord, param.InputSize.xy, crop, shift, param.Rotation,
|
||||
param.CENTER_AFTER_CROPPING, scale_o2i);
|
||||
input_corners = get_input_corners(param.InputSize.xy, crop, param.Rotation);
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
/*
|
||||
Cropping and scaling library v1.1 by fishku
|
||||
Input transformation library v1.2 by fishku
|
||||
Copyright (C) 2023
|
||||
Public domain license (CC0)
|
||||
|
||||
Apply cropping, scaling, and transformation operations to input viewport and
|
||||
provide utility functions for coordinate mappings.
|
||||
|
||||
This file acts like a library and should be included in another shader to be
|
||||
used. For example usages, see the border/blur_fill shaders.
|
||||
|
||||
@ -12,18 +15,33 @@
|
||||
Features:
|
||||
- Cropping on each side
|
||||
- Centering of image after crop has been applied
|
||||
- Additional translation in either direction
|
||||
- Forcing of a certain aspect ratio
|
||||
- Forcing of either vert. or horiz. integer scaling, or both
|
||||
- Rotation support (0, 90, 180, 270 degrees).
|
||||
- Rotation support (0, 90, 180, 270 degrees) -- all "vertical" and
|
||||
"horizontal" paramaters are transformed accordingly.
|
||||
- Overscaling
|
||||
|
||||
Refactored from the version that used to be in the blur_fill shader.
|
||||
|
||||
Changelog:
|
||||
v1.2: Rename to "input transform". Add translation option.
|
||||
v1.1: Add overscaling option. Unify parameters.
|
||||
v1.0: Initial conversion from blur_fill release. Add rotation support.
|
||||
*/
|
||||
|
||||
vec2 get_rotated_size(vec2 x, uint rotation) {
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
case 2:
|
||||
default:
|
||||
return x;
|
||||
case 1:
|
||||
case 3:
|
||||
return x.yx;
|
||||
}
|
||||
}
|
||||
|
||||
vec4 get_rotated_crop(vec4 crop, uint rotation) {
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
@ -38,15 +56,17 @@ vec4 get_rotated_crop(vec4 crop, uint rotation) {
|
||||
}
|
||||
}
|
||||
|
||||
vec2 get_rotated_size(vec2 x, uint rotation) {
|
||||
vec2 get_rotated_vector(vec2 x, uint rotation) {
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
case 2:
|
||||
default:
|
||||
return x;
|
||||
case 1:
|
||||
return vec2(-x.y, x.x);
|
||||
case 2:
|
||||
return -x;
|
||||
case 3:
|
||||
return x.yx;
|
||||
return vec2(x.y, -x.x);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,13 +79,15 @@ vec4 get_input_corners(vec2 input_size, vec4 crop, uint rotation) {
|
||||
}
|
||||
|
||||
// Get adjusted center in input pixel coordinate system.
|
||||
vec2 get_input_center(vec2 input_size, vec4 crop, uint rotation,
|
||||
vec2 get_input_center(vec2 input_size, vec4 crop, vec2 shift, uint rotation,
|
||||
float center_after_cropping) {
|
||||
crop = get_rotated_crop(crop, rotation);
|
||||
return center_after_cropping > 0.5
|
||||
? 0.5 * vec2(crop.y + input_size.x - crop.w,
|
||||
crop.x + input_size.y - crop.z)
|
||||
: vec2(0.49999) * input_size;
|
||||
shift = get_rotated_vector(shift, rotation);
|
||||
return (center_after_cropping > 0.5
|
||||
? 0.5 * vec2(crop.y + input_size.x - crop.w,
|
||||
crop.x + input_size.y - crop.z)
|
||||
: vec2(0.49999) * input_size) -
|
||||
shift;
|
||||
}
|
||||
|
||||
// Scaling from unit output to pixel input space.
|
||||
@ -128,18 +150,19 @@ vec2 get_scale_o2i(vec2 input_size, vec2 output_size, vec4 crop, uint rotation,
|
||||
// coord_in_input_space = o2i(coord_in_output_space)
|
||||
// This is used to sample from the input texture in the output pass.
|
||||
// Version where scale is passed in.
|
||||
vec2 o2i(vec2 x, vec2 input_size, vec4 crop, uint rotation,
|
||||
vec2 o2i(vec2 x, vec2 input_size, vec4 crop, vec2 shift, uint rotation,
|
||||
float center_after_cropping, vec2 scale_o2i) {
|
||||
return (x - 0.49999) * scale_o2i +
|
||||
get_input_center(input_size, crop, rotation, center_after_cropping);
|
||||
return (x - 0.49999) * scale_o2i + get_input_center(input_size, crop, shift,
|
||||
rotation,
|
||||
center_after_cropping);
|
||||
}
|
||||
|
||||
// Version that computes scale.
|
||||
vec2 o2i(vec2 x, vec2 input_size, vec2 output_size, vec4 crop, uint rotation,
|
||||
float center_after_cropping, float force_aspect_ratio, vec2 aspect,
|
||||
vec2 force_integer_scaling, float overscale,
|
||||
vec2 o2i(vec2 x, vec2 input_size, vec2 output_size, vec4 crop, vec2 shift,
|
||||
uint rotation, float center_after_cropping, float force_aspect_ratio,
|
||||
vec2 aspect, vec2 force_integer_scaling, float overscale,
|
||||
bool output_size_is_final_viewport_size) {
|
||||
return o2i(x, input_size, crop, rotation, center_after_cropping,
|
||||
return o2i(x, input_size, crop, shift, rotation, center_after_cropping,
|
||||
get_scale_o2i(input_size, output_size, crop, rotation,
|
||||
center_after_cropping, force_aspect_ratio, aspect,
|
||||
force_integer_scaling, overscale,
|
||||
@ -148,24 +171,22 @@ vec2 o2i(vec2 x, vec2 input_size, vec2 output_size, vec4 crop, uint rotation,
|
||||
|
||||
// From pixel input to unit output space.
|
||||
// Version where scale is passed in.
|
||||
vec2 i2o(vec2 x, vec2 input_size, vec4 crop, uint rotation,
|
||||
vec2 i2o(vec2 x, vec2 input_size, vec4 crop, vec2 shift, uint rotation,
|
||||
float center_after_cropping, vec2 scale_o2i) {
|
||||
return (x - get_input_center(input_size, crop, rotation,
|
||||
return (x - get_input_center(input_size, crop, shift, rotation,
|
||||
center_after_cropping)) /
|
||||
scale_o2i +
|
||||
0.49999;
|
||||
}
|
||||
|
||||
// Version that computes scale.
|
||||
vec2 i2o(vec2 x, vec2 input_size, vec2 output_size, vec4 crop, uint rotation,
|
||||
float center_after_cropping, float force_aspect_ratio, vec2 aspect,
|
||||
vec2 force_integer_scaling, float overscale,
|
||||
vec2 i2o(vec2 x, vec2 input_size, vec2 output_size, vec4 crop, vec2 shift,
|
||||
uint rotation, float center_after_cropping, float force_aspect_ratio,
|
||||
vec2 aspect, vec2 force_integer_scaling, float overscale,
|
||||
bool output_size_is_final_viewport_size) {
|
||||
return (x - get_input_center(input_size, crop, rotation,
|
||||
center_after_cropping)) /
|
||||
return i2o(x, input_size, crop, shift, rotation, center_after_cropping,
|
||||
get_scale_o2i(input_size, output_size, crop, rotation,
|
||||
center_after_cropping, force_aspect_ratio, aspect,
|
||||
force_integer_scaling, overscale,
|
||||
output_size_is_final_viewport_size) +
|
||||
0.49999;
|
||||
output_size_is_final_viewport_size));
|
||||
}
|
@ -14,5 +14,8 @@
|
||||
#pragma parameter OS_CROP_LEFT "Overscan crop left" 0.0 0.0 1024.0 1.0
|
||||
#pragma parameter OS_CROP_RIGHT "Overscan crop right" 0.0 0.0 1024.0 1.0
|
||||
|
||||
#pragma parameter MOVING_SETTINGS "= Moving parameters =" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter CENTER_AFTER_CROPPING "Center cropped area" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter SHIFT_H "Horizontal shift" 0.0 -1024.0 1024.0 0.5
|
||||
#pragma parameter SHIFT_V "Vertical shift" 0.0 -1024.0 1024.0 0.5
|
||||
// clang-format on
|
Loading…
x
Reference in New Issue
Block a user