I should start using recipes more then I don’t have to dig through 100x files to find something
“`cpp
#bind layer src float4 #bind layer &dst float4 #bind parm radius int value=4 #bind parm sigma_s float value=4.0 // spatial falloff #bind parm sigma_r float value=0.1 // range/value falloff
@KERNEL { int2 gid = (int2)(@ix, @iy); int w = @src.xres; int h = @src.yres;
float4 center = (float4)(@src.bufferIndex(gid)); float4 acc = (float4)(0.0f); float weight = 0.0f;
float ss2 = 2.0f * @sigma_s * @sigma_s; float sr2 = 2.0f *max(@sigma_r,0.001f) * max(@sigma_r,0.001f);
int r = @radius;
for (int dy = -r; dy <= r; dy++) { for (int dx = -r; dx <= r; dx++) { int2 p = (int2)( clamp(gid.x + dx, 0, w-1), clamp(gid.y + dy, 0, h-1) );
float4 sample = (float4)(@src.bufferIndex(p));
// Spatial weight — gaussian falloff by pixel distance float spatial = (float)(dx*dx + dy*dy) / ss2;
// Range weight — gaussian falloff by value difference float4 diff = sample – center; float range = dot(diff, diff) / sr2;
float w_combined = exp(-spatial – range);
acc += sample * w_combined; weight += w_combined; } }
@dst.set(acc / weight); }
“`