Files
prosperon/shaders/msl/blur.frag.msl
2025-12-22 16:21:21 -06:00

35 lines
887 B
Plaintext

#include <metal_stdlib>
using namespace metal;
struct Uniforms {
float2 direction; // (1,0) for horizontal, (0,1) for vertical
float2 texel_size; // 1.0 / texture_size
};
struct FragmentIn {
float4 position [[position]];
float2 uv;
};
// 9-tap Gaussian blur
fragment float4 fragment_main(
FragmentIn in [[stage_in]],
constant Uniforms &uniforms [[buffer(0)]],
texture2d<float> tex [[texture(0)]],
sampler samp [[sampler(0)]]
) {
float2 offset = uniforms.direction * uniforms.texel_size;
// Gaussian weights for 9 samples
float weights[5] = {0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216};
float4 result = tex.sample(samp, in.uv) * weights[0];
for (int i = 1; i < 5; i++) {
result += tex.sample(samp, in.uv + offset * float(i)) * weights[i];
result += tex.sample(samp, in.uv - offset * float(i)) * weights[i];
}
return result;
}