mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-25 08:51:32 +11:00
Fix scaling in border fill shaders (#454)
* Debug commit; Seems working, before cleanup * Clean up * Bump versions; Add changes to log
This commit is contained in:
parent
4fbac6b177
commit
dd7db517ee
|
@ -27,6 +27,7 @@
|
||||||
3 = Smooth angle-based blending
|
3 = Smooth angle-based blending
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
v1.2: Fix scaling bugs.
|
||||||
v1.1: Add extension modes from blur fill; Add average gamma adjustment.
|
v1.1: Add extension modes from blur fill; Add average gamma adjustment.
|
||||||
v1.0: Initial release.
|
v1.0: Initial release.
|
||||||
*/
|
*/
|
||||||
|
@ -116,7 +117,7 @@ vec3 blend_corner(vec3 a, // The first color to blend
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const vec2 pixel_coord = o2i(vTexCoord) * param.InputSize.xy;
|
const vec2 pixel_coord = o2i(vTexCoord);
|
||||||
if (pixel_coord.x < param.OS_CROP_LEFT) {
|
if (pixel_coord.x < param.OS_CROP_LEFT) {
|
||||||
if (param.EXTEND_H < 0.5) {
|
if (param.EXTEND_H < 0.5) {
|
||||||
FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
@ -131,8 +132,7 @@ void main() {
|
||||||
// Top left corner
|
// Top left corner
|
||||||
const vec3 top = textureLod(Top, vec2(0.5), BIG_NUMBER).rgb;
|
const vec3 top = textureLod(Top, vec2(0.5), BIG_NUMBER).rgb;
|
||||||
const vec2 content_corner =
|
const vec2 content_corner =
|
||||||
i2o(vec2(param.OS_CROP_LEFT, param.OS_CROP_TOP) *
|
i2o(vec2(param.OS_CROP_LEFT, param.OS_CROP_TOP));
|
||||||
param.InputSize.zw);
|
|
||||||
const vec2 viewport_corner = vec2(0.0, 0.0);
|
const vec2 viewport_corner = vec2(0.0, 0.0);
|
||||||
FragColor =
|
FragColor =
|
||||||
vec4(blend_corner(left, top,
|
vec4(blend_corner(left, top,
|
||||||
|
@ -154,10 +154,8 @@ void main() {
|
||||||
}
|
}
|
||||||
// Bottom left corner
|
// Bottom left corner
|
||||||
const vec3 bottom = textureLod(Bottom, vec2(0.5), BIG_NUMBER).rgb;
|
const vec3 bottom = textureLod(Bottom, vec2(0.5), BIG_NUMBER).rgb;
|
||||||
const vec2 content_corner =
|
const vec2 content_corner = i2o(vec2(
|
||||||
i2o(vec2(param.OS_CROP_LEFT,
|
param.OS_CROP_LEFT, param.InputSize.y - param.OS_CROP_BOTTOM));
|
||||||
param.InputSize.y - param.OS_CROP_BOTTOM) *
|
|
||||||
param.InputSize.zw);
|
|
||||||
const vec2 viewport_corner = vec2(0.0, 1.0);
|
const vec2 viewport_corner = vec2(0.0, 1.0);
|
||||||
FragColor =
|
FragColor =
|
||||||
vec4(blend_corner(left, bottom,
|
vec4(blend_corner(left, bottom,
|
||||||
|
@ -209,10 +207,8 @@ void main() {
|
||||||
}
|
}
|
||||||
// Top right corner
|
// Top right corner
|
||||||
const vec3 top = textureLod(Top, vec2(0.5), BIG_NUMBER).rgb;
|
const vec3 top = textureLod(Top, vec2(0.5), BIG_NUMBER).rgb;
|
||||||
const vec2 content_corner =
|
const vec2 content_corner = i2o(vec2(
|
||||||
i2o(vec2(param.InputSize.x - param.OS_CROP_RIGHT,
|
param.InputSize.x - param.OS_CROP_RIGHT, param.OS_CROP_TOP));
|
||||||
param.OS_CROP_TOP) *
|
|
||||||
param.InputSize.zw);
|
|
||||||
const vec2 viewport_corner = vec2(1.0, 0.0);
|
const vec2 viewport_corner = vec2(1.0, 0.0);
|
||||||
FragColor =
|
FragColor =
|
||||||
vec4(blend_corner(right, top,
|
vec4(blend_corner(right, top,
|
||||||
|
@ -236,8 +232,7 @@ void main() {
|
||||||
const vec3 bottom = textureLod(Bottom, vec2(0.5), BIG_NUMBER).rgb;
|
const vec3 bottom = textureLod(Bottom, vec2(0.5), BIG_NUMBER).rgb;
|
||||||
const vec2 content_corner =
|
const vec2 content_corner =
|
||||||
i2o(vec2(param.InputSize.x - param.OS_CROP_RIGHT,
|
i2o(vec2(param.InputSize.x - param.OS_CROP_RIGHT,
|
||||||
param.InputSize.y - param.OS_CROP_BOTTOM) *
|
param.InputSize.y - param.OS_CROP_BOTTOM));
|
||||||
param.InputSize.zw);
|
|
||||||
const vec2 viewport_corner = vec2(1.0, 1.0);
|
const vec2 viewport_corner = vec2(1.0, 1.0);
|
||||||
FragColor =
|
FragColor =
|
||||||
vec4(blend_corner(right, bottom,
|
vec4(blend_corner(right, bottom,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// See compose.slang for copyright and other information.
|
// See compose.slang for copyright and other information.
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#pragma parameter AVERAGE_FILL_SETTINGS "=== Average fill v1.1 settings ===" 0.0 0.0 1.0 1.0
|
#pragma parameter AVERAGE_FILL_SETTINGS "=== Average fill v1.2 settings ===" 0.0 0.0 1.0 1.0
|
||||||
#pragma parameter OS_CROP_TOP "Overscan crop top" 8.0 0.0 1024.0 1.0
|
#pragma parameter OS_CROP_TOP "Overscan crop top" 8.0 0.0 1024.0 1.0
|
||||||
#pragma parameter OS_CROP_BOTTOM "Overscan crop bottom" 8.0 0.0 1024.0 1.0
|
#pragma parameter OS_CROP_BOTTOM "Overscan crop bottom" 8.0 0.0 1024.0 1.0
|
||||||
#pragma parameter OS_CROP_LEFT "Overscan crop left" 0.0 0.0 1024.0 1.0
|
#pragma parameter OS_CROP_LEFT "Overscan crop left" 0.0 0.0 1024.0 1.0
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
strength of the blur.
|
strength of the blur.
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
v1.2: Fix scaling bugs.
|
||||||
v1.1: Fix bug with glcore driver.
|
v1.1: Fix bug with glcore driver.
|
||||||
v1.0: Initial release.
|
v1.0: Initial release.
|
||||||
*/
|
*/
|
||||||
|
@ -77,7 +78,7 @@ layout(set = 0, binding = 3) uniform sampler2D Tiled;
|
||||||
layout(set = 0, binding = 4) uniform sampler2D Blurred;
|
layout(set = 0, binding = 4) uniform sampler2D Blurred;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const vec2 pixel_coord = o2i(vTexCoord) * param.InputSize.xy;
|
const vec2 pixel_coord = o2i(vTexCoord);
|
||||||
|
|
||||||
const vec4 input_extrema = vec4(param.OS_CROP_LEFT, param.OS_CROP_TOP,
|
const vec4 input_extrema = vec4(param.OS_CROP_LEFT, param.OS_CROP_TOP,
|
||||||
param.InputSize.x - param.OS_CROP_RIGHT,
|
param.InputSize.x - param.OS_CROP_RIGHT,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// See compose.slang for copyright and other information.
|
// See compose.slang for copyright and other information.
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#pragma parameter BLUR_FILL_SETTINGS "=== Blur fill v1.1 settings ===" 0.0 0.0 1.0 1.0
|
#pragma parameter BLUR_FILL_SETTINGS "=== Blur fill v1.2 settings ===" 0.0 0.0 1.0 1.0
|
||||||
#pragma parameter OS_CROP_TOP "Overscan crop top" 0.0 0.0 1024.0 1.0
|
#pragma parameter OS_CROP_TOP "Overscan crop top" 0.0 0.0 1024.0 1.0
|
||||||
#pragma parameter OS_CROP_BOTTOM "Overscan crop bottom" 0.0 0.0 1024.0 1.0
|
#pragma parameter OS_CROP_BOTTOM "Overscan crop bottom" 0.0 0.0 1024.0 1.0
|
||||||
#pragma parameter OS_CROP_LEFT "Overscan crop left" 0.0 0.0 1024.0 1.0
|
#pragma parameter OS_CROP_LEFT "Overscan crop left" 0.0 0.0 1024.0 1.0
|
||||||
|
|
|
@ -216,7 +216,7 @@ vec3 sample_mirrored_frame(sampler2D tex, vec2 coord, vec4 input_extrema) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const vec2 pixel_coord = o2i(vTexCoord) * param.InputSize.xy;
|
const vec2 pixel_coord = o2i(vTexCoord);
|
||||||
FragColor = vec4(
|
FragColor = vec4(
|
||||||
sample_mirrored_frame(Input, pixel_coord,
|
sample_mirrored_frame(Input, pixel_coord,
|
||||||
vec4(param.OS_CROP_LEFT, param.OS_CROP_TOP,
|
vec4(param.OS_CROP_LEFT, param.OS_CROP_TOP,
|
||||||
|
|
|
@ -1,69 +1,73 @@
|
||||||
// See compose.slang for copyright and other information.
|
// See compose.slang for copyright and other information.
|
||||||
|
|
||||||
// Pixels in input coord. space
|
// Scaling from unit output to pixel input space.
|
||||||
vec2 eff_input_res() {
|
|
||||||
if (param.CENTER_CROP > 0.5) {
|
|
||||||
return param.InputSize.xy -
|
|
||||||
vec2(param.OS_CROP_LEFT + param.OS_CROP_RIGHT,
|
|
||||||
param.OS_CROP_TOP + param.OS_CROP_BOTTOM);
|
|
||||||
}
|
|
||||||
return param.InputSize.xy -
|
|
||||||
2.0 * vec2(min(param.OS_CROP_LEFT, param.OS_CROP_RIGHT),
|
|
||||||
min(param.OS_CROP_TOP, param.OS_CROP_BOTTOM));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output to input scaling, in unit coordinate systems.
|
|
||||||
vec2 scale_o2i() {
|
vec2 scale_o2i() {
|
||||||
const vec2 eff_input_res = eff_input_res();
|
// Pixels in input coord. space, after cropping.
|
||||||
const vec2 eff_aspect =
|
const vec2 eff_input_res =
|
||||||
vec2(eff_input_res.x, param.FORCE_ASPECT_RATIO > 0.5
|
param.InputSize.xy -
|
||||||
? eff_input_res.y / param.InputSize.y *
|
(param.CENTER_CROP > 0.5
|
||||||
param.InputSize.x * param.ASPECT_V /
|
? vec2(param.OS_CROP_LEFT + param.OS_CROP_RIGHT,
|
||||||
param.ASPECT_H
|
param.OS_CROP_TOP + param.OS_CROP_BOTTOM)
|
||||||
: eff_input_res.y);
|
: 2 * vec2(min(param.OS_CROP_LEFT, param.OS_CROP_RIGHT),
|
||||||
if (param.FinalViewportSize.x / eff_aspect.x <
|
min(param.OS_CROP_TOP, param.OS_CROP_BOTTOM)));
|
||||||
param.FinalViewportSize.y / eff_aspect.y) {
|
// Integer aspect ratio after cropping.
|
||||||
|
// lambda_1 * input_pixels.x, lambda_2 * input_pixels.y,
|
||||||
|
// possibly corrected for forced aspect ratio
|
||||||
|
const vec2 eff_aspect = param.FORCE_ASPECT_RATIO < 0.5
|
||||||
|
? eff_input_res
|
||||||
|
: vec2(eff_input_res.x * param.ASPECT_H,
|
||||||
|
eff_input_res.y * param.ASPECT_V);
|
||||||
|
float scale_x, scale_y;
|
||||||
|
if (param.FinalViewportSize.x * eff_aspect.y <
|
||||||
|
param.FinalViewportSize.y * eff_aspect.x) {
|
||||||
// Scale will be limited by width. Calc x scale, then derive y scale
|
// Scale will be limited by width. Calc x scale, then derive y scale
|
||||||
// using aspect ratio.
|
// using aspect ratio.
|
||||||
const float scale_x =
|
scale_x = param.FinalViewportSize.x / eff_input_res.x;
|
||||||
param.FORCE_INTEGER_SCALING > 0.5
|
if (param.FORCE_INTEGER_SCALING > 0.5) {
|
||||||
? floor(param.FinalViewportSize.x / eff_input_res.x)
|
scale_x = max(1.0, floor(scale_x));
|
||||||
: param.FinalViewportSize.x / eff_input_res.x;
|
}
|
||||||
const float scale_y = scale_x * eff_input_res.x * eff_aspect.y /
|
if (param.FORCE_ASPECT_RATIO < 0.5) {
|
||||||
(eff_input_res.y * eff_aspect.x);
|
scale_y = scale_x;
|
||||||
return param.FinalViewportSize.xy * param.InputSize.zw /
|
} else {
|
||||||
vec2(scale_x, scale_y);
|
scale_y = scale_x * param.ASPECT_V / param.ASPECT_H;
|
||||||
|
if (param.FORCE_INTEGER_SCALING > 0.5) {
|
||||||
|
scale_y = max(1.0, floor(scale_y));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Scale will be limited by height.
|
// Scale will be limited by height.
|
||||||
const float scale_y =
|
scale_y = param.FinalViewportSize.y / eff_input_res.y;
|
||||||
param.FORCE_INTEGER_SCALING > 0.5
|
if (param.FORCE_INTEGER_SCALING > 0.5) {
|
||||||
? floor(param.FinalViewportSize.y / eff_input_res.y)
|
scale_y = max(1.0, floor(scale_y));
|
||||||
: param.FinalViewportSize.y / eff_input_res.y;
|
}
|
||||||
const float scale_x = scale_y * eff_input_res.y * eff_aspect.x /
|
if (param.FORCE_ASPECT_RATIO < 0.5) {
|
||||||
(eff_input_res.x * eff_aspect.y);
|
scale_x = scale_y;
|
||||||
return param.FinalViewportSize.xy * param.InputSize.zw /
|
} else {
|
||||||
vec2(scale_x, scale_y);
|
scale_x = scale_y * param.ASPECT_H / param.ASPECT_V;
|
||||||
|
if (param.FORCE_INTEGER_SCALING > 0.5) {
|
||||||
|
scale_x = max(1.0, floor(scale_x));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return param.FinalViewportSize.xy / vec2(scale_x, scale_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input to output scaling, in unit coordinate systems.
|
// Get adjusted center in input pixel coordinate system.
|
||||||
vec2 scale_i2o() { return 1.0 / scale_o2i(); }
|
// Round to whole pixels to avoid issues on low-res output resolutions, e.g.,
|
||||||
|
// when using a 10x by 1x horizontal superresolution.
|
||||||
// Get adjusted center in input unit coordinate system.
|
|
||||||
vec2 get_input_center() {
|
vec2 get_input_center() {
|
||||||
return param.CENTER_CROP > 0.5
|
return floor(param.CENTER_CROP > 0.5
|
||||||
? 0.5 * param.InputSize.zw *
|
? 0.5 * vec2(param.OS_CROP_LEFT + param.InputSize.x -
|
||||||
vec2(param.OS_CROP_LEFT + param.InputSize.x -
|
param.OS_CROP_RIGHT,
|
||||||
param.OS_CROP_RIGHT,
|
param.OS_CROP_TOP + param.InputSize.y -
|
||||||
param.OS_CROP_TOP + param.InputSize.y -
|
param.OS_CROP_BOTTOM)
|
||||||
param.OS_CROP_BOTTOM)
|
: vec2(0.49999) * param.InputSize.xy);
|
||||||
: vec2(0.49999);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In unit space (output to input).
|
// From unit output to pixel input space.
|
||||||
// coord_in_input_space = o2i(coord_in_output_space)
|
// coord_in_input_space = o2i(coord_in_output_space)
|
||||||
// This is used to sample from the input texture in the output pass.
|
// This is used to sample from the input texture in the output pass.
|
||||||
vec2 o2i(vec2 x) { return (x - 0.49999) * scale_o2i() + get_input_center(); }
|
vec2 o2i(vec2 x) { return (x - 0.49999) * scale_o2i() + get_input_center(); }
|
||||||
|
|
||||||
// In unit coordinate systems.
|
// From pixel input to unit output space.
|
||||||
vec2 i2o(vec2 x) { return (x - get_input_center()) * scale_i2o() + 0.49999; }
|
vec2 i2o(vec2 x) { return (x - get_input_center()) / scale_o2i() + 0.49999; }
|
||||||
|
|
Loading…
Reference in a new issue