armory/Shaders/blur_adaptive_pass/blur_adaptive_pass.frag.glsl

52 lines
1.3 KiB
Plaintext
Raw Normal View History

2016-08-09 23:51:40 +02:00
// Exclusive to SSR for now
2016-06-21 13:29:27 +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"
// unpackFloat()
2016-08-09 23:51:40 +02:00
2016-06-21 13:29:27 +02:00
uniform sampler2D tex;
2016-08-07 01:43:21 +02:00
uniform sampler2D gbuffer0; // Roughness
2016-06-21 13:29:27 +02:00
uniform vec2 dir;
uniform vec2 screenSize;
in vec2 texCoord;
2016-10-12 17:52:27 +02:00
out vec4 fragColor;
2016-06-21 13:29:27 +02:00
void main() {
2016-08-09 23:51:40 +02:00
vec2 tc = texCoord * ssrTextureScale;
2016-08-29 09:56:34 +02:00
float roughness = unpackFloat(texture(gbuffer0, texCoord).b).y;
2016-09-08 14:08:31 +02:00
// if (roughness == 0.0) { // Always blur for now, non blured output can produce noise
2016-10-12 17:52:27 +02:00
// fragColor = texture(tex, tc);
2016-09-08 14:08:31 +02:00
// return;
// }
2016-10-17 00:02:51 +02:00
if (roughness >= 0.8) { // No reflections
fragColor = texture(tex, tc);
return;
}
2016-06-21 13:29:27 +02:00
2016-08-09 23:51:40 +02:00
vec2 step = dir / screenSize * ssrTextureScale;
2016-06-21 13:29:27 +02:00
2016-08-09 23:51:40 +02:00
vec3 result = texture(tex, tc + step * 2.5).rgb;
// vec3 result = texture(tex, tc + step * 5.5).rgb;
// result += texture(tex, tc + step * 4.5).rgb;
// result += texture(tex, tc + step * 3.5).rgb;
// result += texture(tex, tc + step * 2.5).rgb;
result += texture(tex, tc + step * 1.5).rgb;
result += texture(tex, tc).rgb;
result += texture(tex, tc - step * 1.5).rgb;
result += texture(tex, tc - step * 2.5).rgb;
// result += texture(tex, tc - step * 3.5).rgb;
// result += texture(tex, tc - step * 4.5).rgb;
// result += texture(tex, tc - step * 5.5).rgb;
2016-08-07 23:12:14 +02:00
// result /= vec3(11.0);
result /= vec3(5.0);
2016-06-21 13:29:27 +02:00
2016-10-12 17:52:27 +02:00
fragColor.rgb = vec3(result);
2016-06-21 13:29:27 +02:00
}