armory/Shaders/blur_edge_pass/blur_edge_pass.frag.glsl

44 lines
1.1 KiB
Plaintext
Raw 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
2017-03-14 20:43:54 +01:00
const float blurWeights[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
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
vec2 tc = texCoord;
vec3 nor = getNor(textureLod(gbuffer0, texCoord, 0.0).rg);
2016-06-07 09:38:49 +02:00
2018-12-06 15:23:08 +01:00
fragColor = textureLod(tex, tc, 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
for (int i = 1; i < 5; ++i) {
float posadd = i + 0.5;
vec3 nor2 = getNor(textureLod(gbuffer0, tc + i * dirInv, 0.0).rg);
float influenceFactor = step(discardThreshold, dot(nor2, nor));
float col = textureLod(tex, tc + posadd * dirInv, 0.0).r;
float w = blurWeights[i] * influenceFactor;
fragColor += col * w;
weight += w;
nor2 = getNor(textureLod(gbuffer0, tc - i * dirInv, 0.0).rg);
influenceFactor = step(discardThreshold, dot(nor2, nor));
col = textureLod(tex, tc - posadd * dirInv, 0.0).r;
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
}