Files
MinecraftDungeons/data/shaders/convolution.fragment
T
2026-03-08 15:30:46 -05:00

55 lines
1.6 KiB
Plaintext

// __multiversion__
// This signals the loading code to prepend either #version 100 or #version 300 es as apropriate.
// To use centroid sampling we need to have version 300 es shaders, which requires changing:
// attribute to in
// varying to out when in vertex shaders or in when in fragment shaders
// defining an out vec4 FragColor and replacing uses of gl_FragColor with FragColor
// texture2D to texture
#if __VERSION__ >= 300
// version 300 code
#ifdef MSAA_FRAMEBUFFER_ENABLED
#define _centroid centroid
#else
#define _centroid
#endif
_centroid in vec2 uv;
#define varying in
#define texture2D texture
out vec4 FragColor;
#define gl_FragColor FragColor
#else
// version 100 code
varying vec2 uv;
#endif
#define KERNEL_SIZE_FLOAT 19.0
#define KERNEL_SIZE_INT 19
uniform sampler2D TEXTURE_0;
//uniform float cKernel[ KERNEL_SIZE_INT ];
const float cKernel[ KERNEL_SIZE_INT ] = float[](0.0014794516787135662, 0.003804239018665086, 0.00875346226514214, 0.018023411141080636, 0.03320772876259043, 0.05475028876252328, 0.0807753247211904, 0.10663900118033988, 0.12597909446198644, 0.1331759960155365, 0.12597909446198644, 0.10663900118033988, 0.0807753247211904, 0.05475028876252328, 0.03320772876259043, 0.018023411141080636, 0.00875346226514214, 0.003804239018665086, 0.0014794516787135662);
varying vec3 uBlurIncrement;
void main()
{
vec2 imageCoord = uv;
vec4 sum = vec4(0.0);
for (float i = 0.0; i < KERNEL_SIZE_FLOAT; i++) {
sum += texture2D(TEXTURE_0, imageCoord) * cKernel[int(i)];
imageCoord += uBlurIncrement.xy * uBlurIncrement.z;
}
gl_FragColor = sum;
}