diff --git a/crates/bake/src/tests.rs b/crates/bake/src/tests.rs index bb75353e..aaa855f6 100644 --- a/crates/bake/src/tests.rs +++ b/crates/bake/src/tests.rs @@ -565,6 +565,25 @@ fn a_high_poly_box_has_bright_edges_and_flat_faces() { } } +#[test] +fn default_curvature_brightens_box_edges_and_never_darkens_them() { + let mut bake_settings = settings(256, &[BakedMap::Curvature]); + bake_settings.cage = CageSettings { max_frontal: 0.06, max_rear: 0.02, ..bake_settings.cage }; + bake_settings.maps.curvature.parameters.method = CurvatureMethod::default(); + + // A box has no concave texel, whether it is baked from itself or from a beveled high poly + let low = primitives::cube(2.0); + let high = primitives::rounded_box(Vec3::ONE, 0.15); + let bakes = [("itself", run(&low, &bake_settings).unwrap()), ("a beveled high poly", transfer(&low, &high, None, &bake_settings).unwrap())]; + for (source, bake_output) in bakes { + let curvature = covered_values(&low, &bake_output, BakedMap::Curvature); + let darkest = curvature.iter().map(|(_, value)| *value).fold(1.0, f32::min); + let brightest = curvature.iter().map(|(_, value)| *value).fold(0.0, f32::max); + assert!(darkest > 0.45, "baked from {source}, darkest {darkest}"); + assert!(brightest > 0.6, "baked from {source}, brightest {brightest}"); + } +} + #[test] fn a_narrow_high_poly_bevel_stays_bright() { let s = { diff --git a/crates/core/src/bake/curvature_method.rs b/crates/core/src/bake/curvature_method.rs index 2085c85b..32ac645b 100644 --- a/crates/core/src/bake/curvature_method.rs +++ b/crates/core/src/bake/curvature_method.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub enum CurvatureMethod { - #[default] NormalMap, + #[default] Mesh, } diff --git a/crates/core/src/bake/curvature_settings.rs b/crates/core/src/bake/curvature_settings.rs index d67138b8..66b4e732 100644 --- a/crates/core/src/bake/curvature_settings.rs +++ b/crates/core/src/bake/curvature_settings.rs @@ -1,16 +1,10 @@ use super::{CurvatureMethod, MeshCurvatureSettings, NormalMapCurvatureSettings}; use serde::{Deserialize, Serialize}; -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)] #[serde(default)] pub struct CurvatureSettings { pub method: CurvatureMethod, pub normal_map: NormalMapCurvatureSettings, pub mesh: MeshCurvatureSettings, } - -impl Default for CurvatureSettings { - fn default() -> Self { - Self { method: CurvatureMethod::NormalMap, normal_map: NormalMapCurvatureSettings::default(), mesh: MeshCurvatureSettings::default() } - } -} diff --git a/crates/core/tests/bake_settings.rs b/crates/core/tests/bake_settings.rs index 708560f0..800efd98 100644 --- a/crates/core/tests/bake_settings.rs +++ b/crates/core/tests/bake_settings.rs @@ -20,7 +20,7 @@ fn reference_defaults_cover_common_and_per_map_settings() { "id": {"source": "MaterialColor", "generator": "HueShift"}, "ao": {"rays": rays, "ignore_backface": "Never", "self_occlusion": "Always", "attenuation": "Linear", "ground_plane": {"enabled": false, "offset": 0.0}}, "curvature": { - "method": "NormalMap", + "method": "Mesh", "normal_map": {"details": 0.5, "enable_seams": true, "seams_intensity": 1.0}, "mesh": {"rays": 32, "sampling_radius": 0.001, "relative_to_bounding_box": true, "self_intersection": "Always", "auto_tonemapping": true, "value_min": -1.0, "value_max": 1.0} }, @@ -54,7 +54,9 @@ fn reference_defaults_cover_common_and_per_map_settings() { } } } + assert_shape(&serde_json::to_value(decoded).unwrap(), &expected); + assert_eq!(BakedMap::ALL.len(), 10); for name in ["color_map", "Color map", "WorldDirection", "world_space_direction"] { assert_eq!(BakedMap::parse(name), None); diff --git a/crates/ui-egui/tests/bake_mode.rs b/crates/ui-egui/tests/bake_mode.rs index 88a7c1f2..1b330244 100644 --- a/crates/ui-egui/tests/bake_mode.rs +++ b/crates/ui-egui/tests/bake_mode.rs @@ -434,39 +434,48 @@ fn check_all_enables_every_map_then_disables_them_all() { #[test] fn the_breadcrumb_switches_the_shown_map() { let mut harness = harness(Some(BakedMap::Curvature)); - harness.get_by_label("Details"); + harness.get_by_label("Sampling Radius"); assert_eq!(harness.get_all_by_role_and_label(Role::Button, "Position").count(), 1, "only the list row before the menu opens"); + let dropdowns: Vec<_> = harness.get_all_by_label(egui_phosphor::regular::CARET_RIGHT).collect(); let [_texture_set_dropdown, map_dropdown] = dropdowns.as_slice() else { panic!("the breadcrumb has a texture set and a map dropdown") }; map_dropdown.click(); harness.run_steps(3); assert_eq!(harness.get_all_by_role_and_label(Role::Button, "Position").count(), 2, "the map menu lists Position"); + // The menu draws its items after the list rows harness.get_all_by_role_and_label(Role::Button, "Position").last().unwrap().click(); harness.run_steps(3); harness.get_by_label("Normalization Scale"); - assert!(harness.query_by_label("Details").is_none()); + assert!(harness.query_by_label("Sampling Radius").is_none()); assert_eq!(enabled_maps(&harness), [BakedMap::Curvature]); } #[test] fn curvature_controls_follow_the_method_and_notes_visibility_rules() { let mut harness = harness(Some(BakedMap::Curvature)); - harness.get_by_label("Details"); - harness.get_by_label("Seams Intensity"); - click(&mut harness, "Enable Seams"); - assert!(harness.query_by_label("Seams Intensity").is_none()); - click(&mut harness, "Method"); - click(&mut harness, "Generate from Mesh"); - assert_eq!(harness.state().session.doc.project.texture_sets[0].bake.maps.curvature.parameters.method, CurvatureMethod::Mesh); + let curvature = |harness: &Harness<'_, TextureCraftApp>| harness.state().session.doc.project.texture_sets[0].bake.maps.curvature.parameters; + + assert_eq!(curvature(&harness).method, CurvatureMethod::Mesh); assert!(harness.query_by_label("Details").is_none()); harness.get_by_label("Sampling Radius"); assert!(harness.query_by_label("Value Bounds Min").is_none()); assert!(harness.query_by_label("Value Bounds Max").is_none()); + click(&mut harness, "Auto Tonemapping"); harness.get_by_label("Value Bounds Min"); harness.get_by_label("Value Bounds Max"); - assert!(!harness.state().session.doc.project.texture_sets[0].bake.maps.curvature.parameters.mesh.auto_tonemapping); + assert!(!curvature(&harness).mesh.auto_tonemapping); + + click(&mut harness, "Method"); + click(&mut harness, "Generate from Normal Map"); + assert_eq!(curvature(&harness).method, CurvatureMethod::NormalMap); + assert!(harness.query_by_label("Sampling Radius").is_none()); + harness.get_by_label("Details"); + + harness.get_by_label("Seams Intensity"); + click(&mut harness, "Enable Seams"); + assert!(harness.query_by_label("Seams Intensity").is_none()); } #[test]