armory/Shaders/blur_edge_pass/blur_edge_pass.frag.glsl

44 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2016-08-09 23:51:40 +02:00
// Exclusive to SSAO for now
2016-06-07 09:38:49 +02:00
#version 450
#include "compiled.inc"
2017-12-13 14:21:42 +01:00
#include "std/gbuffer.glsl"
2016-08-09 23:51:40 +02:00
2016-06-07 09:38:49 +02:00
uniform sampler2D tex;
uniform sampler2D gbuffer0;
2016-06-21 13:29:27 +02:00
2017-03-11 01:50:47 +01:00
uniform vec2 dirInv; // texStep
2016-06-07 09:38:49 +02:00
in vec2 texCoord;
2018-12-06 15:23:08 +01:00
out float fragColor;
2016-06-07 09:38:49 +02:00
2018-12-07 13:48:40 +01:00
// const float blurWeights[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
const float blurWeights[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
2016-08-09 23:51:40 +02:00
const float discardThreshold = 0.95;
2016-06-07 09:38:49 +02:00
void main() {
2018-12-06 15:23:08 +01:00
vec3 nor = getNor(textureLod(gbuffer0, texCoord, 0.0).rg);
2016-06-07 09:38:49 +02:00
2018-12-06 20:36:56 +01:00
fragColor = textureLod(tex, texCoord, 0.0).r * blurWeights[0];
2017-03-11 01:50:47 +01:00
float weight = blurWeights[0];
2018-12-06 15:23:08 +01:00
2018-12-07 13:48:40 +01:00
for (int i = 1; i < 8; ++i) {
float posadd = i;// + 0.5;
2018-12-06 15:23:08 +01:00
2018-12-06 20:36:56 +01:00
vec3 nor2 = getNor(textureLod(gbuffer0, texCoord + i * dirInv, 0.0).rg);
2018-12-06 15:23:08 +01:00
float influenceFactor = step(discardThreshold, dot(nor2, nor));
2018-12-06 20:36:56 +01:00
float col = textureLod(tex, texCoord + posadd * dirInv, 0.0).r;
2018-12-06 15:23:08 +01:00
float w = blurWeights[i] * influenceFactor;
fragColor += col * w;
weight += w;
2018-12-06 20:36:56 +01:00
nor2 = getNor(textureLod(gbuffer0, texCoord - i * dirInv, 0.0).rg);
2018-12-06 15:23:08 +01:00
influenceFactor = step(discardThreshold, dot(nor2, nor));
2018-12-06 20:36:56 +01:00
col = textureLod(tex, texCoord - posadd * dirInv, 0.0).r;
2018-12-06 15:23:08 +01:00
w = blurWeights[i] * influenceFactor;
fragColor += col * w;
weight += w;
2018-11-27 21:34:42 +01:00
}
2016-06-07 09:38:49 +02:00
2018-12-06 15:23:08 +01:00
fragColor = fragColor / weight;
2017-03-14 20:43:54 +01:00
}