add warp shaders; closes #109

This commit is contained in:
hunterk 2019-07-08 16:18:47 -05:00
parent 968325ddb3
commit c8c3957ad0
3 changed files with 300 additions and 0 deletions

104
warp/shaders/dilation.slang Normal file
View file

@ -0,0 +1,104 @@
#version 450
/*
Hyllian's dilation Shader
Copyright (C) 2011-2015 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 DILATION_Y_WEIGHT, DILATION_U_WEIGHT, DILATION_V_WEIGHT;
} params;
#pragma parameter DILATION_Y_WEIGHT "Dilation Y Weight" 48.0 0.0 128.0 0.5
#pragma parameter DILATION_U_WEIGHT "Dilation U Weight" 7.0 0.0 128.0 0.5
#pragma parameter DILATION_V_WEIGHT "Dilation V Weight" 6.0 0.0 128.0 0.5
#define mul(c,d) (d*c)
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;
layout(location = 1) out vec4 t2;
layout(location = 2) out vec4 t3;
layout(location = 3) out vec4 t4;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord * 1.0001;
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
// A1 B1 C1
// A0 A B C C4
// D0 D E F F4
// G0 G H I I4
// G5 H5 I5
t2 = vTexCoord.xxxy + vec4( -dx, 0., dx, -dy ); // A B C
t3 = vTexCoord.xxxy + vec4( -dx, 0., dx, 0.); // D E F
t4 = vTexCoord.xxxy + vec4( -dx, 0., dx, dy ); // G H I
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t2;
layout(location = 2) in vec4 t3;
layout(location = 3) in vec4 t4;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
const mat3 yuv = mat3(0.299, 0.587, 0.114, -0.169, -0.331, 0.499, 0.499, -0.418, -0.0813);
void main()
{
mat3 yuv_weighted = mat3(params.DILATION_Y_WEIGHT * yuv[0], params.DILATION_U_WEIGHT * yuv[1], params.DILATION_V_WEIGHT * yuv[2]);
vec3 B = texture(Source, t2.yw).rgb;
vec3 D = texture(Source, t3.xw).rgb;
vec3 E = texture(Source, t3.yw).rgb;
vec3 F = texture(Source, t3.zw).rgb;
vec3 H = texture(Source, t4.yw).rgb;
vec4 b = mul( mat4x3(B, D, H, F), yuv_weighted[0] );
vec4 e = mul( mat4x3(E, E, E, E), yuv_weighted[0] );
float di = max(max(b.x, b.y), max(b.z, max(b.w, e.x)));
vec3 res = (di==b.x) ? B : (di==b.y) ? D : (di==b.z) ? H : (di==b.w) ? F : E;
FragColor = vec4(res, 1.0);
}

101
warp/shaders/erosion.slang Normal file
View file

@ -0,0 +1,101 @@
#version 450
/*
Hyllian's erosion Shader
Copyright (C) 2011-2015 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;
const float y_weight = 48.0;
const float u_weight = 7.0;
const float v_weight = 6.0;
const mat3 yuv = mat3(0.299, 0.587, 0.114, -0.169, -0.331, 0.499, 0.499, -0.418, -0.0813);
const mat3 yuv_weighted = mat3(y_weight*yuv[0], u_weight*yuv[1], v_weight*yuv[2]);
#define mul(c,d) (d*c)
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;
layout(location = 1) out vec4 t2;
layout(location = 2) out vec4 t3;
layout(location = 3) out vec4 t4;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord * 1.0001;
float dx = params.SourceSize.z;
float dy = params.SourceSize.w;
// A1 B1 C1
// A0 A B C C4
// D0 D E F F4
// G0 G H I I4
// G5 H5 I5
t2 = vTexCoord.xxxy + vec4( -dx, 0., dx, -dy ); // A B C
t3 = vTexCoord.xxxy + vec4( -dx, 0., dx, 0.); // D E F
t4 = vTexCoord.xxxy + vec4( -dx, 0., dx, dy ); // G H I
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 t2;
layout(location = 2) in vec4 t3;
layout(location = 3) in vec4 t4;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 B = texture(Source, t2.yw).rgb;
vec3 D = texture(Source, t3.xw).rgb;
vec3 E = texture(Source, t3.yw).rgb;
vec3 F = texture(Source, t3.zw).rgb;
vec3 H = texture(Source, t4.yw).rgb;
vec4 b = mul( mat4x3(B, D, H, F), yuv_weighted[0] );
vec4 e = mul( mat4x3(E, E, E, E), yuv_weighted[0] );
float di = min(min(b.x, b.y), min(b.z, min(b.w, e.x)));
vec3 res = (di==b.x) ? B : (di==b.y) ? D : (di==b.z) ? H : (di==b.w) ? F : E;
FragColor = vec4(res, 1.0);
}

View file

@ -0,0 +1,95 @@
#version 450
/*
Smart Morph v1.1
by Sp00kyFox, 2014
Determines the brightest (or darkest) pixel X in the orthogonal neighborship of pixel E (including itself).
Output is a linear combination of X and E weighted with their luma difference d (range: [0.0, 1.0]):
w = sstp{sat[(d - CUTLO)/(CUTHI - CUTLO)]^PWR} * (STRMAX - STRMIN) + STRMIN
with
sstp(x) := smoothstep(0, 1, x) = -2x^3 + 3x^2
sat(x) := saturate(x) = max(0, min(1, x))
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SM_MODE, SM_PWR, SM_STRMIN, SM_STRMAX, SM_CUTLO, SM_CUTHI, SM_DEBUG;
} params;
#pragma parameter SM_MODE "SmartMorph Dilation / Erosion" 0.0 0.0 1.0 1.0 // Switches between dilation and erosion (line thinning or thickening).
#pragma parameter SM_PWR "SmartMorph Luma Exponent" 0.5 0.0 10.0 0.1 // range: [0.0, +inf) - Raises d by the exponent of PWR. Smaller values for stronger morphing.
#pragma parameter SM_STRMIN "SmartMorph MIN Strength" 0.0 0.0 1.0 0.01 // range: [0.0, STRMAX] - Minimal strength to apply
#pragma parameter SM_STRMAX "SmartMorph MAX Strength" 1.0 0.0 1.0 0.01 // range: [STRMIN, 1.0] - Maximal strength to apply.
#pragma parameter SM_CUTLO "SmartMorph LO Contrast Cutoff" 0.0 0.0 1.0 0.01 // range: [0.0, CUTHI) - Cutoff for low contrasts. For d smaller than CUTLO, STRMIN is applied.
#pragma parameter SM_CUTHI "SmartMorph HI Contrast Cutoff" 1.0 0.0 1.0 0.01 // range: (CUTLO, 1.0] - Cutoff for high contrasts. For d bigger than CUTHI, STRMAX is applied.
#pragma parameter SM_DEBUG "SmartMorph Adjust View" 0.0 0.0 1.0 1.0
// STRMIN = CUTLO = 1.0 behaves equivalent to Hyllian's shaders.
const vec3 y_weights = vec3(0.299, 0.587, 0.114);
#define TEX(dx,dy) texture(Source, vTexCoord+vec2((dx),(dy))*params.SourceSize.zw)
#define mul(c,d) (d*c)
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 * 1.0001;
}
#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()
{
vec3 B = TEX( 0.,-1.).rgb;
vec3 D = TEX(-1., 0.).rgb;
vec3 E = TEX( 0., 0.).rgb;
vec3 F = TEX( 1., 0.).rgb;
vec3 H = TEX( 0., 1.).rgb;
vec4 b = mul( mat4x3(B, D, H, F), y_weights );
float e = dot(E, y_weights);
float di = 0.0;
if(params.SM_MODE > 0.5){
di = min(min(b.x, b.y), min(b.z, min(b.w, e)));
}
else{
di = max(max(b.x, b.y), max(b.z, max(b.w, e)));
}
vec3 res = (di==b.x) ? B : (di==b.y) ? D : (di==b.z) ? H : F;
di = abs(e-di);
float str = (di<=params.SM_CUTLO) ? params.SM_STRMIN : (di>=params.SM_CUTHI) ? params.SM_STRMAX : smoothstep( 0.0, 1.0, pow((di-params.SM_CUTLO)/(params.SM_CUTHI-params.SM_CUTLO), params.SM_PWR) ) * (params.SM_STRMAX-params.SM_STRMIN) + params.SM_STRMIN;
if(params.SM_DEBUG > 0.5){
FragColor.rgb = vec3(str);
return;
}
FragColor.rgb = (di==0.0) ? E : mix(E, res, str);
}