forked from Themaister/slang-shaders
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
shaders = 1 | ||
|
||
shader0 = shaders/ddt.slang | ||
filter_linear0 = false | ||
scale_type_0 = source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#version 450 | ||
|
||
/* | ||
Hyllian's DDT Shader | ||
|
||
Copyright (C) 2011-2016 Hyllian/Jararaca - 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; | ||
|
||
#define saturate(c) clamp(c, 0.0, 1.0) | ||
#define lerp(c) mix(c) | ||
#define mul(a,b) (b*a) | ||
#define fmod(c) mod(c) | ||
#define frac(c) fract(c) | ||
#define tex2D(c,d) texture(c,d) | ||
#define float2 vec2 | ||
#define float3 vec3 | ||
#define float4 vec4 | ||
#define int2 ivec2 | ||
#define int3 ivec3 | ||
#define int4 ivec4 | ||
#define bool2 bvec2 | ||
#define bool3 bvec3 | ||
#define bool4 bvec4 | ||
#define float2x2 mat2x2 | ||
#define float3x3 mat3x3 | ||
#define float4x4 mat4x4 | ||
|
||
#define decal Source | ||
|
||
const float3 Y = float3(.2126, .7152, .0722); | ||
|
||
float luma(float3 color) | ||
{ | ||
return dot(color, Y); | ||
} | ||
|
||
float3 bilinear(float p, float q, float3 A, float3 B, float3 C, float3 D) | ||
{ | ||
return ((1-p)*(1-q)*A + p*(1-q)*B + (1-p)*q*C + p*q*D); | ||
} | ||
|
||
#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 vec2 loc; | ||
|
||
void main() | ||
{ | ||
gl_Position = global.MVP * Position; | ||
vTexCoord = TexCoord; | ||
|
||
float2 ps = float2(params.SourceSize.z, params.SourceSize.w); | ||
float dx = ps.x; | ||
float dy = ps.y; | ||
|
||
t1.xy = float2( dx, 0); // F | ||
t1.zw = float2( 0, dy); // H | ||
loc = vTexCoord*params.SourceSize.xy; | ||
} | ||
|
||
#pragma stage fragment | ||
layout(location = 0) in vec2 vTexCoord; | ||
layout(location = 1) in vec4 t1; | ||
layout(location = 2) in vec2 loc; | ||
layout(location = 0) out vec4 FragColor; | ||
layout(set = 0, binding = 2) uniform sampler2D Source; | ||
|
||
void main() | ||
{ | ||
float2 pos = frac(loc * 1.00001)-float2(0.4999, 0.4999); // pos = pixel position | ||
float2 dir = sign(pos); // dir = pixel direction | ||
|
||
float2 g1 = dir*t1.xy; | ||
float2 g2 = dir*t1.zw; | ||
|
||
float3 A = tex2D(decal, vTexCoord ).xyz; | ||
float3 B = tex2D(decal, vTexCoord +g1 ).xyz; | ||
float3 C = tex2D(decal, vTexCoord +g2).xyz; | ||
float3 D = tex2D(decal, vTexCoord +g1+g2).xyz; | ||
|
||
float a = luma(A); | ||
float b = luma(B); | ||
float c = luma(C); | ||
float d = luma(D); | ||
|
||
float p = abs(pos.x); | ||
float q = abs(pos.y); | ||
|
||
float k = distance(pos,g1); | ||
float l = distance(pos,g2); | ||
|
||
float wd1 = abs(a-d); | ||
float wd2 = abs(b-c); | ||
|
||
if ( wd1 < wd2 ) | ||
{ | ||
if (k < l) | ||
{ | ||
C = A + D - B; | ||
} | ||
else | ||
{ | ||
B = A + D - C; | ||
} | ||
} | ||
else if (wd1 > wd2) | ||
{ | ||
D = B + C - A; | ||
} | ||
|
||
float3 color = bilinear(p, q, A, B, C, D); | ||
FragColor = vec4(color, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
shaders = 1 | ||
|
||
shader0 = shaders/fast-bilateral.slang | ||
filter_linear0 = false | ||
scale_type_0 = source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#version 450 | ||
|
||
/* | ||
Hyllian's Fast Bilateral Shader | ||
|
||
Copyright (C) 2011/2016 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 SIGMA_R; | ||
} params; | ||
|
||
#pragma parameter SIGMA_R "Bilateral Blur" 0.4 0.0 1.0 0.1 | ||
|
||
#define SIGMA_R params.SIGMA_R | ||
|
||
layout(std140, set = 0, binding = 0) uniform UBO | ||
{ | ||
mat4 MVP; | ||
} global; | ||
|
||
#define saturate(c) clamp(c, 0.0, 1.0) | ||
#define lerp(c) mix(c) | ||
#define mul(a,b) (b*a) | ||
#define fmod(c) mod(c) | ||
#define frac(c) fract(c) | ||
#define tex2D(c,d) texture(c,d) | ||
#define float2 vec2 | ||
#define float3 vec3 | ||
#define float4 vec4 | ||
#define int2 ivec2 | ||
#define int3 ivec3 | ||
#define int4 ivec4 | ||
#define bool2 bvec2 | ||
#define bool3 bvec3 | ||
#define bool4 bvec4 | ||
#define float2x2 mat2x2 | ||
#define float3x3 mat3x3 | ||
#define float4x4 mat4x4 | ||
|
||
#define decal Source | ||
|
||
#define GET(M,K) (tex2D(decal,tc+M*dx+K*dy).xyz) | ||
|
||
#define BIL(M,K) {col=GET(M,K);ds=M*M+K*K;weight=exp(-ds/sd2)*exp(-(col-center)*(col-center)/si2);color+=(weight*col);wsum+=weight;} | ||
|
||
#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() | ||
{ | ||
float ds, sd2, si2; | ||
float sigma_d = 3.0; | ||
float sigma_r = SIGMA_R*0.04; | ||
|
||
float3 color = float3(0.0, 0.0, 0.0); | ||
float3 wsum = float3(0.0, 0.0, 0.0); | ||
float3 weight; | ||
|
||
float2 dx = float2(1.0, 0.0) * params.SourceSize.zw; | ||
float2 dy = float2(0.0, 1.0) * params.SourceSize.zw; | ||
|
||
sd2 = 2.0 * sigma_d * sigma_d; | ||
si2 = 2.0 * sigma_r * sigma_r; | ||
|
||
float2 tc = vTexCoord; | ||
|
||
float3 col; | ||
float3 center = GET(0,0); | ||
|
||
BIL(-2,-2) | ||
BIL(-1,-2) | ||
BIL( 0,-2) | ||
BIL( 1,-2) | ||
BIL( 2,-2) | ||
BIL(-2,-1) | ||
BIL(-1,-1) | ||
BIL( 0,-1) | ||
BIL( 1,-1) | ||
BIL( 2,-1) | ||
BIL(-2, 0) | ||
BIL(-1, 0) | ||
BIL( 0, 0) | ||
BIL( 1, 0) | ||
BIL( 2, 0) | ||
BIL(-2, 1) | ||
BIL(-1, 1) | ||
BIL( 0, 1) | ||
BIL( 1, 1) | ||
BIL( 2, 1) | ||
BIL(-2, 2) | ||
BIL(-1, 2) | ||
BIL( 0, 2) | ||
BIL( 1, 2) | ||
BIL( 2, 2) | ||
|
||
// Weight normalization | ||
color /= wsum; | ||
FragColor = vec4(color, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
shaders = "5" | ||
shader0 = ../denoisers/shaders/fast-bilateral.slang | ||
filter_linear0 = false | ||
scale_type_0 = source | ||
shader1 = "shaders/nedi-pass0.slang" | ||
filter_linear1 = false | ||
wrap_mode1 = "clamp_to_border" | ||
float_framebuffer1 = "false" | ||
scale_type_x1 = "source" | ||
scale_x1 = "2.000000" | ||
scale_type_y1 = "source" | ||
scale_y1 = "1.000000" | ||
shader2 = "shaders/nedi-pass1.slang" | ||
filter_linear2 = false | ||
wrap_mode2 = "clamp_to_border" | ||
float_framebuffer2 = "false" | ||
scale_type_x2 = "source" | ||
scale_x2 = "1.000000" | ||
scale_type_y2 = "source" | ||
scale_y2 = "2.000000" | ||
shader3 = "shaders/nedi-pass2.slang" | ||
filter_linear3 = false | ||
wrap_mode3 = "clamp_to_border" | ||
float_framebuffer3 = "false" | ||
scale_type_x3 = "source" | ||
scale_x3 = "1.000000" | ||
scale_type_y3 = "source" | ||
scale_y3 = "1.000000" | ||
shader4 = "shaders/nedi-jinc.slang" | ||
filter_linear4 = false | ||
wrap_mode4 = "clamp_to_border" | ||
float_framebuffer4 = "false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
shaders = "4" | ||
shader0 = "shaders/nedi-pass0.slang" | ||
filter_linear0 = false | ||
wrap_mode0 = "clamp_to_border" | ||
float_framebuffer0 = "false" | ||
scale_type_x0 = "source" | ||
scale_x0 = "2.000000" | ||
scale_type_y0 = "source" | ||
scale_y0 = "1.000000" | ||
shader1 = "shaders/nedi-pass1.slang" | ||
filter_linear1 = false | ||
wrap_mode1 = "clamp_to_border" | ||
float_framebuffer1 = "false" | ||
scale_type_x1 = "source" | ||
scale_x1 = "1.000000" | ||
scale_type_y1 = "source" | ||
scale_y1 = "2.000000" | ||
shader2 = "shaders/nedi-pass2.slang" | ||
filter_linear2 = false | ||
wrap_mode2 = "clamp_to_border" | ||
float_framebuffer2 = "false" | ||
scale_type_x2 = "source" | ||
scale_x2 = "1.000000" | ||
scale_type_y2 = "source" | ||
scale_y2 = "1.000000" | ||
shader3 = "shaders/nedi-jinc.slang" | ||
filter_linear3 = false | ||
wrap_mode3 = "clamp_to_border" | ||
float_framebuffer3 = "false" |
Oops, something went wrong.