playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
32 lines (31 loc) • 827 B
JavaScript
var blurVSM_default = `
varying vUv0: vec2f;
var source: texture_2d<f32>;
var sourceSampler: sampler;
uniform weight: array<f32, {SAMPLES}>;
uniform pixelOffset: vec2f;
@fragment
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
var output: FragmentOutput;
var moments: vec3f = vec3f(0.0);
let uv: vec2f = input.vUv0 - uniform.pixelOffset * (f32({SAMPLES}) * 0.5);
for (var i: i32 = 0; i < {SAMPLES}; i = i + 1) {
let c: vec4f = textureSample(source, sourceSampler, uv + uniform.pixelOffset * f32(i));
moments = moments + c.xyz * uniform.weight[i].element;
moments = moments + c.xyz;
}
moments = moments * (1.0 / f32({SAMPLES}));
output.color = vec4f(moments, 1.0);
return output;
}
`;
export {
blurVSM_default as default
};