mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
Add catmull-rom and, b-spline multipass shaders
- Rename old catmull-rom-fast to catmull-rom; - Add new catmull-rom-fast shader; - Delete old b-spline-fast as it behaved exactly like bilinear; - Add new b-spline-fast shaders; - Add anti-ringing code to bicubic fast shaders.
This commit is contained in:
parent
e16a936fb5
commit
a53683a1ad
|
@ -1,4 +1,12 @@
|
|||
shaders = 1
|
||||
shaders = 2
|
||||
|
||||
shader0 = shaders/b-spline-fast.slang
|
||||
filter_linear0 = true
|
||||
shader0 = shaders/b-spline-x.slang
|
||||
filter_linear0 = false
|
||||
scale_type_x0 = viewport
|
||||
scale_type_y0 = source
|
||||
scale0 = 1.0
|
||||
wrap_mode0 = "clamp_to_edge"
|
||||
|
||||
shader1 = shaders/b-spline-y.slang
|
||||
filter_linear1 = false
|
||||
wrap_mode1 = "clamp_to_edge"
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
shaders = 1
|
||||
shaders = 2
|
||||
|
||||
shader0 = shaders/catmull-rom-fast.slang
|
||||
filter_linear0 = true
|
||||
shader0 = shaders/catmull-rom-x.slang
|
||||
filter_linear0 = false
|
||||
scale_type_x0 = viewport
|
||||
scale_type_y0 = source
|
||||
scale0 = 1.0
|
||||
wrap_mode0 = "clamp_to_edge"
|
||||
|
||||
shader1 = shaders/catmull-rom-y.slang
|
||||
filter_linear1 = false
|
||||
wrap_mode1 = "clamp_to_edge"
|
||||
|
|
4
cubic/catmull-rom.slangp
Normal file
4
cubic/catmull-rom.slangp
Normal file
|
@ -0,0 +1,4 @@
|
|||
shaders = 1
|
||||
|
||||
shader0 = shaders/catmull-rom.slang
|
||||
filter_linear0 = true
|
|
@ -1,87 +0,0 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
Bicubic B-Spline 4-taps (Fast) - ported by Hyllian - 2020
|
||||
|
||||
The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
|
||||
|
||||
Samples a texture with B-Spline filtering, using only 4 texture fetches instead of 16.
|
||||
See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
|
||||
|
||||
ATENTION: This code only work using LINEAR filter sampling set on Retroarch!
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
|
||||
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
|
||||
// location [1, 1] in the grid, where [0, 0] is the top left corner.
|
||||
vec2 samplePos = vTexCoord * params.SourceSize.xy;
|
||||
vec2 tc = floor(samplePos - 0.5) + 0.5;
|
||||
|
||||
// Compute the fractional offset from our starting texel to our original sample location, which we'll
|
||||
// feed into the B-Spline function to get our filter weights.
|
||||
vec2 f = samplePos - tc;
|
||||
vec2 f2 = f * f;
|
||||
vec2 f3 = f2 * f;
|
||||
|
||||
// Compute the B-Spline weights using the fractional offset that we calculated earlier.
|
||||
// These equations are pre-expanded based on our knowledge of where the texels will be located,
|
||||
// which lets us avoid having to evaluate a piece-wise function.
|
||||
vec2 w0 = f2 - 0.5 * (f3 + f);
|
||||
vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0;
|
||||
vec2 w2 = -1.5 * f3 + 2. * f2 + 0.5 * f;
|
||||
// vec2 w3 = 0.5 * (f3 - f2);
|
||||
vec2 w3 = 1.0 - w0 - w1 - w2; // The sum of weights must be one.
|
||||
|
||||
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
|
||||
// simultaneously evaluate the 2 samples each from the 4x4 grid.
|
||||
vec2 s0 = w0 + w1;
|
||||
vec2 s1 = w2 + w3;
|
||||
vec2 f0 = w1 / s0;
|
||||
vec2 f1 = w3 / s1;
|
||||
|
||||
// Compute the final UV coordinates we'll use for sampling the texture
|
||||
vec2 t0 = tc - 1. + f0;
|
||||
vec2 t1 = tc + 1. + f1;
|
||||
|
||||
t0 *= params.SourceSize.zw;
|
||||
t1 *= params.SourceSize.zw;
|
||||
|
||||
vec4 c0 = texture(Source, vec2(t0.x, t0.y));
|
||||
vec4 c1 = texture(Source, vec2(t1.x, t0.y));
|
||||
vec4 c2 = texture(Source, vec2(t0.x, t1.y));
|
||||
vec4 c3 = texture(Source, vec2(t1.x, t1.y));
|
||||
|
||||
FragColor = (c0 * s0.x + c1 * s1.x) * s0.y + (c2 * s0.x + c3 * s1.x) * s1.y;
|
||||
}
|
92
cubic/shaders/b-spline-x.slang
Normal file
92
cubic/shaders/b-spline-x.slang
Normal file
|
@ -0,0 +1,92 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
b-spline-x Shader
|
||||
|
||||
Copyright (C) 2011-2022 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
// B-Spline bicubic parameters
|
||||
const float B = 1.0;
|
||||
const float C = 0.0;
|
||||
|
||||
const mat4 INV = mat4( (-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||
(B + 6.0*C)/6.0, -C, 0.0, 0.0);
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out vec4 t1;
|
||||
layout(location = 2) out vec4 t2;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
|
||||
vec2 ps = vec2(params.SourceSize.z, params.SourceSize.w);
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
|
||||
vTexCoord = TexCoord * 1.0001 - vec2(0.5, 0.0)*ps;
|
||||
|
||||
t1 = vTexCoord.xyxy + vec4( -dx, 0.0, 0.0, 0.0);
|
||||
t2 = vTexCoord.xyxy + vec4( dx, 0.0, 2.0*dx, 0.0);
|
||||
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec4 t1;
|
||||
layout(location = 2) in vec4 t2;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
|
||||
|
||||
vec3 C0 = texture(Source, t1.xy).xyz;
|
||||
vec3 C1 = texture(Source, t1.zw).xyz;
|
||||
vec3 C2 = texture(Source, t2.xy).xyz;
|
||||
vec3 C3 = texture(Source, t2.zw).xyz;
|
||||
|
||||
vec4 Px = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Px;
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
92
cubic/shaders/b-spline-y.slang
Normal file
92
cubic/shaders/b-spline-y.slang
Normal file
|
@ -0,0 +1,92 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
b-spline-y Shader
|
||||
|
||||
Copyright (C) 2011-2022 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
// B-Spline bicubic parameters
|
||||
const float B = 1.0;
|
||||
const float C = 0.0;
|
||||
|
||||
const mat4 INV = mat4( (-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||
(B + 6.0*C)/6.0, -C, 0.0, 0.0);
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out vec4 t1;
|
||||
layout(location = 2) out vec4 t2;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
|
||||
vec2 ps = vec2(params.SourceSize.z, params.SourceSize.w);
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
|
||||
vTexCoord = TexCoord * 1.0001 - vec2(0.0, 0.5)*ps;
|
||||
|
||||
t1 = vTexCoord.xyxy + vec4( 0.0, -dy, 0.0, 0.0);
|
||||
t2 = vTexCoord.xyxy + vec4( 0.0, dy, 0.0, 2.0*dy);
|
||||
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec4 t1;
|
||||
layout(location = 2) in vec4 t2;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
|
||||
|
||||
vec3 C0 = texture(Source, t1.xy).xyz;
|
||||
vec3 C1 = texture(Source, t1.zw).xyz;
|
||||
vec3 C2 = texture(Source, t2.xy).xyz;
|
||||
vec3 C3 = texture(Source, t2.zw).xyz;
|
||||
|
||||
vec4 Py = vec4(fp.y*fp.y*fp.y, fp.y*fp.y, fp.y, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Py;
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
|
@ -31,13 +31,19 @@ layout(push_constant) uniform Push
|
|||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float B_ANTI_RINGING;
|
||||
} params;
|
||||
|
||||
#pragma parameter B_ANTI_RINGING "Bicubic Anti-Ringing [ OFF | ON ]" 1.0 0.0 1.0 1.0
|
||||
|
||||
#define B_ANTI_RINGING params.B_ANTI_RINGING
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
// Classic Mitchell-Netravali bicubic parameters
|
||||
const float B = 1.0/3.0;
|
||||
const float C = 1.0/3.0;
|
||||
|
||||
|
@ -87,5 +93,15 @@ void main()
|
|||
vec4 Px = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Px;
|
||||
|
||||
// Anti-ringing
|
||||
if (B_ANTI_RINGING == 1.0)
|
||||
{
|
||||
vec3 aux = color;
|
||||
vec3 min_sample = min(min(C0, C1), min(C2, C3));
|
||||
vec3 max_sample = max(max(C0, C1), max(C2, C3));
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
color = mix(aux, color, step(0.0, (C0-C1)*(C2-C3)));
|
||||
}
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
|
|
@ -31,13 +31,19 @@ layout(push_constant) uniform Push
|
|||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float B_ANTI_RINGING;
|
||||
} params;
|
||||
|
||||
#pragma parameter B_ANTI_RINGING "Bicubic Anti-Ringing [ OFF | ON ]" 1.0 0.0 1.0 1.0
|
||||
|
||||
#define B_ANTI_RINGING params.B_ANTI_RINGING
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
// Classic Mitchell-Netravali bicubic parameters
|
||||
const float B = 1.0/3.0;
|
||||
const float C = 1.0/3.0;
|
||||
|
||||
|
@ -87,5 +93,15 @@ void main()
|
|||
vec4 Py = vec4(fp.y*fp.y*fp.y, fp.y*fp.y, fp.y, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Py;
|
||||
|
||||
// Anti-ringing
|
||||
if (B_ANTI_RINGING == 1.0)
|
||||
{
|
||||
vec3 aux = color;
|
||||
vec3 min_sample = min(min(C0, C1), min(C2, C3));
|
||||
vec3 max_sample = max(max(C0, C1), max(C2, C3));
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
color = mix(aux, color, step(0.0, (C0-C1)*(C2-C3)));
|
||||
}
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
|
107
cubic/shaders/catmull-rom-x.slang
Normal file
107
cubic/shaders/catmull-rom-x.slang
Normal file
|
@ -0,0 +1,107 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
catmull-rom-x Shader
|
||||
|
||||
Copyright (C) 2011-2022 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float C_ANTI_RINGING;
|
||||
} params;
|
||||
|
||||
#pragma parameter C_ANTI_RINGING "Catmull-Rom Anti-Ringing [ OFF | ON ]" 1.0 0.0 1.0 1.0
|
||||
|
||||
#define C_ANTI_RINGING params.C_ANTI_RINGING
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
// Catmull-Rom parameters
|
||||
const float B = 0.0;
|
||||
const float C = 0.5;
|
||||
|
||||
const mat4 INV = mat4( (-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||
(B + 6.0*C)/6.0, -C, 0.0, 0.0);
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out vec4 t1;
|
||||
layout(location = 2) out vec4 t2;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
|
||||
vec2 ps = vec2(params.SourceSize.z, params.SourceSize.w);
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
|
||||
vTexCoord = TexCoord * 1.0001 - vec2(0.5, 0.0)*ps;
|
||||
|
||||
t1 = vTexCoord.xyxy + vec4( -dx, 0.0, 0.0, 0.0);
|
||||
t2 = vTexCoord.xyxy + vec4( dx, 0.0, 2.0*dx, 0.0);
|
||||
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec4 t1;
|
||||
layout(location = 2) in vec4 t2;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
|
||||
|
||||
vec3 C0 = texture(Source, t1.xy).xyz;
|
||||
vec3 C1 = texture(Source, t1.zw).xyz;
|
||||
vec3 C2 = texture(Source, t2.xy).xyz;
|
||||
vec3 C3 = texture(Source, t2.zw).xyz;
|
||||
|
||||
vec4 Px = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Px;
|
||||
|
||||
// Anti-ringing
|
||||
if (C_ANTI_RINGING == 1.0)
|
||||
{
|
||||
vec3 aux = color;
|
||||
vec3 min_sample = min(min(C0, C1), min(C2, C3));
|
||||
vec3 max_sample = max(max(C0, C1), max(C2, C3));
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
color = mix(aux, color, step(0.0, (C0-C1)*(C2-C3)));
|
||||
}
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
107
cubic/shaders/catmull-rom-y.slang
Normal file
107
cubic/shaders/catmull-rom-y.slang
Normal file
|
@ -0,0 +1,107 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
catmull-rom-y Shader
|
||||
|
||||
Copyright (C) 2011-2022 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float C_ANTI_RINGING;
|
||||
} params;
|
||||
|
||||
#pragma parameter C_ANTI_RINGING "Catmull-Rom Anti-Ringing [ OFF | ON ]" 1.0 0.0 1.0 1.0
|
||||
|
||||
#define C_ANTI_RINGING params.C_ANTI_RINGING
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
// Catmull-Rom parameters
|
||||
const float B = 0.0;
|
||||
const float C = 0.5;
|
||||
|
||||
const mat4 INV = mat4( (-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||
(B + 6.0*C)/6.0, -C, 0.0, 0.0);
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out vec4 t1;
|
||||
layout(location = 2) out vec4 t2;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
|
||||
vec2 ps = vec2(params.SourceSize.z, params.SourceSize.w);
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
|
||||
vTexCoord = TexCoord * 1.0001 - vec2(0.0, 0.5)*ps;
|
||||
|
||||
t1 = vTexCoord.xyxy + vec4( 0.0, -dy, 0.0, 0.0);
|
||||
t2 = vTexCoord.xyxy + vec4( 0.0, dy, 0.0, 2.0*dy);
|
||||
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec4 t1;
|
||||
layout(location = 2) in vec4 t2;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fp = fract(vTexCoord*params.SourceSize.xy);
|
||||
|
||||
vec3 C0 = texture(Source, t1.xy).xyz;
|
||||
vec3 C1 = texture(Source, t1.zw).xyz;
|
||||
vec3 C2 = texture(Source, t2.xy).xyz;
|
||||
vec3 C3 = texture(Source, t2.zw).xyz;
|
||||
|
||||
vec4 Py = vec4(fp.y*fp.y*fp.y, fp.y*fp.y, fp.y, 1.0) * INV;
|
||||
vec3 color = mat4x3(C0, C1, C2, C3) * Py;
|
||||
|
||||
// Anti-ringing
|
||||
if (C_ANTI_RINGING == 1.0)
|
||||
{
|
||||
vec3 aux = color;
|
||||
vec3 min_sample = min(min(C0, C1), min(C2, C3));
|
||||
vec3 max_sample = max(max(C0, C1), max(C2, C3));
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
color = mix(aux, color, step(0.0, (C0-C1)*(C2-C3)));
|
||||
}
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
0
cubic/shaders/catmull-rom-fast.slang → cubic/shaders/catmull-rom.slang
Executable file → Normal file
0
cubic/shaders/catmull-rom-fast.slang → cubic/shaders/catmull-rom.slang
Executable file → Normal file
Loading…
Reference in a new issue