mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 07:41:31 +11:00
add slow-bilateral shader
This commit is contained in:
parent
87ea6c000b
commit
bf8c497809
82
denoisers/shaders/slow-bilateral.slang
Normal file
82
denoisers/shaders/slow-bilateral.slang
Normal file
|
@ -0,0 +1,82 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float SIGMA;
|
||||
float BSIGMA;
|
||||
} params;
|
||||
|
||||
#pragma parameter SIGMA "Sigma" 10.0 1.0 20.0 1.0
|
||||
#pragma parameter BSIGMA "BSigma" 0.1 0.01 0.5 0.01
|
||||
|
||||
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;
|
||||
|
||||
#define MSIZE 15
|
||||
|
||||
float normpdf(in float x, in float sigma)
|
||||
{
|
||||
return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
|
||||
}
|
||||
|
||||
float normpdf3(in vec3 v, in float sigma)
|
||||
{
|
||||
return 0.39894*exp(-0.5*dot(v,v)/(sigma*sigma))/sigma;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 fragcoord = vTexCoord * params.OutputSize.xy;
|
||||
vec3 c = texture(Source, (fragcoord.xy / params.OutputSize.xy)).rgb;
|
||||
|
||||
//declare stuff
|
||||
const int kSize = (MSIZE-1)/2;
|
||||
float kernel[MSIZE];
|
||||
vec3 final_colour = vec3(0.0);
|
||||
|
||||
//create the 1-D kernel
|
||||
float Z = 0.0;
|
||||
for (int j = 0; j <= kSize; ++j)
|
||||
{
|
||||
kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j), params.SIGMA);
|
||||
}
|
||||
|
||||
vec3 cc;
|
||||
float factor;
|
||||
float bZ = 1.0/normpdf(0.0, params.BSIGMA);
|
||||
//read out the texels
|
||||
for (int i=-kSize; i <= kSize; ++i)
|
||||
{
|
||||
for (int j=-kSize; j <= kSize; ++j)
|
||||
{
|
||||
cc = texture(Source, (fragcoord.xy+vec2(float(i),float(j))) / params.OutputSize.xy).rgb;
|
||||
factor = normpdf3(cc-c, params.BSIGMA)*bZ*kernel[kSize+j]*kernel[kSize+i];
|
||||
Z += factor;
|
||||
final_colour += factor*cc;
|
||||
}
|
||||
}
|
||||
|
||||
FragColor = vec4(final_colour/Z, 1.0);
|
||||
}
|
6
denoisers/slow-bilateral.slangp
Normal file
6
denoisers/slow-bilateral.slangp
Normal file
|
@ -0,0 +1,6 @@
|
|||
shaders = 1
|
||||
|
||||
shader0 = shaders/slow-bilateral.slang
|
||||
scale_type0 = source
|
||||
filter_linear0 = true
|
||||
scale0 = 1.0
|
Loading…
Reference in a new issue