use crate::{
geometry::{cuts::StandardGemCuts, tool::ToolPrimitive},
optics::{
fluorescence::Fluorescence,
materials::GemMaterial,
raytracer::{BACKDROP_GREY, Camera, LightingPreset, build_plane_soa},
},
renderer::{cpu_frame::trace_pixels_interleaved_geom, frame_scene::FrameScene},
};
use glam::Vec3;
const SIZE: u32 = 48;
const SPP: u32 = 48;
fn dimple_and_tunnel() -> [ToolPrimitive; 2] {
[
ToolPrimitive::ball(Vec3::new(0.25, 0.32, 0.1), 0.22),
ToolPrimitive::cylinder(
Vec3::new(-0.3, 0.2, -0.2),
Vec3::new(1.0, 0.0, 0.2).normalize(),
0.08,
0.5,
),
]
}
#[test]
fn a_dimple_and_tunnel_trace_without_losing_track_of_the_medium() {
let planes = StandardGemCuts::standard_round_brilliant();
let soa = build_plane_soa(&planes);
let material = GemMaterial::by_name("Diamond").expect("Diamond is a built-in material");
let camera = Camera::new(0.35, 0.28, 5.0, 18.0);
let scene = FrameScene {
camera: &camera,
width: SIZE,
height: SIZE,
planes: &planes,
facet_finishes: &[],
material: &material,
max_bounces: 8,
environment: LightingPreset::LightTent
.studio(1.0, 0.4, 0.35)
.with_backdrop(BACKDROP_GREY),
};
let tools = dimple_and_tunnel();
let cut =
trace_pixels_interleaved_geom(&scene, &tools, Fluorescence::none(), &soa, 0, 1, 0, SPP);
let flat = trace_pixels_interleaved_geom(&scene, &[], Fluorescence::none(), &soa, 0, 1, 0, SPP);
assert_eq!(cut.len(), (SIZE * SIZE) as usize);
assert!(cut.iter().all(|p| p.is_finite()), "a non-finite pixel");
assert_ne!(
cut.iter().map(|p| p.y).sum::<f32>().to_bits(),
flat.iter().map(|p| p.y).sum::<f32>().to_bits(),
"the dimple and tunnel must show in the picture"
);
}