1//! Wave 35B — Depth, Optical & Filter FX GPU pipelines and evaluators:
2//! - `DepthBlur` (depth-driven CoC blur from `BlurImage`/`BlurChannel` or `aux.z`)
3//! - `Fog` (depth-driven atmospheric fog from `aux.z` or `FogImage`/`Fog`)
4//! - `Highlight` (2-pass bright-threshold extraction + directional starburst streaks)
5//! - `HotSpot` (radial primary glow + secondary optical lens flare elements)
6//! - `RankFilter` (GPU order-statistic Min/Median/Max/Percentile filter)
7//!
8//! WebGPU safety: `R32Float` depth textures are bound with `filterable: false` and read
9//! exclusively via `textureLoad`; output storage textures are `WriteOnly`.
10
11use super::*;
12use crate::cache::{AuxChannelTex, EMPTY_Z_SENTINEL};
13use std::num::NonZeroU64;
14
15const DEPTH_OPTICAL_WGSL: &str = include_str!("../shaders/depth_optical.wgsl");
16const UNIFORM_SLOTS_PER_CHUNK: u32 = 512;
17const MAX_RANK_RADIUS: f32 = 5.0;
18
19#[derive(Clone, Copy)]
20enum DepthOpticalOp {
21 DepthBlur,
22 Fog,
23 HighlightExtract,
24 HighlightStreaks,
25 HotSpot,
26 RankFilter,
27}
28
29fn build_wgsl(format: wgpu::TextureFormat, hdr_float: bool) -> String {
30 let storage_fmt = match format {
31 wgpu::TextureFormat::Rgba16Float => "rgba16float",
32 wgpu::TextureFormat::Rgba32Float => "rgba32float",
33 _ => "rgba8unorm",
34 };
35 let mut src = DEPTH_OPTICAL_WGSL.to_owned();
36 if storage_fmt != "rgba8unorm" {
37 src = src.replace(
38 "texture_storage_2d<rgba8unorm, write>",
39 &format!("texture_storage_2d<{storage_fmt}, write>"),
40 );
41 }
42 if hdr_float {
43 src = src.replace("const HDR_FLOAT: bool = false;", "const HDR_FLOAT: bool = true;");
44 }
45 src
46}
47
48fn tex_entry(binding: u32, filterable: bool) -> wgpu::BindGroupLayoutEntry {
49 wgpu::BindGroupLayoutEntry {
50 binding,
51 visibility: wgpu::ShaderStages::COMPUTE,
52 ty: wgpu::BindingType::Texture {
53 sample_type: wgpu::TextureSampleType::Float { filterable },
54 view_dimension: wgpu::TextureViewDimension::D2,
55 multisampled: false,
56 },
57 count: None,
58 }
59}
60
61struct FormatPipelines {
62 bgl: wgpu::BindGroupLayout,
63 depth_blur: wgpu::ComputePipeline,
64 fog: wgpu::ComputePipeline,
65 highlight_extract: wgpu::ComputePipeline,
66 highlight_streaks: wgpu::ComputePipeline,
67 hot_spot: wgpu::ComputePipeline,
68 rank_filter: wgpu::ComputePipeline,
69}
70
71pub(super) struct DepthOpticalPipelines {
72 sampler: wgpu::Sampler,
73 uniform_stride: u32,
74 uniform_chunks: Vec<wgpu::Buffer>,
75 uniform_cursor: u32,
76 dummy_z: AuxChannelTex,
77 formats: HashMap<(wgpu::TextureFormat, bool), FormatPipelines>,
78}
79
80impl DepthOpticalPipelines {
81 pub(super) fn new(device: &wgpu::Device, queue: &wgpu::Queue) -> Self {
82 let uniform_size = std::mem::size_of::<UniformParams>() as u32;
83 let min_align = device.limits().min_uniform_buffer_offset_alignment.max(1);
84 let uniform_stride = uniform_size.div_ceil(min_align) * min_align;
85
86 let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
87 label: Some("depth-optical-linear"),
88 address_mode_u: wgpu::AddressMode::ClampToEdge,
89 address_mode_v: wgpu::AddressMode::ClampToEdge,
90 mag_filter: wgpu::FilterMode::Linear,
91 min_filter: wgpu::FilterMode::Linear,
92 mipmap_filter: wgpu::MipmapFilterMode::Nearest,
93 ..Default::default()
94 });
95
96 let dummy_z = AuxChannelTex::new(device, [1, 1], wgpu::TextureFormat::R32Float, "do-dummy-z");
97 queue.write_texture(
98 dummy_z.texture.as_image_copy(),
99 &EMPTY_Z_SENTINEL.to_le_bytes(),
100 wgpu::TexelCopyBufferLayout {
101 offset: 0,
102 bytes_per_row: Some(4),
103 rows_per_image: Some(1),
104 },
105 wgpu::Extent3d { width: 1, height: 1, depth_or_array_layers: 1 },
106 );
107
108 Self {
109 sampler,
110 uniform_stride,
111 uniform_chunks: Vec::new(),
112 uniform_cursor: 0,
113 dummy_z,
114 formats: HashMap::new(),
115 }
116 }
117
118 pub(super) fn reset_uniform_cursor(&mut self) {
119 self.uniform_cursor = 0;
120 }
121
122 pub(super) fn trim_uniform_chunks(&mut self, max_chunks: usize) {
123 self.uniform_cursor = 0;
124 if self.uniform_chunks.len() > max_chunks {
125 self.uniform_chunks.truncate(max_chunks);
126 }
127 }
128
129 fn alloc_uniform_slot(
130 &mut self,
131 device: &wgpu::Device,
132 queue: &wgpu::Queue,
133 params: &UniformParams,
134 ) -> (usize, u32) {
135 let slot_global = self.uniform_cursor;
136 let chunk_idx = (slot_global / UNIFORM_SLOTS_PER_CHUNK) as usize;
137 let slot_in_chunk = slot_global % UNIFORM_SLOTS_PER_CHUNK;
138 while chunk_idx >= self.uniform_chunks.len() {
139 let size = u64::from(UNIFORM_SLOTS_PER_CHUNK) * u64::from(self.uniform_stride);
140 let buf = device.create_buffer(&wgpu::BufferDescriptor {
141 label: Some("depth-optical-params-ring"),
142 size,
143 usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
144 mapped_at_creation: false,
145 });
146 self.uniform_chunks.push(buf);
147 }
148 let offset = slot_in_chunk * self.uniform_stride;
149 queue.write_buffer(
150 &self.uniform_chunks[chunk_idx],
151 u64::from(offset),
152 bytemuck::bytes_of(params),
153 );
154 self.uniform_cursor = slot_global + 1;
155 (chunk_idx, offset)
156 }
157
158 fn ensure_format(&mut self, device: &wgpu::Device, format: wgpu::TextureFormat, hdr_float: bool) {
159 if self.formats.contains_key(&(format, hdr_float)) {
160 return;
161 }
162 let u_size = std::mem::size_of::<UniformParams>() as u64;
163 let bgl = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
164 label: Some("depth-optical-bgl"),
165 entries: &[
166 tex_entry(0, true),
167 tex_entry(1, true),
168 tex_entry(2, false), // R32Float depth: MUST be unfilterable for WebGPU/wasm32!
169 tex_entry(3, true),
170 wgpu::BindGroupLayoutEntry {
171 binding: 4,
172 visibility: wgpu::ShaderStages::COMPUTE,
173 ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
174 count: None,
175 },
176 wgpu::BindGroupLayoutEntry {
177 binding: 5,
178 visibility: wgpu::ShaderStages::COMPUTE,
179 ty: wgpu::BindingType::StorageTexture {
180 access: wgpu::StorageTextureAccess::WriteOnly,
181 format,
182 view_dimension: wgpu::TextureViewDimension::D2,
183 },
184 count: None,
185 },
186 wgpu::BindGroupLayoutEntry {
187 binding: 6,
188 visibility: wgpu::ShaderStages::COMPUTE,
189 ty: wgpu::BindingType::Buffer {
190 ty: wgpu::BufferBindingType::Uniform,
191 has_dynamic_offset: true,
192 min_binding_size: NonZeroU64::new(u_size),
193 },
194 count: None,
195 },
196 ],
197 });
198 let pl = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
199 label: Some("depth-optical-pl"),
200 bind_group_layouts: &[Some(&bgl)],
201 immediate_size: 0,
202 });
203 let module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
204 label: Some("depth-optical-wgsl"),
205 source: wgpu::ShaderSource::Wgsl(build_wgsl(format, hdr_float).into()),
206 });
207 let mk = |entry: &str| {
208 device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
209 label: Some(entry),
210 layout: Some(&pl),
211 module: &module,
212 entry_point: Some(entry),
213 compilation_options: Default::default(),
214 cache: None,
215 })
216 };
217 self.formats.insert(
218 (format, hdr_float),
219 FormatPipelines {
220 bgl,
221 depth_blur: mk("depth_blur_op"),
222 fog: mk("fog_op"),
223 highlight_extract: mk("highlight_extract_op"),
224 highlight_streaks: mk("highlight_streaks_op"),
225 hot_spot: mk("hot_spot_op"),
226 rank_filter: mk("rank_filter_op"),
227 },
228 );
229 }
230
231 #[allow(clippy::too_many_arguments)]
232 fn dispatch(
233 &mut self,
234 device: &wgpu::Device,
235 queue: &wgpu::Queue,
236 enc: &mut wgpu::CommandEncoder,
237 op: DepthOpticalOp,
238 src_view: &wgpu::TextureView,
239 aux_img_view: &wgpu::TextureView,
240 z_view: Option<&wgpu::TextureView>,
241 mask_view: &wgpu::TextureView,
242 dst: &CachedTexture,
243 params: &UniformParams,
244 ) {
245 let format = dst.texture.format();
246 let hdr_float = dst.depth.is_float();
247 self.ensure_format(device, format, hdr_float);
248 let (chunk_idx, offset) = self.alloc_uniform_slot(device, queue, params);
249 let fp = &self.formats[&(format, hdr_float)];
250 let zv = z_view.unwrap_or(&self.dummy_z.view);
251 let u_size = NonZeroU64::new(std::mem::size_of::<UniformParams>() as u64);
252 let bg = device.create_bind_group(&wgpu::BindGroupDescriptor {
253 label: Some("depth-optical-bg"),
254 layout: &fp.bgl,
255 entries: &[
256 wgpu::BindGroupEntry { binding: 0, resource: wgpu::BindingResource::TextureView(src_view) },
257 wgpu::BindGroupEntry { binding: 1, resource: wgpu::BindingResource::TextureView(aux_img_view) },
258 wgpu::BindGroupEntry { binding: 2, resource: wgpu::BindingResource::TextureView(zv) },
259 wgpu::BindGroupEntry { binding: 3, resource: wgpu::BindingResource::TextureView(mask_view) },
260 wgpu::BindGroupEntry { binding: 4, resource: wgpu::BindingResource::Sampler(&self.sampler) },
261 wgpu::BindGroupEntry { binding: 5, resource: wgpu::BindingResource::TextureView(&dst.view) },
262 wgpu::BindGroupEntry {
263 binding: 6,
264 resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
265 buffer: &self.uniform_chunks[chunk_idx],
266 offset: 0,
267 size: u_size,
268 }),
269 },
270 ],
271 });
272 let pipeline = match op {
273 DepthOpticalOp::DepthBlur => &fp.depth_blur,
274 DepthOpticalOp::Fog => &fp.fog,
275 DepthOpticalOp::HighlightExtract => &fp.highlight_extract,
276 DepthOpticalOp::HighlightStreaks => &fp.highlight_streaks,
277 DepthOpticalOp::HotSpot => &fp.hot_spot,
278 DepthOpticalOp::RankFilter => &fp.rank_filter,
279 };
280 let mut pass = enc.begin_compute_pass(&wgpu::ComputePassDescriptor {
281 label: Some("depth-optical-pass"),
282 timestamp_writes: None,
283 });
284 pass.set_pipeline(pipeline);
285 pass.set_bind_group(0, &bg, &[offset]);
286 pass.dispatch_workgroups(dst.size[0].div_ceil(8), dst.size[1].div_ceil(8), 1);
287 }
288}
289
290fn parse_depth_blur_channel(comp: &Comp, node: &Node, time: f64, expr: &ExprEngine) -> i32 {
291 if let Some(s) = node.static_str("BlurChannel") {
292 return match s {
293 "Red" => 0,
294 "Green" => 1,
295 "Blue" => 2,
296 "Alpha" => 3,
297 "Z" | "ZBuffer" | "Z-Buffer" => 4,
298 "Luminance" | "Luma" => 5,
299 _ => 4,
300 };
301 }
302 comp.eval_number(node, "BlurChannel", time, 4.0, expr).round().clamp(0.0, 5.0) as i32
303}
304
305fn parse_depth_blur_filter(comp: &Comp, node: &Node, time: f64, expr: &ExprEngine) -> i32 {
306 if let Some(s) = node.static_str("Filter") {
307 return match s {
308 "Box" => 1,
309 "Gaussian" | "Fast Gaussian" => 2,
310 "Lens" | "Bokeh" => 3,
311 _ => 0,
312 };
313 }
314 comp.eval_number(node, "Filter", time, 0.0, expr).round().clamp(0.0, 3.0) as i32
315}
316
317fn parse_hotspot_apply_mode(comp: &Comp, node: &Node, time: f64, expr: &ExprEngine) -> i32 {
318 if let Some(s) = node.static_str("ApplyMode") {
319 return match s {
320 "Screen" => 1,
321 "Normal" | "Over" => 2,
322 "Multiply" => 3,
323 "Lighten" | "Max" => 4,
324 "Overlay" => 5,
325 _ => 0, // Add / LinearDodge
326 };
327 }
328 comp.eval_number(node, "ApplyMode", time, 0.0, expr).round().clamp(0.0, 5.0) as i32
329}
330
331fn parse_rank_filter_type(comp: &Comp, node: &Node, time: f64, expr: &ExprEngine) -> i32 {
332 if let Some(s) = node.static_str("FilterType") {
333 return match s {
334 "Circle" | "Circular" | "Disc" => 1,
335 "Cross" | "Plus" => 2,
336 "Diamond" => 3,
337 _ => 0, // Box / Square
338 };
339 }
340 comp.eval_number(node, "FilterType", time, 0.0, expr).round().clamp(0.0, 3.0) as i32
341}
342
343impl Engine {
344 pub(super) fn depth_optical_pipelines(&self) -> &RefCell<DepthOpticalPipelines> {
345 self.depth_optical_pipelines
346 .get_or_init(|| RefCell::new(DepthOpticalPipelines::new(&self.device, &self.queue)))
347 }
348
349 fn eval_num_alias(&self, comp: &Comp, node: &Node, primary: &str, fallback: &str, time: f64, default: f64) -> f32 {
350 if node.inputs.contains_key(primary) {
351 comp.eval_number(node, primary, time, default, &self.expr) as f32
352 } else {
353 comp.eval_number(node, fallback, time, default, &self.expr) as f32
354 }
355 }
356
357 fn combined_skip(&self, comp: &Comp, node: &Node, time: f64) -> [f32; 4] {
358 let p_skip = self.process_skip(comp, node, time);
359 let c_names = ["Red", "Green", "Blue", "Alpha"];
360 let mut out = p_skip;
361 for i in 0..4 {
362 if node.inputs.contains_key(c_names[i])
363 && comp.eval_number(node, c_names[i], time, 1.0, &self.expr) <= 0.5
364 {
365 out[i] = 1.0;
366 }
367 }
368 out
369 }
370
371 /// 1. `DepthBlur`: circle-of-confusion blur driven by `BlurImage`/`BlurChannel` or `aux.z`.
372 #[allow(clippy::too_many_arguments)]
373 pub(super) fn eval_depth_blur(
374 &mut self,
375 comp: &Comp,
376 node: &Node,
377 time: f64,
378 frame_i: i64,
379 enc: &mut wgpu::CommandEncoder,
380 visiting: &mut HashSet<(NodeId, i64)>,
381 stats: &mut EvalStats,
382 ) -> CachedTexture {
383 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
384 return self.dummy.clone();
385 };
386 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
387 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
388 let mbm = self.multiplies_by_mask(comp, node, time);
389 let blur_raw = self.eval_num_alias(comp, node, "XBlurSize", "BlurSize", time, 1.0).max(0.0);
390 // Fusion blur size uses 720px-width reference; src.canvas_size already reflects proxy_scale.
391 let max_r = (blur_raw * (src.canvas_size[0] as f32 / 720.0)).min(96.0);
392 if (blend <= 1e-6 || max_r < 0.25) && !mbm {
393 return src;
394 }
395
396 let src_aux = src.aux.clone();
397 let src = self.crop_to_canvas(enc, src);
398 let blur_img = node
399 .connected_node("BlurImage")
400 .and_then(|s| comp.find_node(s))
401 .map(|bid| {
402 let t = self.eval_node(comp, bid, time, enc, visiting, stats);
403 self.crop_to_canvas(enc, t)
404 });
405
406 let mut channel = parse_depth_blur_channel(comp, node, time, &self.expr);
407 let (depth_src_mode, z_tex_opt): (i32, Option<AuxChannelTex>) = if channel == 4 {
408 if let Some(bi) = &blur_img {
409 if let Some(bz) = bi.aux.as_ref().and_then(|a| a.z.clone()) {
410 (0, Some(bz))
411 } else {
412 channel = 5; // BlurImage without aux.z -> use luminance
413 (1, None)
414 }
415 } else if let Some(sz) = src_aux.as_ref().and_then(|a| a.z.clone()) {
416 (0, Some(sz))
417 } else {
418 // No depth source available -> pass through unless MultiplyByMask is active.
419 if !mbm {
420 let mut out = src;
421 out.set_aux(src_aux);
422 return out;
423 }
424 (0, None)
425 }
426 } else if blur_img.is_some() {
427 (1, None)
428 } else {
429 (2, None)
430 };
431
432 let focal = comp.eval_number(node, "FocalPoint", time, 0.0, &self.expr) as f32;
433 let dof = comp.eval_number(node, "DepthOfField", time, 0.0, &self.expr) as f32;
434 let z_scale = comp.eval_number(node, "ZScale", time, 1.0, &self.expr) as f32;
435 let filter_mode = parse_depth_blur_filter(comp, node, time, &self.expr);
436 let clamp_edges = if node.static_str("ClippingMode").unwrap_or("Frame") == "None" { 0.0 } else { 1.0 };
437 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
438 let skip = self.combined_skip(comp, node, time);
439 let taps = match (filter_mode, self.hiq) {
440 (1, true) => 3.0,
441 (1, false) => 2.0,
442 (_, true) => 36.0,
443 (_, false) => 16.0,
444 };
445
446 let mut u = UniformParams::default();
447 u.p[0] = [if depth_src_mode == 0 && z_tex_opt.is_none() { 0.0 } else { max_r }, focal, dof, z_scale];
448 u.p[1] = [filter_mode as f32, depth_src_mode as f32, channel as f32, clamp_edges];
449 u.p[2] = [blend, mask.is_some() as u8 as f32, mask_inv as u8 as f32, mbm as u8 as f32];
450 u.p[3] = skip;
451 u.p[4] = [taps, z_tex_opt.is_some() as u8 as f32, 0.0, 0.0];
452
453 let bi_hash = blur_img.as_ref().map_or(0, |b| b.content_hash);
454 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
455 let key = self.make_key(
456 node,
457 "DepthBlur",
458 src.size,
459 &[src.content_hash, bi_hash, mask_hash],
460 bytemuck::cast_slice(&u.p[..5]),
461 );
462 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
463 stats.cache_hits += 1;
464 return hit;
465 }
466 stats.cache_misses += 1;
467 stats.nodes_evaluated += 1;
468
469 let mut dst = self.alloc_tex_like(&src, src.depth, key);
470 dst.set_aux(src_aux);
471 let bv = blur_img.as_ref().map_or(&self.dummy.view, |b| &b.view);
472 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
473 let zv = z_tex_opt.as_ref().map(|z| z.view.as_ref());
474 self.depth_optical_pipelines().borrow_mut().dispatch(
475 &self.device,
476 &self.queue,
477 enc,
478 DepthOpticalOp::DepthBlur,
479 &src.view,
480 bv,
481 zv,
482 mv,
483 &dst,
484 &u,
485 );
486 self.cache.insert(key, dst.clone(), node.id, frame_i);
487 dst
488 }
489
490 /// 2. `Fog`: depth-driven atmospheric fog from `aux.z` or `FogImage`/`Fog`.
491 #[allow(clippy::too_many_arguments)]
492 pub(super) fn eval_fog(
493 &mut self,
494 comp: &Comp,
495 node: &Node,
496 time: f64,
497 frame_i: i64,
498 enc: &mut wgpu::CommandEncoder,
499 visiting: &mut HashSet<(NodeId, i64)>,
500 stats: &mut EvalStats,
501 ) -> CachedTexture {
502 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
503 return self.dummy.clone();
504 };
505 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
506 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
507 let fog_opacity = comp.eval_number(node, "FogOpacity", time, 1.0, &self.expr) as f32;
508 let mbm = self.multiplies_by_mask(comp, node, time);
509 if (blend <= 1e-6 || fog_opacity <= 1e-6) && !mbm {
510 return src;
511 }
512
513 let src_aux = src.aux.clone();
514 let src = self.crop_to_canvas(enc, src);
515 let fog_img = node
516 .connected_node("FogImage")
517 .or_else(|| node.connected_node("Fog"))
518 .and_then(|s| comp.find_node(s))
519 .map(|fid| {
520 let t = self.eval_node(comp, fid, time, enc, visiting, stats);
521 self.crop_to_canvas(enc, t)
522 });
523
524 let (depth_mode, has_fog_color_img, z_tex_opt): (i32, bool, Option<AuxChannelTex>) =
525 if let Some(sz) = src_aux.as_ref().and_then(|a| a.z.clone()) {
526 (0, fog_img.is_some(), Some(sz))
527 } else if let Some(fi) = &fog_img {
528 if let Some(fz) = fi.aux.as_ref().and_then(|a| a.z.clone()) {
529 (0, false, Some(fz))
530 } else {
531 (1, false, None)
532 }
533 } else {
534 (0, false, None)
535 };
536
537 let near_p = self.eval_num_alias(comp, node, "ZNearPlane", "NearPlane", time, 0.0);
538 let far_p = self.eval_num_alias(comp, node, "ZFarPlane", "FarPlane", time, -100.0);
539 let falloff = comp.eval_number(node, "Falloff", time, 1.0, &self.expr) as f32;
540 let z_scale = comp.eval_number(node, "ZScale", time, 1.0, &self.expr) as f32;
541 let fog_r = comp.eval_number(node, "FogRed", time, 1.0, &self.expr) as f32;
542 let fog_g = comp.eval_number(node, "FogGreen", time, 1.0, &self.expr) as f32;
543 let fog_b = comp.eval_number(node, "FogBlue", time, 1.0, &self.expr) as f32;
544 let fog_a = comp.eval_number(node, "FogAlpha", time, 1.0, &self.expr) as f32;
545 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
546 let skip = self.process_skip(comp, node, time);
547
548 let mut u = UniformParams::default();
549 u.p[0] = [near_p, far_p, falloff, z_scale];
550 u.p[1] = [fog_r, fog_g, fog_b, fog_a];
551 u.p[2] = [fog_opacity, depth_mode as f32, has_fog_color_img as u8 as f32, z_tex_opt.is_some() as u8 as f32];
552 u.p[3] = [blend, mask.is_some() as u8 as f32, mask_inv as u8 as f32, mbm as u8 as f32];
553 u.p[4] = skip;
554
555 let fi_hash = fog_img.as_ref().map_or(0, |f| f.content_hash);
556 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
557 let key = self.make_key(
558 node,
559 "Fog",
560 src.size,
561 &[src.content_hash, fi_hash, mask_hash],
562 bytemuck::cast_slice(&u.p[..5]),
563 );
564 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
565 stats.cache_hits += 1;
566 return hit;
567 }
568 stats.cache_misses += 1;
569 stats.nodes_evaluated += 1;
570
571 let mut dst = self.alloc_tex_like(&src, src.depth, key);
572 dst.set_aux(src_aux);
573 let fv = fog_img.as_ref().map_or(&self.dummy.view, |f| &f.view);
574 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
575 let zv = z_tex_opt.as_ref().map(|z| z.view.as_ref());
576 self.depth_optical_pipelines().borrow_mut().dispatch(
577 &self.device,
578 &self.queue,
579 enc,
580 DepthOpticalOp::Fog,
581 &src.view,
582 fv,
583 zv,
584 mv,
585 &dst,
586 &u,
587 );
588 self.cache.insert(key, dst.clone(), node.id, frame_i);
589 dst
590 }
591
592 /// 3. `Highlight`: threshold bright pixels (`Low`/`High`) + directional starburst streaks.
593 #[allow(clippy::too_many_arguments)]
594 pub(super) fn eval_highlight(
595 &mut self,
596 comp: &Comp,
597 node: &Node,
598 time: f64,
599 frame_i: i64,
600 enc: &mut wgpu::CommandEncoder,
601 visiting: &mut HashSet<(NodeId, i64)>,
602 stats: &mut EvalStats,
603 ) -> CachedTexture {
604 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
605 return self.dummy.clone();
606 };
607 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
608 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
609 let mbm = self.multiplies_by_mask(comp, node, time);
610 if blend <= 1e-6 && !mbm {
611 return src;
612 }
613 let src = self.crop_to_canvas(enc, src);
614
615 let low = comp.eval_number(node, "Low", time, 0.75, &self.expr) as f32;
616 let high = comp.eval_number(node, "High", time, 1.0, &self.expr) as f32;
617 let num_points = comp.eval_number(node, "NumberOfPoints", time, 4.0, &self.expr).clamp(1.0, 16.0) as f32;
618 let angle_deg = comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32;
619 let length_norm = comp.eval_number(node, "Length", time, 0.15, &self.expr).max(0.0) as f32;
620 // Length is normalized to image width; src.size[0] already scales cleanly by proxy_scale.
621 let length_px = (length_norm * src.size[0] as f32).min(256.0);
622 let falloff = self.eval_num_alias(comp, node, "Falloff", "Decay", time, 1.0);
623 let strength = self.eval_num_alias(comp, node, "Strength", "Gain", time, 1.0);
624 let tint_r = self.eval_num_alias(comp, node, "ColorRed", "RedScale", time, 1.0);
625 let tint_g = self.eval_num_alias(comp, node, "ColorGreen", "GreenScale", time, 1.0);
626 let tint_b = self.eval_num_alias(comp, node, "ColorBlue", "BlueScale", time, 1.0);
627 let merge_orig = comp.eval_number(node, "MergeWithOriginal", time, 1.0, &self.expr) > 0.5;
628 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
629 let skip = self.process_skip(comp, node, time);
630 let steps = if self.hiq { 28.0 } else { 14.0 };
631
632 let mut u_ext = UniformParams::default();
633 u_ext.p[0] = [low, high, strength, 0.0];
634
635 let mut u_str = UniformParams::default();
636 u_str.p[0] = [num_points, angle_deg.to_radians(), length_px, falloff];
637 u_str.p[1] = [tint_r, tint_g, tint_b, merge_orig as u8 as f32];
638 u_str.p[2] = [blend, mask.is_some() as u8 as f32, mask_inv as u8 as f32, mbm as u8 as f32];
639 u_str.p[3] = skip;
640 u_str.p[4] = [steps, low, high, strength];
641
642 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
643 let key = self.make_key(
644 node,
645 "Highlight",
646 src.size,
647 &[src.content_hash, mask_hash],
648 bytemuck::cast_slice(&u_str.p[..5]),
649 );
650 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
651 stats.cache_hits += 1;
652 return hit;
653 }
654 stats.cache_misses += 1;
655 stats.nodes_evaluated += 1;
656
657 let bright = self.alloc_tex(src.size, src.depth, 0);
658 let mut dst = self.alloc_tex_like(&src, src.depth, key);
659 if src.aux.is_some() && dst.size == src.size && dst.origin == src.origin {
660 dst.set_aux(src.aux.clone());
661 }
662 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
663 let mut pipes = self.depth_optical_pipelines().borrow_mut();
664 pipes.dispatch(
665 &self.device,
666 &self.queue,
667 enc,
668 DepthOpticalOp::HighlightExtract,
669 &src.view,
670 &self.dummy.view,
671 None,
672 &self.dummy.view,
673 &bright,
674 &u_ext,
675 );
676 pipes.dispatch(
677 &self.device,
678 &self.queue,
679 enc,
680 DepthOpticalOp::HighlightStreaks,
681 &src.view,
682 &bright.view,
683 None,
684 mv,
685 &dst,
686 &u_str,
687 );
688 drop(pipes);
689 self.cache.insert(key, dst.clone(), node.id, frame_i);
690 dst
691 }
692
693 /// 4. `HotSpot`: radial primary glow + optional secondary optical lens flare elements.
694 #[allow(clippy::too_many_arguments)]
695 pub(super) fn eval_hot_spot(
696 &mut self,
697 comp: &Comp,
698 node: &Node,
699 time: f64,
700 frame_i: i64,
701 enc: &mut wgpu::CommandEncoder,
702 visiting: &mut HashSet<(NodeId, i64)>,
703 stats: &mut EvalStats,
704 ) -> CachedTexture {
705 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
706 return self.dummy.clone();
707 };
708 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
709 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
710 let mbm = self.multiplies_by_mask(comp, node, time);
711 if blend <= 1e-6 && !mbm {
712 return src;
713 }
714 let src = self.crop_to_canvas(enc, src);
715
716 let p_center = if node.inputs.contains_key("Center") {
717 comp.eval_point(node, "Center", time, [0.5, 0.5], &self.expr)
718 } else {
719 comp.eval_point(node, "PrimaryPosition", time, [0.5, 0.5], &self.expr)
720 };
721 let default_sec = [1.0 - p_center[0], 1.0 - p_center[1]];
722 let has_explicit_sec = node.inputs.contains_key("SecondaryCenter")
723 || node.inputs.contains_key("SecondaryPosition")
724 || node.inputs.contains_key("SecondaryStrength");
725 let s_center = if node.inputs.contains_key("SecondaryCenter") {
726 comp.eval_point(node, "SecondaryCenter", time, default_sec, &self.expr)
727 } else if node.inputs.contains_key("SecondaryPosition") {
728 comp.eval_point(node, "SecondaryPosition", time, default_sec, &self.expr)
729 } else {
730 default_sec
731 };
732
733 let primary_size = self.eval_num_alias(comp, node, "PrimarySize", "HotSpotSize", time, 0.25);
734 let primary_strength = comp.eval_number(node, "PrimaryStrength", time, 1.0, &self.expr) as f32;
735 let primary_aspect = self.eval_num_alias(comp, node, "PrimaryAspect", "Aspect", time, 1.0);
736 let primary_r = self.eval_num_alias(comp, node, "PrimaryRed", "ColorRed", time, 1.0);
737 let primary_g = self.eval_num_alias(comp, node, "PrimaryGreen", "ColorGreen", time, 1.0);
738 let primary_b = self.eval_num_alias(comp, node, "PrimaryBlue", "ColorBlue", time, 1.0);
739 let default_sec_elems = if has_explicit_sec { 4.0 } else { 0.0 };
740 let sec_elements = self
741 .eval_num_alias(comp, node, "SecondaryElements", "Elements", time, default_sec_elems)
742 .clamp(0.0, 16.0);
743 let sec_strength = comp.eval_number(node, "SecondaryStrength", time, 0.5, &self.expr) as f32;
744 let sec_size = comp.eval_number(node, "SecondarySize", time, (primary_size * 0.45) as f64, &self.expr) as f32;
745 let apply_mode = parse_hotspot_apply_mode(comp, node, time, &self.expr);
746 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
747 let skip = self.process_skip(comp, node, time);
748
749 let mut u = UniformParams::default();
750 u.p[0] = [p_center[0] as f32, p_center[1] as f32, s_center[0] as f32, s_center[1] as f32];
751 u.p[1] = [primary_size, primary_strength, primary_aspect, sec_elements];
752 u.p[2] = [primary_r, primary_g, primary_b, apply_mode as f32];
753 u.p[3] = [sec_strength, sec_size, blend, mask.is_some() as u8 as f32];
754 u.p[4] = [mask_inv as u8 as f32, mbm as u8 as f32, 0.0, 0.0];
755 u.p[5] = skip;
756
757 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
758 let key = self.make_key(
759 node,
760 "HotSpot",
761 src.size,
762 &[src.content_hash, mask_hash],
763 bytemuck::cast_slice(&u.p[..6]),
764 );
765 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
766 stats.cache_hits += 1;
767 return hit;
768 }
769 stats.cache_misses += 1;
770 stats.nodes_evaluated += 1;
771
772 let mut dst = self.alloc_tex_like(&src, src.depth, key);
773 if src.aux.is_some() && dst.size == src.size && dst.origin == src.origin {
774 dst.set_aux(src.aux.clone());
775 }
776 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
777 self.depth_optical_pipelines().borrow_mut().dispatch(
778 &self.device,
779 &self.queue,
780 enc,
781 DepthOpticalOp::HotSpot,
782 &src.view,
783 &self.dummy.view,
784 None,
785 mv,
786 &dst,
787 &u,
788 );
789 self.cache.insert(key, dst.clone(), node.id, frame_i);
790 dst
791 }
792
793 /// 5. `RankFilter`: GPU order-statistic filter (Min / Median / Max / Percentile).
794 #[allow(clippy::too_many_arguments)]
795 pub(super) fn eval_rank_filter(
796 &mut self,
797 comp: &Comp,
798 node: &Node,
799 time: f64,
800 frame_i: i64,
801 enc: &mut wgpu::CommandEncoder,
802 visiting: &mut HashSet<(NodeId, i64)>,
803 stats: &mut EvalStats,
804 ) -> CachedTexture {
805 let Some(src_id) = node.connected_node("Input").and_then(|s| comp.find_node(s)) else {
806 return self.dummy.clone();
807 };
808 let src = self.eval_node(comp, src_id, time, enc, visiting, stats);
809 let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32;
810 let mbm = self.multiplies_by_mask(comp, node, time);
811 let raw_size = self.eval_num_alias(comp, node, "Size", "FilterSize", time, 1.0).max(0.0);
812 let proxy = self.proxy_scale.max(1) as f32;
813 let radius = (raw_size / proxy).round().clamp(0.0, MAX_RANK_RADIUS);
814 let skip = self.combined_skip(comp, node, time);
815 let all_skipped = skip.iter().all(|&s| s > 0.5);
816 if (blend <= 1e-6 || radius < 0.5 || all_skipped) && !mbm {
817 return src;
818 }
819
820 let src = self.crop_to_canvas(enc, src);
821 let rank = comp.eval_number(node, "Rank", time, 0.5, &self.expr).clamp(0.0, 1.0) as f32;
822 let ftype = parse_rank_filter_type(comp, node, time, &self.expr);
823 let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats);
824
825 let mut u = UniformParams::default();
826 u.p[0] = [radius, rank, ftype as f32, 0.0];
827 u.p[1] = [blend, mask.is_some() as u8 as f32, mask_inv as u8 as f32, mbm as u8 as f32];
828 u.p[2] = skip;
829
830 let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash);
831 let key = self.make_key(
832 node,
833 "RankFilter",
834 src.size,
835 &[src.content_hash, mask_hash],
836 bytemuck::cast_slice(&u.p[..3]),
837 );
838 if let Some(hit) = self.cache.get(key, node.id, frame_i) {
839 stats.cache_hits += 1;
840 return hit;
841 }
842 stats.cache_misses += 1;
843 stats.nodes_evaluated += 1;
844
845 let mut dst = self.alloc_tex_like(&src, src.depth, key);
846 if src.aux.is_some() && dst.size == src.size && dst.origin == src.origin {
847 dst.set_aux(src.aux.clone());
848 }
849 let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view);
850 self.depth_optical_pipelines().borrow_mut().dispatch(
851 &self.device,
852 &self.queue,
853 enc,
854 DepthOpticalOp::RankFilter,
855 &src.view,
856 &self.dummy.view,
857 None,
858 mv,
859 &dst,
860 &u,
861 );
862 self.cache.insert(key, dst.clone(), node.id, frame_i);
863 dst
864 }
865}
866
867#[cfg(test)]
868mod tests {
869 use super::*;
870
871 fn px_at(rgba: &[u8], w: u32, x: u32, y: u32) -> [u8; 4] {
872 let i = ((y * w + x) * 4) as usize;
873 [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]]
874 }
875
876 fn eval_px(eng: &mut Engine, comp: &Comp, name: &str) -> (CachedTexture, Vec<u8>) {
877 let id = comp.find_node(name).unwrap_or_else(|| panic!("missing node {name}"));
878 let (tex, stats) = eng.evaluate(comp, id, 0.0);
879 assert!(stats.unsupported_nodes.is_empty(), "unexpected unsupported: {:?}", stats.unsupported_nodes);
880 let rgba = eng.readback_rgba(&tex).expect("readback rgba");
881 (tex, rgba)
882 }
883
884 fn z_bg_nodes(prefix: &str, w: u32, h: u32, rgba: [f32; 4], z: f32) -> String {
885 format!(
886 r#"
887 {prefix}Col = Background {{
888 Inputs = {{
889 Width = Input {{ Value = {w}, }}, Height = Input {{ Value = {h}, }}, Depth = Input {{ Value = 4, }},
890 TopLeftRed = Input {{ Value = {}, }}, TopLeftGreen = Input {{ Value = {}, }},
891 TopLeftBlue = Input {{ Value = {}, }}, TopLeftAlpha = Input {{ Value = {}, }},
892 }},
893 }},
894 {prefix}Z = Background {{
895 Inputs = {{
896 Width = Input {{ Value = {w}, }}, Height = Input {{ Value = {h}, }}, Depth = Input {{ Value = 4, }},
897 TopLeftRed = Input {{ Value = {z}, }}, TopLeftAlpha = Input {{ Value = 1.0, }},
898 }},
899 }},
900 {prefix}ZAux = Dimension.CopyAux {{
901 Inputs = {{
902 Mode = Input {{ Value = 1, }},
903 Channel = Input {{ Value = FuID {{ "Z" }}, }},
904 Input = Input {{ SourceOp = "{prefix}Z", Source = "Output", }},
905 }},
906 }},
907 {prefix} = ChannelBoolean {{
908 Inputs = {{
909 ToRed = Input {{ Value = 5, }}, ToGreen = Input {{ Value = 6, }},
910 ToBlue = Input {{ Value = 7, }}, ToAlpha = Input {{ Value = 8, }},
911 EnableExtraChannels = Input {{ Value = 1, }}, ToZBuffer = Input {{ Value = 18, }},
912 Background = Input {{ SourceOp = "{prefix}Col", Source = "Output", }},
913 Foreground = Input {{ SourceOp = "{prefix}ZAux", Source = "Output", }},
914 }},
915 }},
916 "#,
917 rgba[0], rgba[1], rgba[2], rgba[3]
918 )
919 }
920
921 #[test]
922 fn depth_blur_aux_z_focal_sharp_far_and_sky_blurred() {
923 let Ok(mut eng) = Engine::new_headless() else { return };
924 // 64x64 sharp vertical stripe across two depth layers:
925 // top half (y<32 in texture = Fusion Y>0.5) has focal z=-5.0, bottom half has far z=-25.0.
926 let src = format!(
927 r#"Composition {{
928 CurrentTime = 0, RenderRange = {{ 0, 0 }}, GlobalRange = {{ 0, 0 }},
929 Tools = ordered() {{
930 {}
931 {}
932 MTop = RectangleMask {{
933 Inputs = {{ Center = Input {{ Value = {{ 0.5, 0.75 }}, }}, Width = Input {{ Value = 1.0, }}, Height = Input {{ Value = 0.5, }}, }},
934 }},
935 MStripe = RectangleMask {{
936 Inputs = {{ Center = Input {{ Value = {{ 0.5, 0.5 }}, }}, Width = Input {{ Value = 0.125, }}, Height = Input {{ Value = 1.0, }}, }},
937 }},
938 White = Background {{
939 Inputs = {{ Width = Input {{ Value = 64, }}, Height = Input {{ Value = 64, }},
940 TopLeftRed = Input {{ Value = 1.0, }}, TopLeftGreen = Input {{ Value = 1.0, }}, TopLeftBlue = Input {{ Value = 1.0, }},
941 EffectMask = Input {{ SourceOp = "MStripe", Source = "Mask", }}, }},
942 }},
943 Black = Background {{ Inputs = {{ Width = Input {{ Value = 64, }}, Height = Input {{ Value = 64, }}, }}, }},
944 Striped = Merge {{
945 Inputs = {{ Background = Input {{ SourceOp = "Black", Source = "Output", }}, Foreground = Input {{ SourceOp = "White", Source = "Output", }}, }},
946 }},
947 DepthSplit = Merge {{
948 Inputs = {{
949 Background = Input {{ SourceOp = "FarZ", Source = "Output", }},
950 Foreground = Input {{ SourceOp = "NearZ", Source = "Output", }},
951 EffectMask = Input {{ SourceOp = "MTop", Source = "Mask", }},
952 PerformDepthMerge = Input {{ Value = 1, }},
953 }},
954 }},
955 Scene = ChannelBoolean {{
956 Inputs = {{
957 ToRed = Input {{ Value = 5, }}, ToGreen = Input {{ Value = 6, }},
958 ToBlue = Input {{ Value = 7, }}, ToAlpha = Input {{ Value = 8, }},
959 EnableExtraChannels = Input {{ Value = 1, }}, ToZBuffer = Input {{ Value = 18, }},
960 Background = Input {{ SourceOp = "Striped", Source = "Output", }},
961 Foreground = Input {{ SourceOp = "DepthSplit", Source = "Output", }},
962 }},
963 }},
964 DB = DepthBlur {{
965 Inputs = {{
966 Input = Input {{ SourceOp = "Scene", Source = "Output", }},
967 XBlurSize = Input {{ Value = 60.0, }},
968 FocalPoint = Input {{ Value = -5.0, }},
969 DepthOfField = Input {{ Value = 1.0, }},
970 ZScale = Input {{ Value = 20.0, }},
971 }},
972 }},
973 }},
974 }}"#,
975 z_bg_nodes("NearZ", 64, 64, [0.0, 0.0, 0.0, 1.0], -5.0),
976 z_bg_nodes("FarZ", 64, 64, [0.0, 0.0, 0.0, 1.0], -25.0),
977 );
978 let comp = Comp::from_fusion_str(&src).expect("parse DepthBlur aux.z comp");
979 let (tex, px) = eval_px(&mut eng, &comp, "DB");
980 assert!(tex.aux.as_ref().and_then(|a| a.z.as_ref()).is_some(), "DepthBlur must preserve aux.z");
981
982 // Stripe occupies x in [28..36]; check 2px outside stripe edge (x=25):
983 // Near row (y=12) is at focal plane -> stays black (0); Far row (y=52) is out of focus -> blurred (>15)!
984 let near_outside = px_at(&px, 64, 25, 12)[0];
985 let far_outside = px_at(&px, 64, 25, 52)[0];
986 let near_inside = px_at(&px, 64, 32, 12)[0];
987 let far_inside = px_at(&px, 64, 32, 52)[0];
988 assert!(near_outside <= 2, "focal plane outside stripe must stay sharp black, got {near_outside}");
989 assert!(near_inside >= 250, "focal plane inside stripe must stay crisp white, got {near_inside}");
990 assert!(far_outside >= 15, "far depth outside stripe must receive blur bleed, got {far_outside}");
991 assert!(far_inside < near_inside, "far depth inside stripe must soften ({far_inside} vs {near_inside})");
992
993 // Verify EMPTY_Z_SENTINEL (-1e30) in aux.z is treated as far background (full CoC blur).
994 let sky_src = format!(
995 r#"Composition {{
996 CurrentTime = 0, RenderRange = {{ 0, 0 }}, GlobalRange = {{ 0, 0 }},
997 Tools = ordered() {{
998 {}
999 MStripe = RectangleMask {{ Inputs = {{ Center = Input {{ Value = {{ 0.5, 0.5 }}, }}, Width = Input {{ Value = 0.125, }}, Height = Input {{ Value = 1.0, }}, }}, }},
1000 Black = Background {{ Inputs = {{ Width = Input {{ Value = 64, }}, Height = Input {{ Value = 64, }}, }}, }},
1001 White = Background {{ Inputs = {{ Width = Input {{ Value = 64, }}, Height = Input {{ Value = 64, }},
1002 TopLeftRed = Input {{ Value = 1.0, }}, TopLeftGreen = Input {{ Value = 1.0, }}, TopLeftBlue = Input {{ Value = 1.0, }},
1003 EffectMask = Input {{ SourceOp = "MStripe", Source = "Mask", }}, }}, }},
1004 Striped = Merge {{ Inputs = {{ Background = Input {{ SourceOp = "Black", Source = "Output", }}, Foreground = Input {{ SourceOp = "White", Source = "Output", }}, }}, }},
1005 Scene = ChannelBoolean {{
1006 Inputs = {{
1007 ToRed = Input {{ Value = 5, }}, ToGreen = Input {{ Value = 6, }},
1008 ToBlue = Input {{ Value = 7, }}, ToAlpha = Input {{ Value = 8, }},
1009 EnableExtraChannels = Input {{ Value = 1, }}, ToZBuffer = Input {{ Value = 18, }},
1010 Background = Input {{ SourceOp = "Striped", Source = "Output", }},
1011 Foreground = Input {{ SourceOp = "SkyZ", Source = "Output", }},
1012 }},
1013 }},
1014 DB = DepthBlur {{
1015 Inputs = {{
1016 Input = Input {{ SourceOp = "Scene", Source = "Output", }},
1017 XBlurSize = Input {{ Value = 60.0, }},
1018 FocalPoint = Input {{ Value = -5.0, }},
1019 ZScale = Input {{ Value = 20.0, }},
1020 }},
1021 }},
1022 }},
1023 }}"#,
1024 z_bg_nodes("SkyZ", 64, 64, [0.0, 0.0, 0.0, 1.0], EMPTY_Z_SENTINEL),
1025 );
1026 let sky_comp = Comp::from_fusion_str(&sky_src).expect("parse DepthBlur sky comp");
1027 let (_, sky_px) = eval_px(&mut eng, &sky_comp, "DB");
1028 assert!(px_at(&sky_px, 64, 25, 32)[0] >= 15, "EMPTY_Z_SENTINEL sky must blur as far background");
1029 }
1030
1031 #[test]
1032 fn depth_blur_external_blur_image_and_proxy_scale() {
1033 let Ok(mut eng) = Engine::new_headless() else { return };
1034 // BlurImage has black top half (depth=0, sharp) and white bottom half (depth=1, blurred).
1035 let src = r#"Composition {
1036 CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 },
1037 Tools = ordered() {
1038 MStripe = RectangleMask { Inputs = { Center = Input { Value = { 0.5, 0.5 }, }, Width = Input { Value = 0.125, }, Height = Input { Value = 1.0, }, }, },
1039 Black = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, }, }, },
1040 Stripe = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, },
1041 TopLeftRed = Input { Value = 1.0, }, TopLeftGreen = Input { Value = 1.0, }, TopLeftBlue = Input { Value = 1.0, },
1042 EffectMask = Input { SourceOp = "MStripe", Source = "Mask", }, }, },
1043 Img = Merge { Inputs = { Background = Input { SourceOp = "Black", Source = "Output", }, Foreground = Input { SourceOp = "Stripe", Source = "Output", }, }, },
1044 MBot = RectangleMask { Inputs = { Center = Input { Value = { 0.5, 0.25 }, }, Width = Input { Value = 1.0, }, Height = Input { Value = 0.5, }, }, },
1045 DepthMap = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, },
1046 TopLeftRed = Input { Value = 1.0, }, TopLeftGreen = Input { Value = 1.0, }, TopLeftBlue = Input { Value = 1.0, },
1047 EffectMask = Input { SourceOp = "MBot", Source = "Mask", }, }, },
1048 DB = DepthBlur {
1049 Inputs = {
1050 Input = Input { SourceOp = "Img", Source = "Output", },
1051 BlurImage = Input { SourceOp = "DepthMap", Source = "Output", },
1052 BlurChannel = Input { Value = 5, },
1053 Filter = Input { Value = 1, },
1054 BlurSize = Input { Value = 72.0, },
1055 FocalPoint = Input { Value = 0.0, },
1056 ZScale = Input { Value = 1.0, },
1057 },
1058 },
1059 },
1060 }"#;
1061 let comp = Comp::from_fusion_str(src).expect("parse DepthBlur BlurImage comp");
1062 let (_, px) = eval_px(&mut eng, &comp, "DB");
1063 assert!(px_at(&px, 64, 24, 12)[0] <= 2, "top half depth=0 must stay sharp");
1064 assert!(px_at(&px, 64, 24, 52)[0] >= 15, "bottom half depth=1 must blur");
1065
1066 eng.proxy_scale = 2;
1067 let (tex_p, px_p) = eval_px(&mut eng, &comp, "DB");
1068 assert_eq!(tex_p.size, [32, 32]);
1069 assert!(px_at(&px_p, 32, 12, 6)[0] <= 2, "proxy top half must stay sharp");
1070 assert!(px_at(&px_p, 32, 12, 26)[0] >= 15, "proxy bottom half must blur");
1071 }
1072
1073 #[test]
1074 fn fog_aux_z_near_far_falloff_alpha_and_fog_image() {
1075 let Ok(mut eng) = Engine::new_headless() else { return };
1076 // Left=near(-2, red), Middle=mid(-16, green), Right=far(-30, blue).
1077 let src = format!(
1078 r#"Composition {{
1079 CurrentTime = 0, RenderRange = {{ 0, 0 }}, GlobalRange = {{ 0, 0 }},
1080 Tools = ordered() {{
1081 {}
1082 {}
1083 {}
1084 MLeft = RectangleMask {{ Inputs = {{ Center = Input {{ Value = {{ 0.16, 0.5 }}, }}, Width = Input {{ Value = 0.34, }}, Height = Input {{ Value = 1.0, }}, }}, }},
1085 MMid = RectangleMask {{ Inputs = {{ Center = Input {{ Value = {{ 0.5, 0.5 }}, }}, Width = Input {{ Value = 0.34, }}, Height = Input {{ Value = 1.0, }}, }}, }},
1086 M1 = Merge {{ Inputs = {{ Background = Input {{ SourceOp = "Far", Source = "Output", }}, Foreground = Input {{ SourceOp = "Mid", Source = "Output", }}, EffectMask = Input {{ SourceOp = "MMid", Source = "Mask", }}, PerformDepthMerge = Input {{ Value = 1, }}, }}, }},
1087 Scene = Merge {{ Inputs = {{ Background = Input {{ SourceOp = "M1", Source = "Output", }}, Foreground = Input {{ SourceOp = "Near", Source = "Output", }}, EffectMask = Input {{ SourceOp = "MLeft", Source = "Mask", }}, PerformDepthMerge = Input {{ Value = 1, }}, }}, }},
1088 FogSolid = Fog {{
1089 Inputs = {{
1090 Input = Input {{ SourceOp = "Scene", Source = "Output", }},
1091 ZNearPlane = Input {{ Value = -2.0, }},
1092 ZFarPlane = Input {{ Value = -30.0, }},
1093 Falloff = Input {{ Value = 1.0, }},
1094 FogRed = Input {{ Value = 1.0, }}, FogGreen = Input {{ Value = 1.0, }}, FogBlue = Input {{ Value = 1.0, }},
1095 }},
1096 }},
1097 TintImg = Background {{ Inputs = {{ Width = Input {{ Value = 32, }}, Height = Input {{ Value = 32, }},
1098 TopLeftRed = Input {{ Value = 0.0, }}, TopLeftGreen = Input {{ Value = 1.0, }}, TopLeftBlue = Input {{ Value = 1.0, }}, }}, }},
1099 FogTex = Fog {{
1100 Inputs = {{
1101 Input = Input {{ SourceOp = "Scene", Source = "Output", }},
1102 FogImage = Input {{ SourceOp = "TintImg", Source = "Output", }},
1103 NearPlane = Input {{ Value = -2.0, }},
1104 FarPlane = Input {{ Value = -30.0, }},
1105 }},
1106 }},
1107 EmptySky = Background {{ Inputs = {{ Width = Input {{ Value = 16, }}, Height = Input {{ Value = 16, }}, TopLeftAlpha = Input {{ Value = 0.0, }}, }}, }},
1108 FogSkyZeroA = Fog {{ Inputs = {{ Input = Input {{ SourceOp = "EmptySky", Source = "Output", }}, FogAlpha = Input {{ Value = 0.0, }}, }}, }},
1109 FogSkyFullA = Fog {{ Inputs = {{ Input = Input {{ SourceOp = "EmptySky", Source = "Output", }}, FogAlpha = Input {{ Value = 1.0, }}, FogRed = Input {{ Value = 0.5, }}, FogGreen = Input {{ Value = 0.5, }}, FogBlue = Input {{ Value = 0.5, }}, }}, }},
1110 }},
1111 }}"#,
1112 z_bg_nodes("Near", 32, 32, [1.0, 0.0, 0.0, 1.0], -2.0),
1113 z_bg_nodes("Mid", 32, 32, [0.0, 1.0, 0.0, 1.0], -16.0),
1114 z_bg_nodes("Far", 32, 32, [0.0, 0.0, 1.0, 1.0], -30.0),
1115 );
1116 let comp = Comp::from_fusion_str(&src).expect("parse Fog comp");
1117 let (tex, px) = eval_px(&mut eng, &comp, "FogSolid");
1118 assert!(tex.aux.as_ref().and_then(|a| a.z.as_ref()).is_some(), "Fog must preserve aux.z for chaining");
1119
1120 let near_c = px_at(&px, 32, 4, 16);
1121 let mid_c = px_at(&px, 32, 16, 16);
1122 let far_c = px_at(&px, 32, 28, 16);
1123 assert!(near_c[0] >= 250 && near_c[1] <= 3 && near_c[2] <= 3, "near plane must have 0% fog, got {near_c:?}");
1124 assert!((mid_c[0] as i32 - 128).abs() <= 6 && mid_c[1] >= 250, "mid plane must have ~50% white fog on green, got {mid_c:?}");
1125 assert!(far_c[0] >= 250 && far_c[1] >= 250 && far_c[2] >= 250, "far plane must have 100% white fog, got {far_c:?}");
1126
1127 let (_, px_t) = eval_px(&mut eng, &comp, "FogTex");
1128 let far_t = px_at(&px_t, 32, 28, 16);
1129 assert!(far_t[0] <= 3 && far_t[1] >= 250 && far_t[2] >= 250, "FogImage cyan must tint far fog, got {far_t:?}");
1130
1131 let (_, sky0) = eval_px(&mut eng, &comp, "FogSkyZeroA");
1132 assert_eq!(px_at(&sky0, 16, 8, 8)[3], 0, "FogAlpha=0 must keep empty sky transparent");
1133 let (_, sky1) = eval_px(&mut eng, &comp, "FogSkyFullA");
1134 assert!(px_at(&sky1, 16, 8, 8)[3] >= 250 && (px_at(&sky1, 16, 8, 8)[0] as i32 - 128).abs() <= 4);
1135 }
1136
1137 #[test]
1138 fn highlight_thresholds_and_casts_directional_streaks() {
1139 let Ok(mut eng) = Engine::new_headless() else { return };
1140 let src = r#"Composition {
1141 CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 },
1142 Tools = ordered() {
1143 Bg = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, }, }, },
1144 MBright = RectangleMask { Inputs = { Center = Input { Value = { 0.5, 0.5 }, }, Width = Input { Value = 0.08, }, Height = Input { Value = 0.08, }, }, },
1145 MDim = RectangleMask { Inputs = { Center = Input { Value = { 0.15, 0.15 }, }, Width = Input { Value = 0.1, }, Height = Input { Value = 0.1, }, }, },
1146 Bright = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, },
1147 TopLeftRed = Input { Value = 1.0, }, TopLeftGreen = Input { Value = 1.0, }, TopLeftBlue = Input { Value = 1.0, },
1148 EffectMask = Input { SourceOp = "MBright", Source = "Mask", }, }, },
1149 Dim = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, },
1150 TopLeftRed = Input { Value = 0.3, }, TopLeftGreen = Input { Value = 0.3, }, TopLeftBlue = Input { Value = 0.3, },
1151 EffectMask = Input { SourceOp = "MDim", Source = "Mask", }, }, },
1152 M1 = Merge { Inputs = { Background = Input { SourceOp = "Bg", Source = "Output", }, Foreground = Input { SourceOp = "Dim", Source = "Output", }, }, },
1153 Scene = Merge { Inputs = { Background = Input { SourceOp = "M1", Source = "Output", }, Foreground = Input { SourceOp = "Bright", Source = "Output", }, }, },
1154 HL = Highlight {
1155 Inputs = {
1156 Input = Input { SourceOp = "Scene", Source = "Output", },
1157 Low = Input { Value = 0.6, }, High = Input { Value = 0.9, },
1158 NumberOfPoints = Input { Value = 4, }, Angle = Input { Value = 0.0, },
1159 Length = Input { Value = 0.25, }, Falloff = Input { Value = 1.0, },
1160 ColorRed = Input { Value = 1.0, }, ColorGreen = Input { Value = 0.5, }, ColorBlue = Input { Value = 0.2, },
1161 MergeWithOriginal = Input { Value = 1, },
1162 },
1163 },
1164 HLOnly = Highlight {
1165 Inputs = {
1166 Input = Input { SourceOp = "Scene", Source = "Output", },
1167 Low = Input { Value = 0.6, }, High = Input { Value = 0.9, },
1168 NumberOfPoints = Input { Value = 4, }, Length = Input { Value = 0.25, },
1169 MergeWithOriginal = Input { Value = 0, },
1170 },
1171 },
1172 },
1173 }"#;
1174 let comp = Comp::from_fusion_str(src).expect("parse Highlight comp");
1175 let (_, px) = eval_px(&mut eng, &comp, "HL");
1176 // Along +X ray from center (32,32): (40,32) must receive warm tinted streak (R > G > B > 0).
1177 let ray_x = px_at(&px, 64, 40, 32);
1178 let ray_y = px_at(&px, 64, 32, 40);
1179 let off_diag = px_at(&px, 64, 44, 44);
1180 assert!(ray_x[0] >= 20 && ray_x[0] > ray_x[1] && ray_x[1] > ray_x[2], "X ray must glow warm, got {ray_x:?}");
1181 assert!(ray_y[0] >= 20, "Y ray must glow for 4-point star, got {ray_y:?}");
1182 assert!(off_diag[0] <= 2, "off-ray diagonal must stay dark, got {off_diag:?}");
1183
1184 // MergeWithOriginal=0 must drop the dim patch (lum=0.3 < Low=0.6).
1185 let (_, px_only) = eval_px(&mut eng, &comp, "HLOnly");
1186 let dim_px = px_at(&px_only, 64, 10, 54);
1187 assert!(dim_px[0] <= 2 && dim_px[1] <= 2 && dim_px[2] <= 2, "dim spot below Low must not highlight, got {dim_px:?}");
1188
1189 eng.proxy_scale = 2;
1190 let (tex_p, px_p) = eval_px(&mut eng, &comp, "HL");
1191 assert_eq!(tex_p.size, [32, 32]);
1192 assert!(px_at(&px_p, 32, 20, 16)[0] >= 15, "proxy Highlight must scale streaks cleanly");
1193 }
1194
1195 #[test]
1196 fn hot_spot_primary_secondary_apply_mode_and_mask() {
1197 let Ok(mut eng) = Engine::new_headless() else { return };
1198 let src = r#"Composition {
1199 CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 },
1200 Tools = ordered() {
1201 Bg = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, },
1202 TopLeftRed = Input { Value = 0.05, }, TopLeftGreen = Input { Value = 0.05, }, TopLeftBlue = Input { Value = 0.05, }, }, },
1203 HS = HotSpot {
1204 Inputs = {
1205 Input = Input { SourceOp = "Bg", Source = "Output", },
1206 Center = Input { Value = { 0.25, 0.25 }, },
1207 SecondaryCenter = Input { Value = { 0.75, 0.75 }, },
1208 PrimarySize = Input { Value = 0.14, },
1209 PrimaryStrength = Input { Value = 1.0, },
1210 PrimaryRed = Input { Value = 1.0, }, PrimaryGreen = Input { Value = 0.5, }, PrimaryBlue = Input { Value = 0.2, },
1211 SecondaryElements = Input { Value = 4, },
1212 ApplyMode = Input { Value = FuID { "Add" }, },
1213 },
1214 },
1215 MLeft = RectangleMask { Inputs = { Center = Input { Value = { 0.25, 0.5 }, }, Width = Input { Value = 0.5, }, Height = Input { Value = 1.0, }, }, },
1216 HSMasked = HotSpot {
1217 Inputs = {
1218 Input = Input { SourceOp = "Bg", Source = "Output", },
1219 Center = Input { Value = { 0.75, 0.5 }, },
1220 PrimarySize = Input { Value = 0.2, },
1221 EffectMask = Input { SourceOp = "MLeft", Source = "Mask", },
1222 },
1223 },
1224 },
1225 }"#;
1226 let comp = Comp::from_fusion_str(src).expect("parse HotSpot comp");
1227 let (_, px) = eval_px(&mut eng, &comp, "HS");
1228 // Primary at Fusion (0.25, 0.25) -> texture pixel (16, 48)
1229 let primary = px_at(&px, 64, 16, 48);
1230 assert!(primary[0] >= 240 && primary[0] > primary[1] && primary[1] > primary[2], "primary core must be bright warm, got {primary:?}");
1231
1232 // Sample along secondary axis (0.5..0.85, 0.5..0.85) vs far off-axis corner (0.85, 0.15 -> px 54, 54).
1233 let mut max_axis = 0u8;
1234 for step in 32..56 {
1235 let y = 63 - step;
1236 let p = px_at(&px, 64, step, y);
1237 max_axis = max_axis.max(p[0]).max(p[1]).max(p[2]);
1238 }
1239 let off_corner = px_at(&px, 64, 56, 56);
1240 assert!(max_axis > off_corner[0] + 20, "secondary elements must brighten optical axis ({max_axis} vs {off_corner:?})");
1241
1242 let (_, px_m) = eval_px(&mut eng, &comp, "HSMasked");
1243 // Center of flare is at x=48 (outside left-half mask) -> must remain background (~13).
1244 assert!(px_at(&px_m, 64, 48, 32)[0] <= 16, "EffectMask must block HotSpot outside mask");
1245 }
1246
1247 #[test]
1248 fn rank_filter_min_median_max_filter_type_channels_and_proxy() {
1249 let Ok(mut eng) = Engine::new_headless() else { return };
1250 // 32x32 mid-gray (0.5) field with a 1px white impulse at center (16,16).
1251 let src = r#"Composition {
1252 CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 },
1253 Tools = ordered() {
1254 Gray = Background { Inputs = { Width = Input { Value = 32, }, Height = Input { Value = 32, },
1255 TopLeftRed = Input { Value = 0.5, }, TopLeftGreen = Input { Value = 0.5, }, TopLeftBlue = Input { Value = 0.5, }, }, },
1256 DotMask = RectangleMask { Inputs = { Center = Input { Value = { 0.515625, 0.484375 }, }, Width = Input { Value = 0.03125, }, Height = Input { Value = 0.03125, }, }, },
1257 White = Background { Inputs = { Width = Input { Value = 32, }, Height = Input { Value = 32, },
1258 TopLeftRed = Input { Value = 1.0, }, TopLeftGreen = Input { Value = 1.0, }, TopLeftBlue = Input { Value = 1.0, },
1259 EffectMask = Input { SourceOp = "DotMask", Source = "Mask", }, }, },
1260 Scene = Merge { Inputs = { Background = Input { SourceOp = "Gray", Source = "Output", }, Foreground = Input { SourceOp = "White", Source = "Output", }, }, },
1261 RMin = RankFilter { Inputs = { Input = Input { SourceOp = "Scene", Source = "Output", }, Size = Input { Value = 1, }, Rank = Input { Value = 0.0, }, }, },
1262 RMed = RankFilter { Inputs = { Input = Input { SourceOp = "Scene", Source = "Output", }, Size = Input { Value = 1, }, Rank = Input { Value = 0.5, }, }, },
1263 RPct = RankFilter { Inputs = { Input = Input { SourceOp = "Scene", Source = "Output", }, Size = Input { Value = 1, }, Rank = Input { Value = 0.9375, }, }, },
1264 RMaxBox = RankFilter { Inputs = { Input = Input { SourceOp = "Scene", Source = "Output", }, Size = Input { Value = 1, }, Rank = Input { Value = 1.0, }, FilterType = Input { Value = 0, }, }, },
1265 RMaxCir = RankFilter { Inputs = { Input = Input { SourceOp = "Scene", Source = "Output", }, Size = Input { Value = 1, }, Rank = Input { Value = 1.0, }, FilterType = Input { Value = 1, }, }, },
1266 RSkipR = RankFilter { Inputs = { Input = Input { SourceOp = "Scene", Source = "Output", }, Size = Input { Value = 1, }, Rank = Input { Value = 1.0, }, ProcessRed = Input { Value = 0, }, }, },
1267 RBig = RankFilter { Inputs = { Input = Input { SourceOp = "Scene", Source = "Output", }, FilterSize = Input { Value = 4, }, Rank = Input { Value = 1.0, }, }, },
1268 },
1269 }"#;
1270 let comp = Comp::from_fusion_str(src).expect("parse RankFilter comp");
1271 let (_, scene_px) = eval_px(&mut eng, &comp, "Scene");
1272 assert!(px_at(&scene_px, 32, 16, 16)[0] >= 250, "sanity: center impulse must be white");
1273
1274 let (_, min_px) = eval_px(&mut eng, &comp, "RMin");
1275 assert!((px_at(&min_px, 32, 16, 16)[0] as i32 - 128).abs() <= 4, "Min must erode 1px white impulse to 0.5");
1276
1277 let (_, med_px) = eval_px(&mut eng, &comp, "RMed");
1278 assert!((px_at(&med_px, 32, 16, 16)[0] as i32 - 128).abs() <= 4, "Median must remove 1px white impulse");
1279
1280 // In 3x3 (9 samples: eight 0.5 + one 1.0), Rank=0.9375 -> pos = 7.5 -> midpoint between 0.5 and 1.0 (~0.75 = 191)!
1281 let (_, pct_px) = eval_px(&mut eng, &comp, "RPct");
1282 assert!((px_at(&pct_px, 32, 16, 16)[0] as i32 - 191).abs() <= 4, "Percentile rank=0.9375 must interpolate to ~191, got {:?}", px_at(&pct_px, 32, 16, 16));
1283
1284 let (_, box_px) = eval_px(&mut eng, &comp, "RMaxBox");
1285 assert!(px_at(&box_px, 32, 17, 17)[0] >= 250, "Max Box(r=1) must dilate impulse to diagonal corner (17,17)");
1286
1287 let (_, cir_px) = eval_px(&mut eng, &comp, "RMaxCir");
1288 assert!(px_at(&cir_px, 32, 17, 16)[0] >= 250, "Max Circle(r=1) must dilate impulse to cardinal neighbor");
1289 assert!((px_at(&cir_px, 32, 17, 17)[0] as i32 - 128).abs() <= 4, "Max Circle(r=1) must exclude diagonal corner");
1290
1291 let (_, skip_px) = eval_px(&mut eng, &comp, "RSkipR");
1292 let n_px = px_at(&skip_px, 32, 17, 16);
1293 assert!((n_px[0] as i32 - 128).abs() <= 4 && n_px[1] >= 250, "ProcessRed=0 must skip R while filtering G: {n_px:?}");
1294
1295 eng.proxy_scale = 2;
1296 let (tex_p, _) = eval_px(&mut eng, &comp, "RBig");
1297 assert_eq!(tex_p.size, [16, 16]);
1298 }
1299
1300 #[test]
1301 fn uniform_ring_growth_reset_trim_and_hdr_float16() {
1302 let Ok(mut eng) = Engine::new_headless() else { return };
1303 {
1304 let mut pipes = eng.depth_optical_pipelines().borrow_mut();
1305 let u = UniformParams::default();
1306 for _ in 0..520 {
1307 pipes.alloc_uniform_slot(&eng.device, &eng.queue, &u);
1308 }
1309 assert_eq!(pipes.uniform_chunks.len(), 2, "520 slots must allocate 2x512 chunks");
1310 pipes.reset_uniform_cursor();
1311 assert_eq!(pipes.uniform_cursor, 0);
1312 pipes.trim_uniform_chunks(1);
1313 assert_eq!(pipes.uniform_chunks.len(), 1);
1314 }
1315
1316 // Verify Float16 HDR compilation & execution across all 5 ops.
1317 let src = r#"Composition {
1318 CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 },
1319 Tools = ordered() {
1320 Bg = Background { Inputs = { Width = Input { Value = 16, }, Height = Input { Value = 16, }, Depth = Input { Value = 3, },
1321 TopLeftRed = Input { Value = 0.8, }, TopLeftGreen = Input { Value = 0.4, }, TopLeftBlue = Input { Value = 0.2, }, }, },
1322 F = Fog { Inputs = { Input = Input { SourceOp = "Bg", Source = "Output", }, FogOpacity = Input { Value = 0.25, }, }, },
1323 H = Highlight { Inputs = { Input = Input { SourceOp = "F", Source = "Output", }, Low = Input { Value = 0.3, }, }, },
1324 S = HotSpot { Inputs = { Input = Input { SourceOp = "H", Source = "Output", }, PrimarySize = Input { Value = 0.3, }, }, },
1325 R = RankFilter { Inputs = { Input = Input { SourceOp = "S", Source = "Output", }, Size = Input { Value = 1, }, Rank = Input { Value = 0.5, }, }, },
1326 D = DepthBlur { Inputs = { Input = Input { SourceOp = "R", Source = "Output", }, BlurChannel = Input { Value = 5, }, BlurSize = Input { Value = 16.0, }, }, },
1327 },
1328 }"#;
1329 let comp = Comp::from_fusion_str(src).expect("parse HDR chain");
1330 let (tex, _) = eval_px(&mut eng, &comp, "D");
1331 assert_eq!(tex.depth, BitDepth::Float16);
1332 }
1333}