oglc/shader/quad/shader.frag

59 lines
1.5 KiB
GLSL
Raw Normal View History

2021-07-07 00:13:56 +02:00
#version 430 core
2021-07-04 03:53:37 +02:00
out vec4 FragColor;
2021-07-06 01:58:55 +02:00
in vec3 ourColor;
2021-07-06 22:20:01 +02:00
in vec2 TexCoord;
uniform sampler2D ourTexture;
2021-07-05 09:51:55 +02:00
2023-02-26 03:49:52 +01:00
#define INV_SQRT_OF_2PI 0.39894228040143267793994605993439 // 1.0/SQRT_OF_2PI
#define INV_PI 0.31830988618379067153776752674503
// https://github.com/BrutPitt/glslSmartDeNoise/blob/master/Shaders/frag.glsl
vec4 denoise(sampler2D tex, vec2 uv, float sigma, float kSigma, float threshold)
{
float radius = round(kSigma*sigma);
float radQ = radius*radius;
float invSigmaQx2 = .5 / (sigma*sigma);
float invSigmaQx2PI = INV_PI * invSigmaQx2;
float invThresholdSqx2 = .5 / (threshold*threshold);
float invThresholdSqrt2PI = INV_SQRT_OF_2PI / threshold;
vec4 centrPx = texture(tex,uv);
float zBuff = 0.0;
vec4 aBuff = vec4(0.0);
vec2 size = vec2(textureSize(tex, 0));
vec2 d;
for (d.x=-radius; d.x <= radius; d.x++)
{
float pt = sqrt(radQ-d.x*d.x);
for(d.y=-pt; d.y <= pt; d.y++)
{
float blurFactor = exp(-dot(d,d)*invSigmaQx2)*invSigmaQx2PI;
vec4 walkPx = texture(tex,uv+d/size);
vec4 dC = walkPx-centrPx;
float deltaFactor = exp(-dot(dC.rgb,dC.rgb) * invThresholdSqx2) * invThresholdSqrt2PI * blurFactor;
zBuff += deltaFactor;
aBuff += deltaFactor*walkPx;
}
}
return aBuff/zBuff;
}
2021-07-04 03:53:37 +02:00
void main()
{
2023-02-26 04:27:52 +01:00
float sigma = 2.5;
float kSigma = 7.0;
float threshold = 0.3;
2023-02-26 03:49:52 +01:00
2023-03-01 01:11:29 +01:00
//FragColor = denoise(ourTexture, TexCoord, sigma, kSigma, threshold);
FragColor = texture(ourTexture, TexCoord);
2021-07-04 03:53:37 +02:00
}