transparent roughness and diffuse settings from app

This commit is contained in:
zomseffen 2025-02-03 12:42:56 +01:00
parent fbc21ba523
commit 1ecd1c7403
7 changed files with 39 additions and 17 deletions

View file

@ -50,9 +50,9 @@ impl EmptyVolume {
self.position[2] + self.size_z > pos[2] && pos[2] >= self.position[2]
}
fn check_transparent(cube_result: Option<Cube>, transparent_color: &Vector3<f32>) -> bool {
fn check_transparent(cube_result: Option<Cube>, transparent_color: &Vector3<f32>, transparent_roughness: &u8) -> bool {
if let Some(c) = cube_result {
return c.transparent && &c.color == transparent_color
return c.transparent && &c.color == transparent_color && &c.roughness == transparent_roughness
}
false
}
@ -73,9 +73,11 @@ impl EmptyVolume {
let query_result = tree.test_element(x_index, y_index, z_index);
let mut transparent = false;
let mut transparent_color = Vector3 {x: 0.0, y: 0.0, z: 0.0};
let mut tranparent_roughness = 0;
if let Some(c) = query_result.3 {
transparent = c.transparent;
transparent_color = c.color;
tranparent_roughness = c.roughness;
}
if !query_result.0 || transparent {
@ -112,7 +114,7 @@ impl EmptyVolume {
while z < z_size.max(1) && y < y_size.max(1) {
let query_result = tree.test_element(x_index + x_size + 1, y_index + y, z_index + z);
check_its += 1;
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color))) &&
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color, &tranparent_roughness))) &&
neighbors.get_element(x_index + x_size + 1, y_index + y, z_index + z).is_none();
if query_result.1 > 1 {
@ -159,7 +161,7 @@ impl EmptyVolume {
while z < z_size.max(1) && x < x_size.max(1) {
let query_result = tree.test_element(x_index + x, y_index + y_size + 1, z_index + z);
check_its += 1;
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color))) &&
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color, &tranparent_roughness))) &&
neighbors.get_element(x_index + x, y_index + y_size + 1, z_index + z).is_none();
if query_result.1 > 1 {
@ -207,7 +209,7 @@ impl EmptyVolume {
while y < y_size.max(1) && x < x_size.max(1) {
let query_result = tree.test_element(x_index + x, y_index + y, z_index + z_size + 1);
check_its += 1;
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color))) &&
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color, &tranparent_roughness))) &&
neighbors.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none();
if query_result.1 > 1 {
@ -323,7 +325,7 @@ impl EmptyVolume {
bottom_elements_num += 1;
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
bottom_colors.push(u8_color);
bottom_roughness.push(128);
bottom_roughness.push(c.roughness);
}
else {
bottom_colors.push(Vector3 { x: 0, y: 0, z: 0 });
@ -349,7 +351,7 @@ impl EmptyVolume {
top_elements_num += 1;
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
top_colors.push(u8_color);
top_roughness.push(128);
top_roughness.push(c.roughness);
}
else {
top_colors.push(Vector3 { x: 0, y: 0, z: 0 });
@ -376,7 +378,7 @@ impl EmptyVolume {
back_elements_num += 1;
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
back_colors.push(u8_color);
back_roughness.push(128);
back_roughness.push(c.roughness);
}
else {
back_colors.push(Vector3 { x: 0, y: 0, z: 0 });
@ -403,7 +405,7 @@ impl EmptyVolume {
front_elements_num += 1;
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
front_colors.push(u8_color);
front_roughness.push(128);
front_roughness.push(c.roughness);
}
else {
front_colors.push(Vector3 { x: 0, y: 0, z: 0 });
@ -430,7 +432,7 @@ impl EmptyVolume {
left_elements_num += 1;
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
left_colors.push(u8_color);
left_roughness.push(128);
left_roughness.push(c.roughness);
}
else {
left_colors.push(Vector3 { x: 0, y: 0, z: 0 });
@ -457,7 +459,7 @@ impl EmptyVolume {
right_elements_num += 1;
let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
right_colors.push(u8_color);
right_roughness.push(128);
right_roughness.push(c.roughness);
}
else {
right_colors.push(Vector3 { x: 0, y: 0, z: 0 });