5struct LensDistortionSettings { 14const VISUAL_THRESHOLD: f32 = 1e-4; 15const MATH_EPSILON: f32 = 1e-6; 18@group(0) @binding(5) var<uniform> lens_distortion_settings: LensDistortionSettings; 20fn lens_distortion(uv: vec2<f32>) -> vec2<f32> { 21 let intensity = lens_distortion_settings.intensity; 22 if (abs(intensity) < VISUAL_THRESHOLD) { 25 let multiplier = lens_distortion_settings.multiplier; 26 let center = lens_distortion_settings.center; 28 let uv_centered = uv - center; 30 let radius = max(length(uv_centered), MATH_EPSILON); 32 let direction = uv_centered / radius; 33 let adjust = dot(abs(direction), multiplier); 37 let k1 = intensity * adjust; 38 let k2 = k1 * intensity * lens_distortion_settings.edge_curvature; 40 let r2 = radius * radius; 41 let r_distorted = radius * (1.0 + (k1 + k2 * r2) * r2); 43 let uv_distorted = direction * r_distorted + center; 46 let uv_scaled = (uv_distorted - center) / lens_distortion_settings.scale + center; 49 let uv_safe = clamp(uv_scaled, vec2<f32>(0.0), vec2<f32>(1.0));