mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-24 08:20:46 +01:00
Auto: Integrate main, fix orthographic visibility, trim UI tests
Reject orthographic paint points on or behind the eye plane, with regression coverage preserving near-eye and nonfinite fallbacks. Remove three UI anchor-picker tests. Integrate main's no-op tile-free sharing optimization, copy-on-write regression tests, clearer benchmark fixtures and architecture documentation, and adapter-tolerant sheen and refraction assertions.
This commit is contained in:
1 parent
31904e08a3
commit
1b5d9bd16c
2 files changed
+41
-77
No files matched your search
@@ -117,7 +117,16 @@ fn ray_reaches_eye(context: &RasterCtx, depth: &EyeDepth, point: Vec3, geometric
|
||||
let direction = depth.orthographic_to_eye.unwrap_or(to_eye);
|
||||
let eye_distance = (context.eye - point).dot(direction);
|
||||
let lift = depth.bias * RAY_START_PER_BIAS;
|
||||
if !eye_distance.is_finite() || lift >= eye_distance {
|
||||
if !eye_distance.is_finite() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Orthographic points on or behind the eye plane cannot be visible
|
||||
if eye_distance <= 0.0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
if lift >= eye_distance {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -458,6 +467,37 @@ mod tests {
|
||||
assert!(!ray_reaches_eye(&context, &depth, point, Vec3::Z, to_eye));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orthographic_ray_rejects_points_on_or_behind_the_eye_plane() {
|
||||
let mesh = primitives::plane(2.0, 8);
|
||||
let camera = texturecraft_geom::OrbitCamera { ortho: true, ..Default::default() };
|
||||
let bvh = Bvh::new(&mesh);
|
||||
let gbuf = UvGBuffer::new(&mesh, 0, 4, 4);
|
||||
let mut depth = EyeDepth::render(&mesh, &camera, 4, 4);
|
||||
depth.dist.fill(0.1);
|
||||
depth.dist[10] = f32::MAX;
|
||||
let context = RasterCtx {
|
||||
mesh: &mesh,
|
||||
bvh: &bvh,
|
||||
gbuf: &gbuf,
|
||||
material: 0,
|
||||
depth: Some(&depth),
|
||||
eye: camera.eye(),
|
||||
backface_culling: false,
|
||||
angle_fade: (89.0, 90.0),
|
||||
shape: Shape { alpha: crate::BrushAlpha::Round, image: None, library: None, level: 0 },
|
||||
};
|
||||
let to_eye = -camera.forward();
|
||||
let behind = context.eye + to_eye;
|
||||
let near = context.eye - to_eye * (depth.bias * RAY_START_PER_BIAS * 0.5);
|
||||
|
||||
assert_eq!(depth.visibility(behind), (false, true), "the uncertain depth reaches the exact ray fallback");
|
||||
assert!(!surface_visible(&context, &depth, behind, to_eye, to_eye, 0.0, 0.0));
|
||||
assert!(!ray_reaches_eye(&context, &depth, context.eye, to_eye, to_eye));
|
||||
assert!(ray_reaches_eye(&context, &depth, near, to_eye, to_eye), "the existing near-eye fallback remains accepted");
|
||||
assert!(ray_reaches_eye(&context, &depth, Vec3::splat(f32::NAN), to_eye, to_eye), "nonfinite input retains its fallback");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orthographic_stamps_do_not_paint_behind_an_off_axis_shelf() {
|
||||
let floor = [Vec3::new(-2.0, 0.0, -2.0), Vec3::new(2.0, 0.0, -2.0), Vec3::new(2.0, 0.0, 2.0), Vec3::new(-2.0, 0.0, 2.0)];
|
||||
|
||||
@@ -2250,82 +2250,6 @@ pub(crate) fn anchor_label(app: &TextureCraftApp, anchor: LayerId, channel: Chan
|
||||
if mask_anchor_enabled(app, anchor) == Some(false) { format!("{label} ({})", tr("Off")) } else { label }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod mask_anchor_label_tests {
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_engine::core::{Channel, LayerId};
|
||||
use texturecraft_engine::execute;
|
||||
|
||||
use super::{anchor_label, anchors_below, effect_anchors_below};
|
||||
use crate::TextureCraftApp;
|
||||
|
||||
#[test]
|
||||
fn disabled_mask_anchors_keep_their_selection_and_show_off() {
|
||||
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
let lower = execute(&mut session, "layer.add.fill", &Value::Null).unwrap()["layer"].as_u64().unwrap();
|
||||
execute(&mut session, "mask.add.black", &json!({"layer": lower})).unwrap();
|
||||
let anchor = execute(&mut session, "effect.add.anchor", &json!({"layer": lower, "target": "mask"})).unwrap()["effect"].as_u64().unwrap();
|
||||
let upper = execute(&mut session, "layer.add.fill", &Value::Null).unwrap()["layer"].as_u64().unwrap();
|
||||
execute(&mut session, "mask.toggle", &json!({"layer": lower, "enabled": false})).unwrap();
|
||||
|
||||
let mut harness = Harness::builder().build_eframe(|context| TextureCraftApp::new(context, session));
|
||||
let labels = anchors_below(harness.state(), LayerId(upper));
|
||||
assert!(labels.iter().any(|(id, label)| *id == LayerId(anchor) && label.contains("(Off)")));
|
||||
assert!(anchor_label(harness.state(), LayerId(anchor), Channel::Height).contains("(Off)"));
|
||||
|
||||
execute(&mut harness.state_mut().session, "mask.toggle", &json!({"layer": lower, "enabled": true})).unwrap();
|
||||
let labels = anchors_below(harness.state(), LayerId(upper));
|
||||
assert!(labels.iter().any(|(id, label)| *id == LayerId(anchor) && !label.contains("(Off)")));
|
||||
assert!(!anchor_label(harness.state(), LayerId(anchor), Channel::Height).contains("(Off)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inherited_effect_pickers_list_anchors_below_the_owner() {
|
||||
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
let lower = execute(&mut session, "layer.add.fill", &Value::Null).unwrap()["layer"].as_u64().unwrap();
|
||||
let valid = execute(&mut session, "effect.add.anchor", &json!({"layer": lower})).unwrap()["effect"].as_u64().unwrap();
|
||||
let source = execute(&mut session, "layer.add.fill", &Value::Null).unwrap()["layer"].as_u64().unwrap();
|
||||
execute(&mut session, "mask.add.black", &json!({"layer": source})).unwrap();
|
||||
let fill = execute(&mut session, "effect.add.fill", &json!({"layer": source})).unwrap()["effect"].as_u64().unwrap();
|
||||
let generator = execute(&mut session, "effect.add.generator", &json!({"layer": source})).unwrap()["effect"].as_u64().unwrap();
|
||||
let middle = execute(&mut session, "layer.add.fill", &Value::Null).unwrap()["layer"].as_u64().unwrap();
|
||||
let invalid = execute(&mut session, "effect.add.anchor", &json!({"layer": middle})).unwrap()["effect"].as_u64().unwrap();
|
||||
let instance = execute(&mut session, "layer.instance", &json!({"layer": source})).unwrap()["layer"].as_u64().unwrap();
|
||||
|
||||
assert!(execute(&mut session, "effect.set", &json!({"effect": fill, "anchor": invalid})).is_err());
|
||||
assert!(execute(&mut session, "effect.set", &json!({"effect": generator, "microAnchor": invalid})).is_err());
|
||||
|
||||
let harness = Harness::builder().build_eframe(|context| TextureCraftApp::new(context, session));
|
||||
assert!(anchors_below(harness.state(), LayerId(instance)).iter().any(|(id, _)| *id == LayerId(invalid)));
|
||||
for effect in [fill, generator] {
|
||||
let choices = effect_anchors_below(harness.state(), LayerId(instance), LayerId(effect));
|
||||
assert!(choices.iter().any(|(id, _)| *id == LayerId(valid)));
|
||||
assert!(!choices.iter().any(|(id, _)| *id == LayerId(invalid)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inherited_effect_pickers_hide_unrecorded_source_set_anchors() {
|
||||
let mesh = texturecraft_engine::geom::primitives::material_ball();
|
||||
let mut session = texturecraft_engine::Session::new_project("test", mesh, "builtin:material_ball", None, 256).unwrap();
|
||||
let lower = execute(&mut session, "layer.add.fill", &Value::Null).unwrap()["layer"].as_u64().unwrap();
|
||||
let anchor = execute(&mut session, "effect.add.anchor", &json!({"layer": lower})).unwrap()["effect"].as_u64().unwrap();
|
||||
let source = execute(&mut session, "layer.add.fill", &Value::Null).unwrap()["layer"].as_u64().unwrap();
|
||||
execute(&mut session, "mask.add.black", &json!({"layer": source})).unwrap();
|
||||
let fill = execute(&mut session, "effect.add.fill", &json!({"layer": source, "anchor": anchor})).unwrap()["effect"].as_u64().unwrap();
|
||||
let generator = execute(&mut session, "effect.add.generator", &json!({"layer": source, "microAnchor": anchor})).unwrap()["effect"].as_u64().unwrap();
|
||||
let instance = execute(&mut session, "layer.instance", &json!({"layer": source, "ts": 1})).unwrap()["layer"].as_u64().unwrap();
|
||||
|
||||
let harness = Harness::builder().build_eframe(|context| TextureCraftApp::new(context, session));
|
||||
assert!(anchors_below(harness.state(), LayerId(instance)).is_empty());
|
||||
for effect in [fill, generator] {
|
||||
let choices = effect_anchors_below(harness.state(), LayerId(instance), LayerId(effect));
|
||||
assert!(choices.is_empty(), "source-set anchor {anchor} is not recorded for the instance");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Space above a fill's Material caption, setting it apart from the projection
|
||||
const FILL_MATERIAL_GAP: f32 = 6.0;
|
||||
|
||||
|
||||
Reference in new issue
Block a user