2017-12-03 11:19:13 +01:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
#include "../compiled.glsl"
|
|
|
|
#include "../std/gbuffer.glsl"
|
|
|
|
|
|
|
|
uniform sampler2D tex;
|
|
|
|
uniform sampler2D gbuffer0;
|
|
|
|
uniform sampler2D dist;
|
|
|
|
|
|
|
|
uniform vec2 dirInv; // texStep
|
|
|
|
|
|
|
|
in vec2 texCoord;
|
|
|
|
out float fragColor;
|
|
|
|
|
|
|
|
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);
|
|
|
|
const float discardThreshold = 0.95;
|
|
|
|
|
2017-12-05 21:41:17 +01:00
|
|
|
float doBlur(const float blurWeight, const int pos, const vec3 nor, const float depth, const vec2 texCoord) {
|
2017-12-03 11:19:13 +01:00
|
|
|
const float posadd = pos + 0.5;
|
|
|
|
|
2017-12-05 21:41:17 +01:00
|
|
|
vec4 g0 = texture(gbuffer0, texCoord + pos * dirInv);
|
|
|
|
vec3 nor2 = getNor(g0.rg);
|
|
|
|
float influenceFactor = step(discardThreshold, dot(nor2, nor)) * step(abs(depth - g0.a), 0.001);
|
2017-12-03 11:19:13 +01:00
|
|
|
float col = texture(tex, texCoord + posadd * dirInv).r;
|
|
|
|
fragColor += col * blurWeight * influenceFactor;
|
|
|
|
float weight = blurWeight * influenceFactor;
|
|
|
|
|
2017-12-05 21:41:17 +01:00
|
|
|
g0 = texture(gbuffer0, texCoord - pos * dirInv);
|
|
|
|
nor2 = getNor(g0.rg);
|
|
|
|
influenceFactor = step(discardThreshold, dot(nor2, nor)) * step(abs(depth - g0.a), 0.001);
|
2017-12-03 11:19:13 +01:00
|
|
|
col = texture(tex, texCoord - posadd * dirInv).r;
|
|
|
|
fragColor += col * blurWeight * influenceFactor;
|
|
|
|
weight += blurWeight * influenceFactor;
|
|
|
|
|
|
|
|
return weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2017-12-05 21:41:17 +01:00
|
|
|
vec4 g0 = texture(gbuffer0, texCoord);
|
|
|
|
vec3 nor = getNor(g0.rg);
|
|
|
|
float depth = g0.a;
|
2017-12-03 11:19:13 +01:00
|
|
|
|
|
|
|
float sm = texture(tex, texCoord).r;
|
|
|
|
fragColor = sm * blurWeights[0];
|
|
|
|
float weight = blurWeights[0];
|
|
|
|
float d = texture(dist, texCoord).r;
|
2017-12-04 23:37:45 +01:00
|
|
|
int numTaps = clamp(int(d * 10 * penumbraScale), 2, 10 * penumbraScale);
|
2017-12-04 19:49:06 +01:00
|
|
|
#ifdef _PenumbraScale
|
2017-12-05 21:41:17 +01:00
|
|
|
for (int i = 1; i < numTaps; ++i) weight += doBlur(blurWeights[int(i / penumbraScale)], i, nor, depth, texCoord);
|
2017-12-04 19:49:06 +01:00
|
|
|
#else
|
2017-12-05 21:41:17 +01:00
|
|
|
for (int i = 1; i < numTaps; ++i) weight += doBlur(blurWeights[i - 1], i, nor, depth, texCoord);
|
2017-12-04 19:49:06 +01:00
|
|
|
#endif
|
2017-12-03 11:19:13 +01:00
|
|
|
fragColor /= weight;
|
|
|
|
}
|