From 3f199ce4a6c6a52e95df1cf315d012907df2bb38 Mon Sep 17 00:00:00 2001
From: zomseffen <steffen@tom.bi>
Date: Mon, 7 Apr 2025 11:28:20 +0200
Subject: [PATCH] fix indexing of cubes

---
 shaders/compiled/rt_compute.spv | Bin 26056 -> 25952 bytes
 shaders/rt_compute.comp         |  11 +++--------
 src/command_buffer.rs           |   2 +-
 src/scene/generators.rs         |   6 ++++++
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/shaders/compiled/rt_compute.spv b/shaders/compiled/rt_compute.spv
index 77f16d8e5aba464425329d106c1bd374233df40b..39f83f37be61949f1a0159340e64cc0a7ecb48bc 100644
GIT binary patch
delta 1165
zcmZ9LO=}ZT7=`c5WRifS27;{+Tht=hR)wy_7KN<Ze;{3y5;Y2?<An5Mo2vCAHEQET
ztyU0sZd^z<ZrzFEf6(9I#`Da~wbM+P-1nUKyr0Sa{?qyW!zp?0WWgB695W^JzE`^L
zmd%&jTe;ffoH5OMs~#9*e3LUzhVbqX?jFGf(~p+?>czfTo*=x{Sksx;2hNdwrx6A#
zt#AW>UN!pBN52wBcw(BZa5eEH5hS`<4;rodN;6z1f*ODPYU#CHn>RvbD46|d+^<&m
z)2dtH+GfyLm&Y^j5^mt-PdH1FKwb&UdKWdEZPSmjT1gX33iB+|Udm}(N8%Xee_Zsf
zP+7JE4lCWPQrW;%*w$++zzxT-j>8JG#Y&qBu!qW|KU$1?R#P@3k#J>k3yLC^DhryM
z)t!~iWAT{;#`ul=?1{YOOBXwr6p4epn4}pJu;pw*FbPS3|6uUB_&3)cli3qjN?j*~
zUkbw^J*98^8+Fv|gek^-qshL<rA2pI`d2!ci}~hL%zSX;n%mAYVZ6(6&kzK@O+^ex
zAeg=hyrA*VYq$g9jyt$Ja><?LX0Uj)BRaVm7W0SVW@K@9@T>e`tX<RoW|Zol+|xSe
zB)zH>?DxJnc#9v%UY2G@G5B|c(ZE~HL)p91Y^Rz>!sy_yX<pidL$5urnvOtS0XXRy
zjFTlkl^vx%`UhLzGufX~AGaKQML!7pc`kcYC&kD~Y&WV+&76Ay%Cxs93^%Hm4)E<o
My{XEeJpFb4AChQ;aR2}S

delta 1283
zcmZ9L&2JJ>6vf{F15FH-q$!xxHc}RfH70IMnnsf@4BfcZRc$aGwWfp$p)RRfKUze^
zQR_#Qx-o8C7<MM^jmG~${|k*9&u^GVfg!`Y=iGBY-hK0aeRsb7aFWqTE@6yg4w$5Q
z-%4JL80Yhq_1OHqm@#X`O0i^&aZSwJAHrKhxG{herse;1C$cTEJnQAvTFI*_Q`Gn&
z=bD7s^(Wnl@!gOqm6yF$spI<X`sdwD9#4e$74If_;>rLQmAzIeU+;3Ln{FnD#}!qp
zdP`Tma%ri0t+?z}f~xQ2t6eU4qVaL3{zM=yp%$|sw{0^=K0O5$fTK)7Dq5ZnJo`8+
zOg#QKGRT+GyC7^gL^I^KILv>1fYkU00v+LApnoGVwn#Yau#(C2l+u7Hv7y(Ng&U4z
zTfI2{cVcXX3b6aiZquTJjFh(-iKI$O9D^d3Dhz@tPs`@9INOB*-s^lC`4_8CD$Jh2
zlx$`VKB5#)!*p<SA!h!R$OylZos_M`9Mb=58F1jk`nPAXrGP0j610b=?=6^v5+kJG
zTdgE#9~1<$54ag&4z?}K3{D6g)1dZ*+p*52(UXx=+!W?U?5I|5ip6{o+?0OY=zLAJ
zGxalJ>RWOjRZ5F*3oi<9>WC<PM;Hyf)ojY%mS!W=+!aO#e^&FPB{=lV>VfQ{^!R8`
z_(I@h4%;I9&`Gag0`WbR{W0`$!@;u}Dzj<IPHUwYNr`Rv=khc4N3#0cdn^o>)=LZc
z;QlI4L-rr7O|5o&&*bYL$@37;YanTrejz+7{b^OlXXAEc%a=1&_)-Ml4nmSr9BwDp
J`H=rI_a8M+kOlw%

diff --git a/shaders/rt_compute.comp b/shaders/rt_compute.comp
index e51587a..7ec8245 100644
--- a/shaders/rt_compute.comp
+++ b/shaders/rt_compute.comp
@@ -26,7 +26,7 @@ layout(binding = 6) buffer Indices {
    uint indices[];
 };
 
-layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
+layout (local_size_x = 16, local_size_y = 1, local_size_z = 1) in;
 
 uvec4 unpack_color(uint val) {
     // left most 8 bits first
@@ -241,14 +241,9 @@ void main() {
         }
 
         if (render) {
-            add_cube(index * compound_grid_size + z, compound_scale, check_pos, color);
+            add_cube(gl_GlobalInvocationID.x * compound_grid_size + z, compound_scale, check_pos, color);
         }
-
-
     }
 
-    //add_cube(0, compound_scale, compound_pos + mid_offset, vec3(1.0, 0.0, 0.0));
-    //add_cube(1, compound_scale, compound_pos + vec3(float(compound_grid_size) * compound_scale, float(compound_grid_size) * compound_scale, float(compound_grid_size) * compound_scale) + mid_offset, vec3(1.0, 0.0, 0.0));
-
-    volumes[index] = compounds[index];
+    //volumes[index] = compounds[index];
 }
\ No newline at end of file
diff --git a/src/command_buffer.rs b/src/command_buffer.rs
index 00159eb..583f1e9 100644
--- a/src/command_buffer.rs
+++ b/src/command_buffer.rs
@@ -70,7 +70,7 @@ pub unsafe fn create_command_buffers(device: &Device, data: &mut app_data::AppDa
                 &[data.descriptor_sets[i]],
                  &[]);
             
-            device.cmd_dispatch(*command_buffer, (data.compute_task_one_size as f64 / 256.0).ceil() as u32, 1, 1);
+            device.cmd_dispatch(*command_buffer, (data.compute_task_one_size as f64 / 16.0).ceil() as u32, 1, 1);
 
             let buffer_memory_barrier_vertex = vk::BufferMemoryBarrier::builder()
                 .buffer(data.compute_out_cuboid_buffers[i])
diff --git a/src/scene/generators.rs b/src/scene/generators.rs
index 8e185e5..32f107e 100644
--- a/src/scene/generators.rs
+++ b/src/scene/generators.rs
@@ -124,6 +124,12 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<(Poi
     comp.excluded_shapes.push(Rc::new(RefCell::new(Sphere::new(Vector3 { x: 5.0 + grid_size as f32, y: 5.0 + grid_size as f32, z: 11.5 }, Vector3 { x: 0.0, y: 0.0, z: 0.0 }, 1.5, Vector3 { x: 0, y: 255, z: 0 }, 64, false))));    
     scene.volumetrics.push(Rc::new(RefCell::new(comp)));
 
+    let mut comp = ShapeComposition::new(64);
+    comp.included_shapes.push(Rc::new(RefCell::new(Sphere::new(Vector3 { x: 20.0 + grid_size as f32, y: 5.0 + grid_size as f32, z: 10.0 }, Vector3 { x: 0.0, y: 0.0, z: 0.0 }, 2.0, Vector3 { x: 0, y: 255, z: 0 }, 64, false))));
+    comp.included_shapes.push(Rc::new(RefCell::new(Sphere::new(Vector3 { x: 20.0 + grid_size as f32, y: 5.0 + grid_size as f32, z: 10.0 }, Vector3 { x: 0.0, y: 0.0, z: 0.0 }, 2.5, Vector3 { x: 255, y: 0, z: 0 }, 64, false))));
+    comp.excluded_shapes.push(Rc::new(RefCell::new(Sphere::new(Vector3 { x: 20.0 + grid_size as f32, y: 5.0 + grid_size as f32, z: 11.5 }, Vector3 { x: 0.0, y: 0.0, z: 0.0 }, 1.5, Vector3 { x: 0, y: 255, z: 0 }, 64, false))));    
+    scene.volumetrics.push(Rc::new(RefCell::new(comp)));
+
     Ok((cgmath::point3(5.0, 5.0, 10.0)))
 }