From d58edc41272c73617899e20f8c604c21e09e9a39 Mon Sep 17 00:00:00 2001 From: Schmarni Date: Wed, 29 Jan 2025 21:46:56 +0100 Subject: [PATCH] fix: incorrect material batching Signed-off-by: Schmarni --- src/nodes/drawable/model.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/nodes/drawable/model.rs b/src/nodes/drawable/model.rs index 3e98179..02a7cc4 100644 --- a/src/nodes/drawable/model.rs +++ b/src/nodes/drawable/model.rs @@ -26,7 +26,8 @@ impl Hash for MaterialWrapper { fn hash(&self, state: &mut H) { self.0.get_shader().0.as_ptr().hash(state); for param in self.0.get_all_param_info() { - param.to_string().hash(state) + param.name.hash(state); + param.to_string().hash(state); } self.0.get_chain().map(MaterialWrapper).hash(state) } @@ -59,7 +60,7 @@ unsafe impl Send for MaterialWrapper {} unsafe impl Sync for MaterialWrapper {} #[derive(Default)] -struct MaterialRegistry(Mutex>); +struct MaterialRegistry(Mutex>>); impl MaterialRegistry { fn add_or_get(&self, material: Arc) -> Arc { let mut lock = self.0.lock(); @@ -70,13 +71,11 @@ impl MaterialRegistry { hasher.finish() }; - if let Some(id) = lock.get(&hash) { - if let Ok(existing) = Material::find(id) { - return Arc::new(MaterialWrapper(existing)); - } + if let Some(mat) = lock.get(&hash) { + return mat.clone(); } - lock.insert(hash, material.0.get_id().to_string()); + lock.insert(hash, material.clone()); material } }