armory/Shaders/blur_bilat_pass/blur_bilat_pass.frag.glsl

124 lines
3.4 KiB
Plaintext
Raw Normal View History

2018-01-06 00:33:33 +01:00
// Exclusive to volumetric light for now
#version 450
#include "compiled.inc"
2018-01-06 00:33:33 +01:00
uniform sampler2D tex;
uniform vec2 dir;
uniform vec2 screenSize;
in vec2 texCoord;
2018-01-28 13:53:06 +01:00
out float fragColor;
2018-01-06 00:33:33 +01:00
const float weight[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
float normpdf(float x, float sigma) {
return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;
}
float normpdf3(vec3 v, float sigma) {
return 0.39894 * exp(-0.5 * dot(v, v) / (sigma * sigma)) / sigma;
}
void main() {
vec2 step = (dir / screenSize.xy);
vec3 colf = texture(tex, texCoord).rgb * weight[0];
2018-01-28 13:53:06 +01:00
float col;
2018-01-06 00:33:33 +01:00
float sumfactor = 0.0;
float factor;
2018-01-28 13:53:06 +01:00
float f = 1.0 / normpdf(0.0, 1.0);
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step).r;
factor = normpdf3(col - colf, 1.0) * f * weight[1];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor = factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[1];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[2];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[2];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[3];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[3];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[4];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[4];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[5];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[5];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[6];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[6];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[7];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[7];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[8];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[8];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord + step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[9];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
col = texture(tex, texCoord - step * 1.5).r;
factor = normpdf3(col - colf, 1.0) * f * weight[9];
2018-01-06 00:33:33 +01:00
sumfactor += factor;
2018-01-28 13:53:06 +01:00
fragColor += factor * col;
2018-01-06 00:33:33 +01:00
2018-01-28 13:53:06 +01:00
fragColor /= sumfactor;
2018-01-06 00:33:33 +01:00
}