36 lines
1.1 KiB
GLSL
36 lines
1.1 KiB
GLSL
#version 330
|
|
|
|
#moj_import <minecraft:globals.glsl>
|
|
|
|
uniform sampler2D InSampler;
|
|
|
|
layout(std140) uniform SamplerInfo {
|
|
vec2 OutSize;
|
|
vec2 InSize;
|
|
};
|
|
|
|
layout(std140) uniform BlurConfig {
|
|
vec2 BlurDir;
|
|
float Radius;
|
|
};
|
|
|
|
in vec2 texCoord;
|
|
|
|
out vec4 fragColor;
|
|
|
|
// This shader relies on GL_LINEAR sampling to reduce the amount of texture samples in half.
|
|
// Instead of sampling each pixel position with a step of 1 we sample between pixels with a step of 2.
|
|
// In the end we sample the last pixel with a half weight, since the amount of pixels to sample is always odd (actualRadius * 2 + 1).
|
|
void main() {
|
|
vec2 oneTexel = 1.0 / InSize;
|
|
vec2 sampleStep = oneTexel * BlurDir;
|
|
|
|
vec4 blurred = vec4(0.0);
|
|
float actualRadius = Radius >= 0.5 ? round(Radius) : float(MenuBlurRadius);
|
|
for (float a = -actualRadius + 0.5; a <= actualRadius; a += 2.0) {
|
|
blurred += texture(InSampler, texCoord + sampleStep * a);
|
|
}
|
|
blurred += texture(InSampler, texCoord + sampleStep * actualRadius) / 2.0;
|
|
fragColor = blurred / (actualRadius + 0.5);
|
|
}
|