armory/Shaders/blur_edge_pass/blur_edge_pass.frag.glsl

52 lines
1.5 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
#ifdef GL_ES
precision mediump float;
#endif
2016-08-09 23:51:40 +02:00
#include "../compiled.glsl"
2016-10-17 17:39:40 +02: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;
2016-10-12 17:52:27 +02:00
out vec4 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
2017-03-11 01:50:47 +01:00
float doBlur(const float blurWeight, const int pos, const vec3 nor, const vec2 texCoord) {
const float posadd = pos + 0.5;
2016-06-07 09:38:49 +02:00
2017-03-11 01:50:47 +01:00
vec3 nor2 = getNor(texture(gbuffer0, texCoord + pos * dirInv).rg);
2016-08-07 23:12:14 +02:00
float influenceFactor = step(discardThreshold, dot(nor2, nor));
2017-03-11 01:50:47 +01:00
float col = texture(tex, texCoord + posadd * dirInv).r;
fragColor.r += col * blurWeight * influenceFactor;
2016-08-07 23:12:14 +02:00
float weight = blurWeight * influenceFactor;
2017-03-11 01:50:47 +01:00
nor2 = getNor(texture(gbuffer0, texCoord - pos * dirInv).rg);
2016-08-07 23:12:14 +02:00
influenceFactor = step(discardThreshold, dot(nor2, nor));
2017-03-11 01:50:47 +01:00
col = texture(tex, texCoord - posadd * dirInv).r;
fragColor.r += col * blurWeight * influenceFactor;
2016-08-07 23:12:14 +02:00
weight += blurWeight * influenceFactor;
return weight;
2016-06-07 09:38:49 +02:00
}
void main() {
2016-08-09 23:51:40 +02:00
vec2 tc = texCoord * ssaoTextureScale;
2016-08-07 23:12:14 +02:00
vec3 nor = getNor(texture(gbuffer0, texCoord).rg);
2016-06-07 09:38:49 +02:00
2017-03-11 01:50:47 +01:00
fragColor.r = texture(tex, tc).r * blurWeights[0];
float weight = blurWeights[0];
2017-11-20 12:38:35 +01:00
weight += doBlur(blurWeights[1], 1, nor, tc);
weight += doBlur(blurWeights[2], 2, nor, tc);
weight += doBlur(blurWeights[3], 3, nor, tc);
weight += doBlur(blurWeights[4], 4, nor, tc);
2016-06-07 09:38:49 +02:00
2017-05-22 15:55:34 +02:00
fragColor = vec4(fragColor.r / weight); // SSAO only
2017-03-14 20:43:54 +01:00
}