Compare commits

..

No commits in common. "master" and "volumetrics" have entirely different histories.

32 changed files with 329 additions and 687 deletions

2
.gitignore vendored
View file

@ -1,3 +1 @@
/target
src/test_oct_shader.rs
oct_tree_dump.json

27
Cargo.lock generated
View file

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
version = 3
[[package]]
name = "ab_glyph"
@ -533,12 +533,6 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jni"
version = "0.21.1"
@ -1015,12 +1009,6 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
[[package]]
name = "ryu"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "same-file"
version = "1.0.6"
@ -1069,18 +1057,6 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.141"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
]
[[package]]
name = "shlex"
version = "1.3.0"
@ -1292,7 +1268,6 @@ dependencies = [
"rand",
"rustc-hash",
"serde",
"serde_json",
"thiserror",
"tobj",
"vulkanalia",

View file

@ -16,6 +16,5 @@ tobj = { version = "3", features = ["log"] }
vulkanalia = { version = "=0.23.0", features = ["libloading", "provisional", "window"] }
winit = "0.29"
serde = { version = "1.0", features = ["derive"] }
serde_json = "*"
rand = "0.8"
rustc-hash = "*"

View file

@ -3,7 +3,7 @@ use std::io::{self, Write};
use std::path::Path;
use std::fs::File;
use std::io::{BufReader, BufRead};
use std::io::{BufReader, BufRead, Error};
fn insert_place_holders(path: &str) {
let input = File::open(path).unwrap();
@ -41,7 +41,6 @@ fn main() {
println!("cargo::rerun-if-changed=shaders/rt_quad_placeholder.frag");
println!("cargo::rerun-if-changed=shaders/rt_compute_rasterize.comp");
println!("cargo::rerun-if-changed=shaders/rt_compute_visible.comp");
println!("cargo::rerun-if-changed=shaders/rt_compute_grow_one.comp");
println!("cargo::rerun-if-changed=shaders/rt_compute_grow_two.comp");
println!("cargo::rerun-if-changed=shaders/rt_compute_grow_three.comp");
@ -62,7 +61,6 @@ fn main() {
std::fs::remove_file("shaders/compiled/vert_rt_quad.spv").unwrap_or(());
std::fs::remove_file("shaders/compiled/frag_rt_quad.spv").unwrap_or(());
std::fs::remove_file("shaders/compiled/rt_compute_rasterize.spv").unwrap_or(());
std::fs::remove_file("shaders/compiled/rt_compute_visible.spv").unwrap_or(());
std::fs::remove_file("shaders/compiled/rt_compute_grow_one.spv").unwrap_or(());
std::fs::remove_file("shaders/compiled/rt_compute_grow_two.spv").unwrap_or(());
std::fs::remove_file("shaders/compiled/rt_compute_grow_three.spv").unwrap_or(());

View file

@ -13,7 +13,6 @@ C:/VulkanSDK/1.3.280.0/Bin/glslc.exe shaders/rt_quad.vert -o shaders/compiled/ve
C:/VulkanSDK/1.3.280.0/Bin/glslc.exe shaders/rt_quad.frag -o shaders/compiled/frag_rt_quad.spv
C:/VulkanSDK/1.3.280.0/Bin/glslc.exe shaders/rt_compute_rasterize.comp -o shaders/compiled/rt_compute_rasterize.spv
C:/VulkanSDK/1.3.280.0/Bin/glslc.exe shaders/rt_compute_visible.comp -o shaders/compiled/rt_compute_visible.spv
C:/VulkanSDK/1.3.280.0/Bin/glslc.exe shaders/rt_compute_grow_one.comp -o shaders/compiled/rt_compute_grow_one.spv
C:/VulkanSDK/1.3.280.0/Bin/glslc.exe shaders/rt_compute_grow_two.comp -o shaders/compiled/rt_compute_grow_two.spv
C:/VulkanSDK/1.3.280.0/Bin/glslc.exe shaders/rt_compute_grow_three.comp -o shaders/compiled/rt_compute_grow_three.spv

View file

@ -14,7 +14,6 @@ glslc shaders/rt_quad.vert -o shaders/compiled/vert_rt_quad.spv
glslc shaders/rt_quad.frag -o shaders/compiled/frag_rt_quad.spv
glslc shaders/rt_compute_rasterize.comp -o shaders/compiled/rt_compute_rasterize.spv
glslc shaders/rt_compute_visible.comp -o shaders/compiled/rt_compute_visible.spv
glslc shaders/rt_compute_grow_one.comp -o shaders/compiled/rt_compute_grow_one.spv
glslc shaders/rt_compute_grow_two.comp -o shaders/compiled/rt_compute_grow_two.spv
glslc shaders/rt_compute_grow_three.comp -o shaders/compiled/rt_compute_grow_three.spv

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -67,199 +67,158 @@ vec3 unpack_color(uint val) {
return vec3(val4 / 255.0, val3 / 255.0, val2 / 255.0);
}
bool is_side_visible(uint x, uint y, uint z, uint compound_grid_size, uint input_offset, int dx, int dy, int dz) {
return (
(x == 0 && dx < 0) || (x == compound_grid_size - 1 && dx > 0) ||
(y == 0 && dy < 0) || (y == compound_grid_size - 1 && dy > 0) ||
(z == 0 && dz < 0) || (z == compound_grid_size - 1 && dz > 0)
) ||
(transparent_grid[input_offset + (x + dx) * compound_grid_size * compound_grid_size + (y + dy) * compound_grid_size + (z + dz)] &&
(!transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z] ||
transparent_grid[input_offset + (x + dx) * compound_grid_size * compound_grid_size + (y + dy) * compound_grid_size + (z + dz)] && grid_in[input_offset + (x + dx) * compound_grid_size * compound_grid_size + (y + dy) * compound_grid_size + (z + dz)] != grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z])
);
}
void add_cube(uint cube_num, float scale, vec3 pos, uint color, uint start_volume, bool transparent, uvec3 grid_pos, uint compound_grid_size, uint input_offset) {
void add_cube(uint cube_num, float scale, vec3 pos, uint color, uint start_volume) {
// add node info for the cube
uint vertex_size = 7;
//vertice 0
vertices[(cube_num * 8 + 0) * vertex_size + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 0) * vertex_size + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 0) * vertex_size + 2] = pos.z + 0.5 * scale;
vertices[(cube_num * 8 + 0) * 6 + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 0) * 6 + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 0) * 6 + 2] = pos.z + 0.5 * scale;
//volume
vertices[(cube_num * 8 + 0) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 0) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 0) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 0) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 0) * vertex_size + 5] = uintBitsToFloat(6);
// flags, first bit is transparency
vertices[(cube_num * 8 + 0) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 0) * 6 + 5] = uintBitsToFloat(6);
//vertice 1
vertices[(cube_num * 8 + 1) * vertex_size + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 1) * vertex_size + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 1) * vertex_size + 2] = pos.z + 0.5 * scale;
vertices[(cube_num * 8 + 1) * 6 + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 1) * 6 + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 1) * 6 + 2] = pos.z + 0.5 * scale;
//volume
vertices[(cube_num * 8 + 1) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 1) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 1) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 1) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 1) * vertex_size + 5] = uintBitsToFloat(4);
// flags, first bit is transparency
vertices[(cube_num * 8 + 1) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 1) * 6 + 5] = uintBitsToFloat(4);
//vertice 2
vertices[(cube_num * 8 + 2) * vertex_size + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 2) * vertex_size + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 2) * vertex_size + 2] = pos.z + 0.5 * scale;
vertices[(cube_num * 8 + 2) * 6 + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 2) * 6 + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 2) * 6 + 2] = pos.z + 0.5 * scale;
//volume
vertices[(cube_num * 8 + 2) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 2) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 2) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 2) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 2) * vertex_size + 5] = uintBitsToFloat(3);
// flags, first bit is transparency
vertices[(cube_num * 8 + 2) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 2) * 6 + 5] = uintBitsToFloat(3);
//vertice 3
vertices[(cube_num * 8 + 3) * vertex_size + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 3) * vertex_size + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 3) * vertex_size + 2] = pos.z + 0.5 * scale;
vertices[(cube_num * 8 + 3) * 6 + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 3) * 6 + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 3) * 6 + 2] = pos.z + 0.5 * scale;
//volume
vertices[(cube_num * 8 + 3) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 3) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 3) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 3) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 3) * vertex_size + 5] = uintBitsToFloat(1);
// flags, first bit is transparency
vertices[(cube_num * 8 + 3) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 3) * 6 + 5] = uintBitsToFloat(1);
//vertice 4
vertices[(cube_num * 8 + 4) * vertex_size + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 4) * vertex_size + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 4) * vertex_size + 2] = pos.z - 0.5 * scale;
vertices[(cube_num * 8 + 4) * 6 + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 4) * 6 + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 4) * 6 + 2] = pos.z - 0.5 * scale;
//volume
vertices[(cube_num * 8 + 4) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 4) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 4) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 4) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 4) * vertex_size + 5] = uintBitsToFloat(0);
// flags, first bit is transparency
vertices[(cube_num * 8 + 4) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 4) * 6 + 5] = uintBitsToFloat(0);
//vertice 5
vertices[(cube_num * 8 + 5) * vertex_size + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 5) * vertex_size + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 5) * vertex_size + 2] = pos.z - 0.5 * scale;
vertices[(cube_num * 8 + 5) * 6 + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 5) * 6 + 1] = pos.y + 0.5 * scale;
vertices[(cube_num * 8 + 5) * 6 + 2] = pos.z - 0.5 * scale;
//volume
vertices[(cube_num * 8 + 5) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 5) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 5) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 5) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 5) * vertex_size + 5] = uintBitsToFloat(2);
// flags, first bit is transparency
vertices[(cube_num * 8 + 5) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 5) * 6 + 5] = uintBitsToFloat(2);
//vertice 6
vertices[(cube_num * 8 + 6) * vertex_size + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 6) * vertex_size + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 6) * vertex_size + 2] = pos.z - 0.5 * scale;
vertices[(cube_num * 8 + 6) * 6 + 0] = pos.x - 0.5 * scale;
vertices[(cube_num * 8 + 6) * 6 + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 6) * 6 + 2] = pos.z - 0.5 * scale;
//volume
vertices[(cube_num * 8 + 6) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 6) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 6) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 6) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 6) * vertex_size + 5] = uintBitsToFloat(5);
// flags, first bit is transparency
vertices[(cube_num * 8 + 6) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 6) * 6 + 5] = uintBitsToFloat(5);
//vertice 7
vertices[(cube_num * 8 + 7) * vertex_size + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 7) * vertex_size + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 7) * vertex_size + 2] = pos.z - 0.5 * scale;
vertices[(cube_num * 8 + 7) * 6 + 0] = pos.x + 0.5 * scale;
vertices[(cube_num * 8 + 7) * 6 + 1] = pos.y - 0.5 * scale;
vertices[(cube_num * 8 + 7) * 6 + 2] = pos.z - 0.5 * scale;
//volume
vertices[(cube_num * 8 + 7) * vertex_size + 3] = uintBitsToFloat(start_volume);
vertices[(cube_num * 8 + 7) * 6 + 3] = uintBitsToFloat(start_volume);
//color
vertices[(cube_num * 8 + 7) * vertex_size + 4] = uintBitsToFloat(color);
vertices[(cube_num * 8 + 7) * 6 + 4] = uintBitsToFloat(color);
//facing
vertices[(cube_num * 8 + 7) * vertex_size + 5] = uintBitsToFloat(6);
// flags, first bit is transparency
vertices[(cube_num * 8 + 7) * vertex_size + 6] = 1 * uint(transparent);
vertices[(cube_num * 8 + 7) * 6 + 5] = uintBitsToFloat(6);
//add indices for the cube
//top
if (is_side_visible(grid_pos.x, grid_pos.y, grid_pos.z, compound_grid_size, input_offset, 0, 0, 1)) {
indices[cube_num * 36 + 0] = cube_num * 8 + 3;
indices[cube_num * 36 + 1] = cube_num * 8 + 0;
indices[cube_num * 36 + 2] = cube_num * 8 + 2;
indices[cube_num * 36 + 0] = cube_num * 8 + 3;
indices[cube_num * 36 + 1] = cube_num * 8 + 0;
indices[cube_num * 36 + 2] = cube_num * 8 + 2;
indices[cube_num * 36 + 3] = cube_num * 8 + 3;
indices[cube_num * 36 + 4] = cube_num * 8 + 1;
indices[cube_num * 36 + 5] = cube_num * 8 + 0;
}
indices[cube_num * 36 + 3] = cube_num * 8 + 3;
indices[cube_num * 36 + 4] = cube_num * 8 + 1;
indices[cube_num * 36 + 5] = cube_num * 8 + 0;
//bottom
if (is_side_visible(grid_pos.x, grid_pos.y, grid_pos.z, compound_grid_size, input_offset, 0, 0, -1)) {
indices[cube_num * 36 + 6] = cube_num * 8 + 4;
indices[cube_num * 36 + 7] = cube_num * 8 + 7;
indices[cube_num * 36 + 8] = cube_num * 8 + 6;
indices[cube_num * 36 + 6] = cube_num * 8 + 4;
indices[cube_num * 36 + 7] = cube_num * 8 + 7;
indices[cube_num * 36 + 8] = cube_num * 8 + 6;
indices[cube_num * 36 + 9] = cube_num * 8 + 4;
indices[cube_num * 36 + 10] = cube_num * 8 + 5;
indices[cube_num * 36 + 11] = cube_num * 8 + 7;
}
indices[cube_num * 36 + 9] = cube_num * 8 + 4;
indices[cube_num * 36 + 10] = cube_num * 8 + 5;
indices[cube_num * 36 + 11] = cube_num * 8 + 7;
//left
if (is_side_visible(grid_pos.x, grid_pos.y, grid_pos.z, compound_grid_size, input_offset, -1, 0, 0)) {
indices[cube_num * 36 + 12] = cube_num * 8 + 2;
indices[cube_num * 36 + 13] = cube_num * 8 + 0;
indices[cube_num * 36 + 14] = cube_num * 8 + 4;
indices[cube_num * 36 + 12] = cube_num * 8 + 2;
indices[cube_num * 36 + 13] = cube_num * 8 + 0;
indices[cube_num * 36 + 14] = cube_num * 8 + 4;
indices[cube_num * 36 + 15] = cube_num * 8 + 2;
indices[cube_num * 36 + 16] = cube_num * 8 + 4;
indices[cube_num * 36 + 17] = cube_num * 8 + 6;
}
indices[cube_num * 36 + 15] = cube_num * 8 + 2;
indices[cube_num * 36 + 16] = cube_num * 8 + 4;
indices[cube_num * 36 + 17] = cube_num * 8 + 6;
//right
if (is_side_visible(grid_pos.x, grid_pos.y, grid_pos.z, compound_grid_size, input_offset, 1, 0, 0)) {
indices[cube_num * 36 + 18] = cube_num * 8 + 5;
indices[cube_num * 36 + 19] = cube_num * 8 + 1;
indices[cube_num * 36 + 20] = cube_num * 8 + 3;
indices[cube_num * 36 + 18] = cube_num * 8 + 5;
indices[cube_num * 36 + 19] = cube_num * 8 + 1;
indices[cube_num * 36 + 20] = cube_num * 8 + 3;
indices[cube_num * 36 + 21] = cube_num * 8 + 5;
indices[cube_num * 36 + 22] = cube_num * 8 + 3;
indices[cube_num * 36 + 23] = cube_num * 8 + 7;
}
indices[cube_num * 36 + 21] = cube_num * 8 + 5;
indices[cube_num * 36 + 22] = cube_num * 8 + 3;
indices[cube_num * 36 + 23] = cube_num * 8 + 7;
//near
if (is_side_visible(grid_pos.x, grid_pos.y, grid_pos.z, compound_grid_size, input_offset, 0, -1, 0)) {
indices[cube_num * 36 + 24] = cube_num * 8 + 6;
indices[cube_num * 36 + 25] = cube_num * 8 + 3;
indices[cube_num * 36 + 26] = cube_num * 8 + 2;
indices[cube_num * 36 + 24] = cube_num * 8 + 6;
indices[cube_num * 36 + 25] = cube_num * 8 + 3;
indices[cube_num * 36 + 26] = cube_num * 8 + 2;
indices[cube_num * 36 + 27] = cube_num * 8 + 6;
indices[cube_num * 36 + 28] = cube_num * 8 + 7;
indices[cube_num * 36 + 29] = cube_num * 8 + 3;
}
indices[cube_num * 36 + 27] = cube_num * 8 + 6;
indices[cube_num * 36 + 28] = cube_num * 8 + 7;
indices[cube_num * 36 + 29] = cube_num * 8 + 3;
//far
if (is_side_visible(grid_pos.x, grid_pos.y, grid_pos.z, compound_grid_size, input_offset, 0, 1, 0)) {
indices[cube_num * 36 + 30] = cube_num * 8 + 1;
indices[cube_num * 36 + 31] = cube_num * 8 + 4;
indices[cube_num * 36 + 32] = cube_num * 8 + 0;
indices[cube_num * 36 + 30] = cube_num * 8 + 1;
indices[cube_num * 36 + 31] = cube_num * 8 + 4;
indices[cube_num * 36 + 32] = cube_num * 8 + 0;
indices[cube_num * 36 + 33] = cube_num * 8 + 1;
indices[cube_num * 36 + 34] = cube_num * 8 + 5;
indices[cube_num * 36 + 35] = cube_num * 8 + 4;
}
indices[cube_num * 36 + 33] = cube_num * 8 + 1;
indices[cube_num * 36 + 34] = cube_num * 8 + 5;
indices[cube_num * 36 + 35] = cube_num * 8 + 4;
}
@ -268,6 +227,16 @@ uint cohort_index_from_pos(uint x, uint y, uint z, uint block_size, uint compoun
return (z / block_size) * (steps*steps) + (y / block_size) * steps + (x / block_size);
}
bool is_visible(uint x, uint y, uint z, uint compound_grid_size, uint input_offset) {
return x == 0 || x == compound_grid_size - 1 || y == 0 || y == compound_grid_size -1 || z == 0 || z == compound_grid_size - 1 ||
transparent_grid[input_offset + (x - 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] ||
transparent_grid[input_offset + (x + 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + z] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + (y + 1) * compound_grid_size + z] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z - 1)] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z + 1)];
}
uint find_volume(uint overlapping_volume_num, uint volume_index_offset, vec3 volume_check_pos) {
uint volume_start = 0;
for(int i=0; i < overlapping_volume_num; i++) {
@ -407,94 +376,42 @@ void main() {
vec3 check_pos = compound_pos + vec3(float(x) * compound_scale, float(y) * compound_scale, float(z) * compound_scale) + mid_offset;
uint overlapping_volume_num = compounds[compound_start + 9];
uint volume_index_offset = compound_start + 11 + compounds[compound_start + 3] + compounds[compound_start + 4];
uint volume_index_offset = compound_start + 10 + compounds[compound_start + 3] + compounds[compound_start + 4];
//todo potentially it is needed to find volume start for each pos
uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(0.0, 0.0, 0.0) * compound_scale);
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 1] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 1] != 0 && is_visible(x - 1, y - 1, z - 1, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(1.0, 1.0, 1.0) * compound_scale);
add_cube(input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 1),
compound_scale,
check_pos - vec3(1.0, 1.0, 1.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 1],
volume_start,
transparent_grid[input_offset + (x - 1) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (z - 1)],
uvec3(x - 1, y - 1, z - 1), compound_grid_size, input_offset);
add_cube(input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 1), compound_scale, check_pos - vec3(1.0, 1.0, 1.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 1], volume_start);
}
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 2] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 2] != 0 && is_visible(x - 0, y - 1, z - 1, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(0.0, 1.0, 1.0) * compound_scale);
add_cube(input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 0),
compound_scale,
check_pos - vec3(0.0, 1.0, 1.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 2],
volume_start,
transparent_grid[input_offset + (x - 0) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (z - 1)],
uvec3(x - 0, y - 1, z - 1), compound_grid_size, input_offset);
add_cube(input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 0), compound_scale, check_pos - vec3(0.0, 1.0, 1.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 2], volume_start);
}
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 3] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 3] != 0 && is_visible(x - 1, y - 0, z - 1, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(1.0, 0.0, 1.0) * compound_scale);
add_cube(
input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 1),
compound_scale,
check_pos - vec3(1.0, 0.0, 1.0) * compound_scale,
out_memory[output_offset + cohort_start + cohort_index * 9 + 3],
volume_start,
transparent_grid[input_offset + (x - 1) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (z - 1)],
uvec3(x - 1, y - 0, z - 1), compound_grid_size, input_offset);
add_cube(input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 1), compound_scale, check_pos - vec3(1.0, 0.0, 1.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 3], volume_start);
}
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 4] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 4] != 0 && is_visible(x - 0, y - 0, z - 1, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(0.0, 0.0, 1.0) * compound_scale);
add_cube(
input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 0),
compound_scale,
check_pos - vec3(0.0, 0.0, 1.0) * compound_scale,
out_memory[output_offset + cohort_start + cohort_index * 9 + 4],
volume_start,
transparent_grid[input_offset + (x - 0) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (z - 1)],
uvec3(x - 0, y - 0, z - 1), compound_grid_size, input_offset);
add_cube(input_offset + (z - 1) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 0), compound_scale, check_pos - vec3(0.0, 0.0, 1.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 4], volume_start);
}
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 5] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 5] != 0 && is_visible(x - 1, y - 1, z - 0, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(1.0, 1.0, 0.0) * compound_scale);
add_cube(
input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 1),
compound_scale,
check_pos - vec3(1.0, 1.0, 0.0) * compound_scale,
out_memory[output_offset + cohort_start + cohort_index * 9 + 5],
volume_start,
transparent_grid[input_offset + (x - 1) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (z - 0)],
uvec3(x - 1, y - 1, z - 0), compound_grid_size, input_offset);
add_cube(input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 1), compound_scale, check_pos - vec3(1.0, 1.0, 0.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 5], volume_start);
}
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 6] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 6] != 0 && is_visible(x - 0, y - 1, z - 0, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(0.0, 1.0, 0.0) * compound_scale);
add_cube(
input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 0),
compound_scale,
check_pos - vec3(0.0, 1.0, 0.0) * compound_scale,
out_memory[output_offset + cohort_start + cohort_index * 9 + 6],
volume_start,
transparent_grid[input_offset + (x - 0) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (z - 0)],
uvec3(x - 0, y - 1, z - 0), compound_grid_size, input_offset);
add_cube(input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + (x - 0), compound_scale, check_pos - vec3(0.0, 1.0, 0.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 6], volume_start);
}
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 7] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 7] != 0 && is_visible(x - 1, y - 0, z - 0, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(1.0, 0.0, 0.0) * compound_scale);
add_cube(
input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 1),
compound_scale,
check_pos - vec3(1.0, 0.0, 0.0) * compound_scale,
out_memory[output_offset + cohort_start + cohort_index * 9 + 7],
volume_start,
transparent_grid[input_offset + (x - 1) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (z - 0)],
uvec3(x - 1, y - 0, z - 0), compound_grid_size, input_offset);
add_cube(input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 1), compound_scale, check_pos - vec3(1.0, 0.0, 0.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 7], volume_start);
}
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 8] != 0) {
if (out_memory[output_offset + cohort_start + cohort_index * 9 + 8] != 0 && is_visible(x - 0, y - 0, z - 0, compound_grid_size, input_offset)) {
//uint volume_start = find_volume(overlapping_volume_num, volume_index_offset, check_pos - vec3(0.0, 0.0, 0.0) * compound_scale);
add_cube(
input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 0),
compound_scale,
check_pos - vec3(0.0, 0.0, 0.0) * compound_scale,
out_memory[output_offset + cohort_start + cohort_index * 9 + 8],
volume_start,
transparent_grid[input_offset + (x - 0) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (z - 0)],
uvec3(x - 0, y - 0, z - 0), compound_grid_size, input_offset);
add_cube(input_offset + (z - 0) * compound_grid_size * compound_grid_size + (y - 0) * compound_grid_size + (x - 0), compound_scale, check_pos - vec3(0.0, 0.0, 0.0) * compound_scale, out_memory[output_offset + cohort_start + cohort_index * 9 + 8], volume_start);
}
}
} else {

View file

@ -13,7 +13,7 @@ layout(binding = 3) readonly buffer CompoundBuffer {
uint compounds[];
};
layout(binding = 8) buffer SceneInfoBuffer2 {
layout(binding = 4) buffer SceneInfoBuffer2 {
uint grid[];
};
@ -200,7 +200,7 @@ void main() {
bool transparent = false;
//handle included shapes
for (uint o=0; o < compounds[compound_start + 3]; o++) {
uint component_index = compounds[compound_start + 11 + o];
uint component_index = compounds[compound_start + 10 + o];
uint component_type = compounds[component_index];
vec3 component_pos = vec3(uintBitsToFloat(compounds[component_index + 1]), uintBitsToFloat(compounds[component_index + 2]), uintBitsToFloat(compounds[component_index + 3]));
vec3 component_rot = vec3(uintBitsToFloat(compounds[component_index + 4]), uintBitsToFloat(compounds[component_index + 5]), uintBitsToFloat(compounds[component_index + 6]));
@ -278,7 +278,7 @@ void main() {
}
//handle excluded shapes
for (uint o=0; o < compounds[compound_start + 4]; o++) {
uint component_index = compounds[compound_start + 11 + compounds[compound_start + 3] + o];
uint component_index = compounds[compound_start + 10 + compounds[compound_start + 3] + o];
uint component_type = compounds[component_index];
vec3 component_pos = vec3(uintBitsToFloat(compounds[component_index + 1]), uintBitsToFloat(compounds[component_index + 2]), uintBitsToFloat(compounds[component_index + 3]));
vec3 component_rot = vec3(uintBitsToFloat(compounds[component_index + 4]), uintBitsToFloat(compounds[component_index + 5]), uintBitsToFloat(compounds[component_index + 6]));

View file

@ -1,65 +0,0 @@
#version 450
layout(binding = 3) readonly buffer CompoundBuffer {
uint compounds[];
};
layout(binding = 4) buffer SceneInfoBuffer2 {
uint grid_out[];
};
layout(binding = 8) readonly buffer ColorBuffer {
uint grid_in[];
};
layout(binding = 9) buffer transparencies {
bool transparent_grid[];
};
layout (local_size_x = 16, local_size_y = 1, local_size_z = 1) in;
bool is_visible(uint x, uint y, uint z, uint compound_grid_size, uint input_offset) {
return (x == 0 || x == compound_grid_size - 1 || y == 0 || y == compound_grid_size -1 || z == 0 || z == compound_grid_size - 1) ||
((transparent_grid[input_offset + (x - 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] ||
transparent_grid[input_offset + (x + 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + z] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + (y + 1) * compound_grid_size + z] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z - 1)] ||
transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z + 1)]) &&
(!transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z] ||
(transparent_grid[input_offset + (x + 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] && grid_in[input_offset + (x + 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] != grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z]) ||
(transparent_grid[input_offset + (x - 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] && grid_in[input_offset + (x - 1) * compound_grid_size * compound_grid_size + y * compound_grid_size + z] != grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z]) ||
(transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + (y + 1) * compound_grid_size + z] && grid_in[input_offset + x * compound_grid_size * compound_grid_size + (y + 1) * compound_grid_size + z] != grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z]) ||
(transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + z] && grid_in[input_offset + x * compound_grid_size * compound_grid_size + (y - 1) * compound_grid_size + z] != grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z]) ||
(transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z + 1)] && grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z + 1)] != grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z]) ||
(transparent_grid[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z - 1)] && grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + (z - 1)] != grid_in[input_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z])
));
}
void main() {
uint index = gl_GlobalInvocationID.x;
uint output_offset = 0;
uint compound_start = 1;
// iterate over the compounds and find the work index inside of it
while (index > compounds[compound_start] * compounds[compound_start]) {
output_offset += compounds[compound_start] * compounds[compound_start] * compounds[compound_start];
index -= compounds[compound_start] * compounds[compound_start];
compound_start = compounds[compound_start + 2];
}
// grid pos in the task
uint compound_grid_size = compounds[compound_start];
float compound_scale = uintBitsToFloat(compounds[compound_start + 1]);
vec3 mid_offset = vec3(compound_scale * 0.5, compound_scale * 0.5, compound_scale * 0.5);
uint y = index % compound_grid_size;
uint z = (index - y) / compound_grid_size;
// iterate upwards along the x axis
uint sum = 0;
for (uint x=0; x < compound_grid_size; x++) {
if (is_visible(x, y, z, compound_grid_size, output_offset)) {
grid_out[output_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z] = grid_in[output_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z];
} else {
grid_out[output_offset + x * compound_grid_size * compound_grid_size + y * compound_grid_size + z] = 0;
}
}
}

View file

@ -22,10 +22,6 @@ layout(binding = 3) readonly buffer CompoundBuffer {
uint compounds[];
};
layout(binding = 9) buffer transparencies {
bool transparent_grid[];
};
layout(binding = 10) readonly buffer OctTreeMemory {
uint oct_tree_mem[];
};
@ -44,10 +40,11 @@ const uint absolute_max_compounds = 10;
uint max_num_compounds = min(scene_info.infos[6], absolute_max_compounds);
uvec4 unpack_color(uint val) {
uint val1 = bitfieldExtract(val, 24, 8);
uint val2 = bitfieldExtract(val, 16, 8);
uint val3 = bitfieldExtract(val, 8, 8);
uint val4 = bitfieldExtract(val, 0, 8);
// left most 8 bits first
uint val1 = (val >> 24);
uint val2 = (val << 8) >> 24;
uint val3 = (val << 16) >> 24;
uint val4 = (val << 24) >> 24;
return uvec4(val4, val3, val2, val1);
}
@ -468,7 +465,6 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
float compound_scale = uintBitsToFloat(compounds[compound_start + 1]);
vec3 compound_pos = vec3(uintBitsToFloat(compounds[compound_start + 5]), uintBitsToFloat(compounds[compound_start + 6]), uintBitsToFloat(compounds[compound_start + 7]));
vec3 intersection_pos = pos + hit_factors[min_index] * direction;
uint transparency_offset = compounds[compound_start + 10];
// invalidate the min found
hit_factors[min_index] = max_factor;
@ -478,16 +474,18 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
bool children_open[8] = {true, true, true, true, true, true, true, true};
uint oct_tree_address = oct_tree_index;
// iterate through the oct_tree
uint check_it = 0;
uint max_check_it = 70;
uint prev_child = 0;
uint prev_prev_child = 0;
uvec3 grid_pos = uvec3(0, 0, 0);
uvec3 parent_pos = uvec3(0, 0, 0);
uvec4 last_transp_col = uvec4(0, 0, 0, 0);
for (uint check_it=0; check_it < 80; check_it++) {
// failsafe to get out in case of an accuracy issue
bool has_moved = false;
while (!result.has_hit && check_it < max_check_it) {
// failsafe to get out in case has_moved runs into an accuracy issue
check_it ++;
oct_tree_pos = vec3(grid_pos) * compound_scale + compound_pos;
mid_point = oct_tree_pos + (float(current_size / 2) * vec3(compound_scale, compound_scale, compound_scale));
@ -518,40 +516,17 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
if (current_size == 2) {
// check block if hit break
if (oct_tree_mem[oct_tree_address + child_index] != 0) {
uvec4 unpacked_color = unpack_color(oct_tree_mem[oct_tree_address + child_index]);
uvec3 check_grid_pos = grid_pos + parent_child_vec(1, child_index);
bool is_transparent = transparent_grid[transparency_offset + check_grid_pos.x * compound_grid_size * compound_grid_size + check_grid_pos.y * compound_grid_size + check_grid_pos.z];
//is_transparent = false;
if (!is_transparent) {
result.has_hit = true;
result.end_color = unpacked_color;
break;
} else {
if (last_transp_col != unpacked_color) {
color_mul_transparent = result.color_mul;
float opacity = 1.0 - float(unpacked_color.w) / 255.0;
result.color_mul = result.color_mul * vec3(float(unpacked_color.x) / 255.0, float(unpacked_color.y) / 255.0, float(unpacked_color.z) / 255.0) * opacity;
end_color_transparent = unpacked_color;
end_pos_transparent = intersection_pos;
end_facing_transparent = uint(is_x_hit) * (2 + uint(x_pos)) + uint(is_y_hit) * (4 + uint(y_pos)) + uint(is_z_hit && !z_pos);
if (max(result.color_mul.x, max(result.color_mul.y, result.color_mul.z)) < 0.1) {
break;
}
}
// since we have hollow areas we do not want to double up on the transp color. Will not work as intended with multiple layers of transparent colors
last_transp_col = unpacked_color;
}
result.has_hit = true;
result.end_color = unpack_color(oct_tree_mem[oct_tree_address + child_index]);
break;
}
} else {
// check if the child has content, else skip to next child of current parent
uint next_child = oct_tree_mem[oct_tree_address + child_index];
if (oct_tree_mem[next_child] != 0) {
uint x = oct_tree_mem[oct_tree_address + child_index];
if (oct_tree_mem[x] != 0) {
// change base address and position to child
current_size /= 2;
oct_tree_address = next_child;
oct_tree_address = x;
grid_pos += parent_child_vec(current_size, child_index);
for (int i=0; i < 8; i++) {
children_open[i] = true;
@ -614,6 +589,8 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
// move a bit further to fully enter the next quadrant
smallest_factor += overstep;
//has_moved = length(intersection_pos - (pos + smallest_factor * direction)) >= 0.00001;
has_moved = intersection_pos != (pos + smallest_factor * direction);
intersection_pos = pos + smallest_factor * direction;
}
}
@ -703,8 +680,7 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
volume_pos_x = uintBitsToFloat(scene_info.infos[volume_index + 0]);
volume_pos_y = uintBitsToFloat(scene_info.infos[volume_index + 1]);
volume_pos_z = uintBitsToFloat(scene_info.infos[volume_index + 2]);
float opacity = 1.0 - float(color_sample.w) / 255.0;
result.color_mul = result.color_mul * vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0) * opacity;
result.color_mul = result.color_mul * vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0);
result.has_transparent_hit = true;
result.end_volume = volume_index;
result.end_direction = direction;
@ -881,38 +857,3 @@ vec3 add_reflection(vec3 view_vector, uint f, uint volume_start, vec3 pos, uvec4
return color_sum;
}
vec3 start_tracking(bool is_transparent, uint fragVolumeStart, uvec4 color_roughness, vec3 start_pos, uint facing) {
vec3 orig_color_sample = vec3(float(color_roughness.x) / 255.0, float(color_roughness.y) / 255.0, float(color_roughness.z) / 255.0);
vec3 color_sum;
if (is_transparent) {
vec3 color_direct = diffuse_tracing(fragVolumeStart, color_roughness, start_pos, facing);
Tracing t = trace_ray(fragVolumeStart, ubo.camera_pos, start_pos - ubo.camera_pos, pos_infinity, false);
float opacity = float(color_roughness.w) / 255.0;
vec3 color_seen_through;
if (t.has_hit) {
//color_seen_through = vec3(float(t.end_color.x) / 255.0, float(t.end_color.y) / 255.0, float(t.end_color.z) / 255.0);
color_seen_through = diffuse_tracing(t.end_volume, t.end_color, t.end_pos, t.end_facing);
color_seen_through = add_reflection(t.end_direction, t.end_facing, t.end_volume, t.end_pos, t.end_color, color_seen_through);
color_seen_through = color_seen_through * t.color_mul;
}
else {
// Todo: hit sky box
color_seen_through = vec3(0.0, 0.0, 0.0);
}
color_direct = add_reflection(normalize(start_pos - ubo.camera_pos), facing, fragVolumeStart, start_pos, color_roughness, color_direct);
color_sum = opacity * color_direct + color_seen_through;
//color_sum = color_seen_through;
}
else {
color_sum = diffuse_tracing(fragVolumeStart, color_roughness, start_pos, facing);
//color_sum = add_reflection(normalize(start_pos - ubo.camera_pos), facing, fragVolumeStart, start_pos, color_roughness, color_sum);
}
return color_sum;
}

View file

@ -33,10 +33,6 @@ layout(binding = 3) readonly buffer CompoundBuffer {
uint compounds[];
};
layout(binding = 9) buffer transparencies {
bool transparent_grid[];
};
layout(binding = 10) readonly buffer OctTreeMemory {
uint oct_tree_mem[];
};
@ -55,10 +51,11 @@ const uint absolute_max_compounds = 10;
uint max_num_compounds = min(scene_info.infos[6], absolute_max_compounds);
uvec4 unpack_color(uint val) {
uint val1 = bitfieldExtract(val, 24, 8);
uint val2 = bitfieldExtract(val, 16, 8);
uint val3 = bitfieldExtract(val, 8, 8);
uint val4 = bitfieldExtract(val, 0, 8);
// left most 8 bits first
uint val1 = (val >> 24);
uint val2 = (val << 8) >> 24;
uint val3 = (val << 16) >> 24;
uint val4 = (val << 24) >> 24;
return uvec4(val4, val3, val2, val1);
}
@ -479,7 +476,6 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
float compound_scale = uintBitsToFloat(compounds[compound_start + 1]);
vec3 compound_pos = vec3(uintBitsToFloat(compounds[compound_start + 5]), uintBitsToFloat(compounds[compound_start + 6]), uintBitsToFloat(compounds[compound_start + 7]));
vec3 intersection_pos = pos + hit_factors[min_index] * direction;
uint transparency_offset = compounds[compound_start + 10];
// invalidate the min found
hit_factors[min_index] = max_factor;
@ -488,17 +484,22 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
vec3 mid_point = oct_tree_pos + float(current_size / 2) * vec3(compound_scale, compound_scale, compound_scale);
bool children_open[8] = {true, true, true, true, true, true, true, true};
uint oct_tree_address = oct_tree_index;
/*if (oct_tree_address == 337042) {
result.has_hit = true;
}*/
// iterate through the oct_tree
uint check_it = 0;
uint max_check_it = 80;
uint prev_child = 0;
uint prev_prev_child = 0;
uvec3 grid_pos = uvec3(0, 0, 0);
uvec3 parent_pos = uvec3(0, 0, 0);
uvec4 last_transp_col = uvec4(0, 0, 0, 0);
for (uint check_it=0; check_it < 80; check_it++) {
// failsafe to get out in case of an accuracy issue
bool has_moved = false;
while (!result.has_hit && check_it < max_check_it) {
// failsafe to get out in case has_moved runs into an accuracy issue
check_it ++;
oct_tree_pos = vec3(grid_pos) * compound_scale + compound_pos;
mid_point = oct_tree_pos + (float(current_size / 2) * vec3(compound_scale, compound_scale, compound_scale));
@ -529,40 +530,17 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
if (current_size == 2) {
// check block if hit break
if (oct_tree_mem[oct_tree_address + child_index] != 0) {
uvec4 unpacked_color = unpack_color(oct_tree_mem[oct_tree_address + child_index]);
uvec3 check_grid_pos = grid_pos + parent_child_vec(1, child_index);
bool is_transparent = transparent_grid[transparency_offset + check_grid_pos.x * compound_grid_size * compound_grid_size + check_grid_pos.y * compound_grid_size + check_grid_pos.z];
//is_transparent = false;
if (!is_transparent) {
result.has_hit = true;
result.end_color = unpacked_color;
break;
} else {
if (last_transp_col != unpacked_color) {
color_mul_transparent = result.color_mul;
float opacity = 1.0 - float(unpacked_color.w) / 255.0;
result.color_mul = result.color_mul * vec3(float(unpacked_color.x) / 255.0, float(unpacked_color.y) / 255.0, float(unpacked_color.z) / 255.0) * opacity;
end_color_transparent = unpacked_color;
end_pos_transparent = intersection_pos;
end_facing_transparent = uint(is_x_hit) * (2 + uint(x_pos)) + uint(is_y_hit) * (4 + uint(y_pos)) + uint(is_z_hit && !z_pos);
if (max(result.color_mul.x, max(result.color_mul.y, result.color_mul.z)) < 0.1) {
break;
}
}
// since we have hollow areas we do not want to double up on the transp color. Will not work as intended with multiple layers of transparent colors
last_transp_col = unpacked_color;
}
result.has_hit = true;
result.end_color = unpack_color(oct_tree_mem[oct_tree_address + child_index]);
break;
}
} else {
// check if the child has content, else skip to next child of current parent
uint next_child = oct_tree_mem[oct_tree_address + child_index];
if (oct_tree_mem[next_child] != 0) {
uint x = oct_tree_mem[oct_tree_address + child_index];
if (oct_tree_mem[x] != 0) {
// change base address and position to child
current_size /= 2;
oct_tree_address = next_child;
oct_tree_address = x;
grid_pos += parent_child_vec(current_size, child_index);
for (int i=0; i < 8; i++) {
children_open[i] = true;
@ -625,6 +603,8 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
// move a bit further to fully enter the next quadrant
smallest_factor += overstep;
//has_moved = length(intersection_pos - (pos + smallest_factor * direction)) >= 0.00001;
has_moved = intersection_pos != (pos + smallest_factor * direction);
intersection_pos = pos + smallest_factor * direction;
}
}
@ -714,8 +694,7 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
volume_pos_x = uintBitsToFloat(scene_info.infos[volume_index + 0]);
volume_pos_y = uintBitsToFloat(scene_info.infos[volume_index + 1]);
volume_pos_z = uintBitsToFloat(scene_info.infos[volume_index + 2]);
float opacity = 1.0 - float(color_sample.w) / 255.0;
result.color_mul = result.color_mul * vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0) * opacity;
result.color_mul = result.color_mul * vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0);
result.has_transparent_hit = true;
result.end_volume = volume_index;
result.end_direction = direction;
@ -893,49 +872,41 @@ vec3 add_reflection(vec3 view_vector, uint f, uint volume_start, vec3 pos, uvec4
return color_sum;
}
vec3 start_tracking(bool is_transparent, uint fragVolumeStart, uvec4 color_roughness, vec3 start_pos, uint facing) {
void main() {
vec3 clamped_pos = clamp_to_volume(fragVolumeStart, origPosition);
vec2 clamped_raster_pos = clamp_to_quad(fragRasterPos, minRasterPos, maxRasterPos);
uvec4 color_roughness = sample_color_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
vec3 orig_color_sample = vec3(float(color_roughness.x) / 255.0, float(color_roughness.y) / 255.0, float(color_roughness.z) / 255.0);
vec3 color_sum;
if (is_transparent) {
vec3 color_direct = diffuse_tracing(fragVolumeStart, color_roughness, start_pos, facing);
Tracing t = trace_ray(fragVolumeStart, ubo.camera_pos, start_pos - ubo.camera_pos, pos_infinity, false);
uint orig_neighbor = sample_neighbor_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
if (orig_neighbor != 0) {
vec3 color_direct = diffuse_tracing(fragVolumeStart, color_roughness, clamped_pos, facing);
Tracing t = trace_ray(fragVolumeStart, ubo.camera_pos, clamped_pos - ubo.camera_pos, pos_infinity, false);
float opacity = float(color_roughness.w) / 255.0;
vec3 color_seen_through;
if (t.has_hit) {
//color_seen_through = vec3(float(t.end_color.x) / 255.0, float(t.end_color.y) / 255.0, float(t.end_color.z) / 255.0);
color_seen_through = diffuse_tracing(t.end_volume, t.end_color, t.end_pos, t.end_facing);
color_seen_through = add_reflection(t.end_direction, t.end_facing, t.end_volume, t.end_pos, t.end_color, color_seen_through);
color_seen_through = color_seen_through * t.color_mul;
color_seen_through = diffuse_tracing(t.end_volume, t.end_color, t.end_pos, t.end_facing) * orig_color_sample * t.color_mul;
//color_seen_through = add_reflection(t.end_direction, t.end_facing, t.end_volume, t.end_pos, t.end_color, color_seen_through);
}
else {
// Todo: hit sky box
color_seen_through = vec3(0.0, 0.0, 0.0);
}
color_direct = add_reflection(normalize(start_pos - ubo.camera_pos), facing, fragVolumeStart, start_pos, color_roughness, color_direct);
color_sum = opacity * color_direct + color_seen_through;
//color_direct = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_direct);
color_sum = opacity * color_direct + (1.0 - opacity) * color_seen_through;
//color_sum = color_seen_through;
}
else {
color_sum = diffuse_tracing(fragVolumeStart, color_roughness, start_pos, facing);
color_sum = diffuse_tracing(fragVolumeStart, color_roughness, clamped_pos, facing);
//color_sum = add_reflection(normalize(start_pos - ubo.camera_pos), facing, fragVolumeStart, start_pos, color_roughness, color_sum);
//color_sum = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_sum);
}
return color_sum;
}
void main() {
vec3 clamped_pos = clamp_to_volume(fragVolumeStart, origPosition);
vec2 clamped_raster_pos = clamp_to_quad(fragRasterPos, minRasterPos, maxRasterPos);
uvec4 color_roughness = sample_color_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
uint orig_neighbor = sample_neighbor_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
vec3 color_sum = start_tracking(orig_neighbor != 0, fragVolumeStart, color_roughness, clamped_pos, facing);
outColor = vec4(color_sum, 1.0);
}

View file

@ -15,10 +15,37 @@ void main() {
vec3 clamped_pos = clamp_to_volume(fragVolumeStart, origPosition);
vec2 clamped_raster_pos = clamp_to_quad(fragRasterPos, minRasterPos, maxRasterPos);
uvec4 color_roughness = sample_color_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
vec3 orig_color_sample = vec3(float(color_roughness.x) / 255.0, float(color_roughness.y) / 255.0, float(color_roughness.z) / 255.0);
vec3 color_sum;
uint orig_neighbor = sample_neighbor_from_scene_info(fragVolumeStart, clamped_raster_pos, facing);
if (orig_neighbor != 0) {
vec3 color_direct = diffuse_tracing(fragVolumeStart, color_roughness, clamped_pos, facing);
vec3 color_sum = start_tracking(orig_neighbor != 0, fragVolumeStart, color_roughness, clamped_pos, facing);
Tracing t = trace_ray(fragVolumeStart, ubo.camera_pos, clamped_pos - ubo.camera_pos, pos_infinity, false);
float opacity = float(color_roughness.w) / 255.0;
vec3 color_seen_through;
if (t.has_hit) {
//color_seen_through = vec3(float(t.end_color.x) / 255.0, float(t.end_color.y) / 255.0, float(t.end_color.z) / 255.0);
color_seen_through = diffuse_tracing(t.end_volume, t.end_color, t.end_pos, t.end_facing) * orig_color_sample * t.color_mul;
//color_seen_through = add_reflection(t.end_direction, t.end_facing, t.end_volume, t.end_pos, t.end_color, color_seen_through);
}
else {
// Todo: hit sky box
color_seen_through = vec3(0.0, 0.0, 0.0);
}
//color_direct = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_direct);
color_sum = opacity * color_direct + (1.0 - opacity) * color_seen_through;
//color_sum = color_seen_through;
}
else {
color_sum = diffuse_tracing(fragVolumeStart, color_roughness, clamped_pos, facing);
//color_sum = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_sum);
}
outColor = vec4(color_sum, 1.0);
}

View file

@ -4,7 +4,6 @@ layout(location = 0) flat in uint volume_start;
layout(location = 1) flat in uint color_roughness;
layout(location = 2) flat in uint facing;
layout(location = 3) in vec3 origPosition;
layout(location = 4) flat in uint flags;
layout(location = 0) out vec4 outColor;
@ -32,10 +31,6 @@ layout(binding = 3) readonly buffer CompoundBuffer {
uint compounds[];
};
layout(binding = 9) buffer transparencies {
bool transparent_grid[];
};
layout(binding = 10) readonly buffer OctTreeMemory {
uint oct_tree_mem[];
};
@ -54,10 +49,11 @@ const uint absolute_max_compounds = 10;
uint max_num_compounds = min(scene_info.infos[6], absolute_max_compounds);
uvec4 unpack_color(uint val) {
uint val1 = bitfieldExtract(val, 24, 8);
uint val2 = bitfieldExtract(val, 16, 8);
uint val3 = bitfieldExtract(val, 8, 8);
uint val4 = bitfieldExtract(val, 0, 8);
// left most 8 bits first
uint val1 = (val >> 24);
uint val2 = (val << 8) >> 24;
uint val3 = (val << 16) >> 24;
uint val4 = (val << 24) >> 24;
return uvec4(val4, val3, val2, val1);
}
@ -478,7 +474,6 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
float compound_scale = uintBitsToFloat(compounds[compound_start + 1]);
vec3 compound_pos = vec3(uintBitsToFloat(compounds[compound_start + 5]), uintBitsToFloat(compounds[compound_start + 6]), uintBitsToFloat(compounds[compound_start + 7]));
vec3 intersection_pos = pos + hit_factors[min_index] * direction;
uint transparency_offset = compounds[compound_start + 10];
// invalidate the min found
hit_factors[min_index] = max_factor;
@ -487,17 +482,22 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
vec3 mid_point = oct_tree_pos + float(current_size / 2) * vec3(compound_scale, compound_scale, compound_scale);
bool children_open[8] = {true, true, true, true, true, true, true, true};
uint oct_tree_address = oct_tree_index;
/*if (oct_tree_address == 337042) {
result.has_hit = true;
}*/
// iterate through the oct_tree
uint check_it = 0;
uint max_check_it = 80;
uint prev_child = 0;
uint prev_prev_child = 0;
uvec3 grid_pos = uvec3(0, 0, 0);
uvec3 parent_pos = uvec3(0, 0, 0);
uvec4 last_transp_col = uvec4(0, 0, 0, 0);
for (uint check_it=0; check_it < 80; check_it++) {
// failsafe to get out in case of an accuracy issue
bool has_moved = false;
while (!result.has_hit && check_it < max_check_it) {
// failsafe to get out in case has_moved runs into an accuracy issue
check_it ++;
oct_tree_pos = vec3(grid_pos) * compound_scale + compound_pos;
mid_point = oct_tree_pos + (float(current_size / 2) * vec3(compound_scale, compound_scale, compound_scale));
@ -528,40 +528,17 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
if (current_size == 2) {
// check block if hit break
if (oct_tree_mem[oct_tree_address + child_index] != 0) {
uvec4 unpacked_color = unpack_color(oct_tree_mem[oct_tree_address + child_index]);
uvec3 check_grid_pos = grid_pos + parent_child_vec(1, child_index);
bool is_transparent = transparent_grid[transparency_offset + check_grid_pos.x * compound_grid_size * compound_grid_size + check_grid_pos.y * compound_grid_size + check_grid_pos.z];
//is_transparent = false;
if (!is_transparent) {
result.has_hit = true;
result.end_color = unpacked_color;
break;
} else {
if (last_transp_col != unpacked_color) {
color_mul_transparent = result.color_mul;
float opacity = 1.0 - float(unpacked_color.w) / 255.0;
result.color_mul = result.color_mul * vec3(float(unpacked_color.x) / 255.0, float(unpacked_color.y) / 255.0, float(unpacked_color.z) / 255.0) * opacity;
end_color_transparent = unpacked_color;
end_pos_transparent = intersection_pos;
end_facing_transparent = uint(is_x_hit) * (2 + uint(x_pos)) + uint(is_y_hit) * (4 + uint(y_pos)) + uint(is_z_hit && !z_pos);
if (max(result.color_mul.x, max(result.color_mul.y, result.color_mul.z)) < 0.1) {
break;
}
}
// since we have hollow areas we do not want to double up on the transp color. Will not work as intended with multiple layers of transparent colors
last_transp_col = unpacked_color;
}
result.has_hit = true;
result.end_color = unpack_color(oct_tree_mem[oct_tree_address + child_index]);
break;
}
} else {
// check if the child has content, else skip to next child of current parent
uint next_child = oct_tree_mem[oct_tree_address + child_index];
if (oct_tree_mem[next_child] != 0) {
uint x = oct_tree_mem[oct_tree_address + child_index];
if (oct_tree_mem[x] != 0) {
// change base address and position to child
current_size /= 2;
oct_tree_address = next_child;
oct_tree_address = x;
grid_pos += parent_child_vec(current_size, child_index);
for (int i=0; i < 8; i++) {
children_open[i] = true;
@ -624,6 +601,8 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
// move a bit further to fully enter the next quadrant
smallest_factor += overstep;
//has_moved = length(intersection_pos - (pos + smallest_factor * direction)) >= 0.00001;
has_moved = intersection_pos != (pos + smallest_factor * direction);
intersection_pos = pos + smallest_factor * direction;
}
}
@ -713,8 +692,7 @@ Tracing trace_ray(uint volume_start, vec3 starting_pos, vec3 start_direction, fl
volume_pos_x = uintBitsToFloat(scene_info.infos[volume_index + 0]);
volume_pos_y = uintBitsToFloat(scene_info.infos[volume_index + 1]);
volume_pos_z = uintBitsToFloat(scene_info.infos[volume_index + 2]);
float opacity = 1.0 - float(color_sample.w) / 255.0;
result.color_mul = result.color_mul * vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0) * opacity;
result.color_mul = result.color_mul * vec3(float(color_sample.x) / 255.0, float(color_sample.y) / 255.0, float(color_sample.z) / 255.0);
result.has_transparent_hit = true;
result.end_volume = volume_index;
result.end_direction = direction;
@ -892,60 +870,30 @@ vec3 add_reflection(vec3 view_vector, uint f, uint volume_start, vec3 pos, uvec4
return color_sum;
}
vec3 start_tracking(bool is_transparent, uint fragVolumeStart, uvec4 color_roughness, vec3 start_pos, uint facing) {
vec3 orig_color_sample = vec3(float(color_roughness.x) / 255.0, float(color_roughness.y) / 255.0, float(color_roughness.z) / 255.0);
vec3 color_sum;
if (is_transparent) {
vec3 color_direct = diffuse_tracing(fragVolumeStart, color_roughness, start_pos, facing);
Tracing t = trace_ray(fragVolumeStart, ubo.camera_pos, start_pos - ubo.camera_pos, pos_infinity, false);
float opacity = float(color_roughness.w) / 255.0;
vec3 color_seen_through;
if (t.has_hit) {
//color_seen_through = vec3(float(t.end_color.x) / 255.0, float(t.end_color.y) / 255.0, float(t.end_color.z) / 255.0);
color_seen_through = diffuse_tracing(t.end_volume, t.end_color, t.end_pos, t.end_facing);
color_seen_through = add_reflection(t.end_direction, t.end_facing, t.end_volume, t.end_pos, t.end_color, color_seen_through);
color_seen_through = color_seen_through * t.color_mul;
}
else {
// Todo: hit sky box
color_seen_through = vec3(0.0, 0.0, 0.0);
}
color_direct = add_reflection(normalize(start_pos - ubo.camera_pos), facing, fragVolumeStart, start_pos, color_roughness, color_direct);
color_sum = opacity * color_direct + color_seen_through;
//color_sum = color_seen_through;
}
else {
color_sum = diffuse_tracing(fragVolumeStart, color_roughness, start_pos, facing);
//color_sum = add_reflection(normalize(start_pos - ubo.camera_pos), facing, fragVolumeStart, start_pos, color_roughness, color_sum);
}
return color_sum;
}
struct Flags {
bool transparent;
};
Flags unpack_flags(uint packed_flags) {
// left most 8 bits first
Flags unpacked_flags;
unpacked_flags.transparent = bool(bitfieldExtract(packed_flags, 24, 1));
return unpacked_flags;
}
void main() {
uvec4 unpacked = unpack_color(color_roughness);
vec3 fragColor = vec3(float(unpacked.x) / 255.0, float(unpacked.y) / 255.0, float(unpacked.z) / 255.0);
Flags unpacked_flags = unpack_flags(flags);
if (volume_start != 0) {
vec3 color_sum = start_tracking(unpacked_flags.transparent, volume_start, unpacked, origPosition, facing);
outColor = vec4(color_sum, 1.0);
uint test_facing = facing;
//365905
/*if (volume_start == 158451) {
outColor = vec4(1.0, 0.0, 0.0, 1);
}
if (volume_start == 172317) {
outColor = vec4(0.0, 1.0, 0.0, 1);
}*/
vec3 color_sum = diffuse_tracing(volume_start, unpacked, origPosition, test_facing);
outColor = vec4(color_sum, 1.0);
if (facing == 6) {
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
if (volume_start == 0) {
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
//outColor = vec4(fragColor, 1.0);
}

View file

@ -14,13 +14,11 @@ layout(location = 0) in vec3 inPosition;
layout(location = 1) in uint volume_start;
layout(location = 2) in uint color_roughness;
layout(location = 3) in uint facing;
layout(location = 4) in uint flags;
layout(location = 0) flat out uint out_volume_start;
layout(location = 1) flat out uint out_color_roughness;
layout(location = 2) flat out uint out_facing;
layout(location = 3) out vec3 origPosition;
layout(location = 4) flat out uint out_flags;
void main() {
gl_Position = ubo.proj * ubo.view * ubo.geom_rot * ubo.model * vec4(inPosition, 1.0);
@ -29,5 +27,4 @@ void main() {
out_color_roughness = color_roughness;
out_facing = facing;
origPosition = inPosition;
out_flags = flags;
}

View file

@ -4,31 +4,35 @@ layout(location = 0) flat in uint volume_start;
layout(location = 1) flat in uint color_roughness;
layout(location = 2) flat in uint facing;
layout(location = 3) in vec3 origPosition;
layout(location = 4) flat in uint flags;
layout(location = 0) out vec4 outColor;
#include rt_lib.frag
struct Flags {
bool transparent;
};
Flags unpack_flags(uint packed_flags) {
// left most 8 bits first
Flags unpacked_flags;
unpacked_flags.transparent = bool(bitfieldExtract(packed_flags, 24, 1));
return unpacked_flags;
}
void main() {
uvec4 unpacked = unpack_color(color_roughness);
vec3 fragColor = vec3(float(unpacked.x) / 255.0, float(unpacked.y) / 255.0, float(unpacked.z) / 255.0);
Flags unpacked_flags = unpack_flags(flags);
if (volume_start != 0) {
vec3 color_sum = start_tracking(unpacked_flags.transparent, volume_start, unpacked, origPosition, facing);
outColor = vec4(color_sum, 1.0);
uint test_facing = facing;
//365905
/*if (volume_start == 158451) {
outColor = vec4(1.0, 0.0, 0.0, 1);
}
if (volume_start == 172317) {
outColor = vec4(0.0, 1.0, 0.0, 1);
}*/
vec3 color_sum = diffuse_tracing(volume_start, unpacked, origPosition, test_facing);
outColor = vec4(color_sum, 1.0);
if (facing == 6) {
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
if (volume_start == 0) {
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
//outColor = vec4(fragColor, 1.0);
}

View file

@ -29,7 +29,6 @@ pub struct AppData {
pub pipeline_compute_grow_two: vk::Pipeline,
pub pipeline_compute_grow_three: vk::Pipeline,
pub pipeline_compute_mempos: vk::Pipeline,
pub pipeline_compute_visible: vk::Pipeline,
pub framebuffers: Vec<vk::Framebuffer>,
pub command_pool: vk::CommandPool,

View file

@ -10,6 +10,7 @@ pub type Mat4 = cgmath::Matrix4<f32>;
use crate::app_data;
use crate::command_buffer;
use crate::primitives;
use crate::vertex;
use crate::vertex::VertexContainer;
use crate::scene;
@ -533,8 +534,6 @@ pub unsafe fn update_compute_storage_buffer(
/*
// used to look into the oct tree buffer. Needs to have it marked as transfer src to avoid validation error
use serde_json::to_writer;
use std::fs::OpenOptions;
pub unsafe fn show_oct_tree(
instance: &Instance,
device: &Device,
@ -569,8 +568,6 @@ pub unsafe fn show_oct_tree(
//337042
//674083 max pos for two volumetrics
//337042 for one
let file_ref = OpenOptions::new().create(true).write(true).truncate(true).open("oct_tree_dump.json")?;
serde_json::to_writer(&file_ref, &test_vec)?;
let mut line = 0;
for val in &test_vec {
/*if *val != 0 {

View file

@ -60,7 +60,7 @@ pub unsafe fn create_command_buffers(device: &Device, data: &mut app_data::AppDa
// define the compute load before going into the render pass
if scene_handler.volumetrics.len() != 0 {
device.cmd_bind_pipeline(
*command_buffer, vk::PipelineBindPoint::COMPUTE, data.pipeline_compute_rasterize);
*command_buffer, vk::PipelineBindPoint::COMPUTE, data.pipeline_compute_rasterize); //todo build own pipeline
device.cmd_bind_descriptor_sets(
*command_buffer,
@ -87,7 +87,7 @@ pub unsafe fn create_command_buffers(device: &Device, data: &mut app_data::AppDa
// compute storage barrier
let buffer_memory_barrier_color = vk::BufferMemoryBarrier::builder()
.buffer(data.compute_out_storage_buffers_size_three[i])
.buffer(data.compute_out_storage_buffers_color[i])
.src_access_mask(vk::AccessFlags::SHADER_WRITE)
.dst_access_mask(vk::AccessFlags::SHADER_READ)
.size(vk::WHOLE_SIZE as u64)
@ -107,40 +107,6 @@ pub unsafe fn create_command_buffers(device: &Device, data: &mut app_data::AppDa
&[] as &[vk::MemoryBarrier],
&[buffer_memory_barrier_color, buffer_memory_barrier_transparent],
&[] as &[vk::ImageMemoryBarrier]);
// prune for visibility
device.cmd_bind_pipeline(
*command_buffer, vk::PipelineBindPoint::COMPUTE, data.pipeline_compute_visible);
device.cmd_bind_descriptor_sets(
*command_buffer,
vk::PipelineBindPoint::COMPUTE,
data.pipeline_layout,
0,
&[data.descriptor_sets[i]],
&[]);
device.cmd_dispatch(*command_buffer, (data.compute_task_one_size as f64 / 16.0).ceil() as u32, 1, 1);
let buffer_memory_barrier_color = vk::BufferMemoryBarrier::builder()
.buffer(data.compute_out_storage_buffers_color[i])
.src_access_mask(vk::AccessFlags::SHADER_WRITE)
.dst_access_mask(vk::AccessFlags::SHADER_READ)
.size(vk::WHOLE_SIZE as u64)
.build();
let buffer_memory_barrier_threed = vk::BufferMemoryBarrier::builder()
.buffer(data.compute_out_storage_buffers_size_three[i])
.src_access_mask(vk::AccessFlags::SHADER_READ)
.dst_access_mask(vk::AccessFlags::SHADER_WRITE)
.size(vk::WHOLE_SIZE as u64)
.build();
device.cmd_pipeline_barrier(*command_buffer,
vk::PipelineStageFlags::COMPUTE_SHADER,
vk::PipelineStageFlags::COMPUTE_SHADER,
vk::DependencyFlags::DEVICE_GROUP,
&[] as &[vk::MemoryBarrier],
&[buffer_memory_barrier_color, buffer_memory_barrier_threed],
&[] as &[vk::ImageMemoryBarrier]);
// grow x axis
device.cmd_bind_pipeline(
*command_buffer, vk::PipelineBindPoint::COMPUTE, data.pipeline_compute_grow_one);

View file

@ -22,6 +22,7 @@ use vulkanalia::bytecode::Bytecode;
use std::collections::HashSet;
use std::ffi::CStr;
use std::time::{Duration, SystemTime};
use std::os::raw::c_void;
// extension imports
@ -49,8 +50,6 @@ pub mod load_model;
pub mod scene;
pub mod primitives;
mod test_oct_shader;
const PORTABILITY_MACOS_VERSION: Version = Version::new(1, 3, 216);
const VALIDATION_ENABLED: bool =
cfg!(debug_assertions);
@ -65,10 +64,8 @@ const DEVICE_EXTENSIONS: &[vk::ExtensionName] = &[
const MAX_FRAMES_IN_FLIGHT: usize = 30;
fn main() -> Result<()> {
//test_oct_shader::test()?;
//Ok(())
pretty_env_logger::init();
// Window
let event_loop = EventLoop::new()?;
@ -159,9 +156,8 @@ fn main() -> Result<()> {
unsafe { app.destroy(); }
}
/*
if event.logical_key == "p" && event.state == ElementState::Pressed && event.repeat == false {
// print part of the oct tree buffer function need to be uncommented
/*if event.logical_key == "p" && event.state == ElementState::Pressed && event.repeat == false {
// print part of the oct tree buffer
unsafe {
buffer::show_oct_tree(&app.instance, &app.device, &app.data, 0, &app.scene_handler).expect("failed to show oct tree");
}
@ -496,7 +492,6 @@ impl App {
self.device.destroy_pipeline(self.data.pipeline_compute_grow_two, None);
self.device.destroy_pipeline(self.data.pipeline_compute_grow_three, None);
self.device.destroy_pipeline(self.data.pipeline_compute_mempos, None);
self.device.destroy_pipeline(self.data.pipeline_compute_visible, None);
self.device.destroy_pipeline_layout(self.data.pipeline_layout, None);
self.device.destroy_render_pass(self.data.render_pass, None);
@ -902,7 +897,7 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
.vertex_binding_descriptions(binding_descriptions_quad)
.vertex_attribute_descriptions(&attribute_descriptions_quad);
// set up compute shaders
// set up compute shader
// load the byte data
let compute_bytes = include_bytes!("../shaders/compiled/rt_compute_rasterize.spv");
// create the shaders
@ -913,16 +908,6 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
.module(compute_shader_module_rasterize)
.name(b"main\0");
// load the byte data
let compute_bytes = include_bytes!("../shaders/compiled/rt_compute_visible.spv");
// create the shaders
let compute_shader_module_visible = create_shader_module(device, &compute_bytes[..])?;
//create the shader stage for the compute shader
let compute_stage_visible = vk::PipelineShaderStageCreateInfo::builder()
.stage(vk::ShaderStageFlags::COMPUTE)
.module(compute_shader_module_visible)
.name(b"main\0");
// load the byte data
let compute_bytes = include_bytes!("../shaders/compiled/rt_compute_grow_one.spv");
// create the shaders
@ -1126,10 +1111,6 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
.stage(compute_stage_rasterize)
.layout(data.pipeline_layout);
let info_compute_visible = vk::ComputePipelineCreateInfo::builder()
.stage(compute_stage_visible)
.layout(data.pipeline_layout);
let info_compute_grow_one = vk::ComputePipelineCreateInfo::builder()
.stage(compute_stage_grow_one)
.layout(data.pipeline_layout);
@ -1146,7 +1127,7 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
.stage(compute_stage_mempos)
.layout(data.pipeline_layout);
let compute_pipelines = device.create_compute_pipelines(vk::PipelineCache::null(), &[info_compute_rasterize, info_compute_grow_one, info_compute_grow_two, info_compute_grow_three, info_compute_mempos, info_compute_visible], None)?.0;
let compute_pipelines = device.create_compute_pipelines(vk::PipelineCache::null(), &[info_compute_rasterize, info_compute_grow_one, info_compute_grow_two, info_compute_grow_three, info_compute_mempos], None)?.0;
data.pipeline_cube = pipelines[0];
data.pipeline_cuboid = pipelines[1];
@ -1158,7 +1139,6 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
data.pipeline_compute_grow_two = compute_pipelines[2];
data.pipeline_compute_grow_three = compute_pipelines[3];
data.pipeline_compute_mempos = compute_pipelines[4];
data.pipeline_compute_visible = compute_pipelines[5];
device.destroy_shader_module(vert_shader_module_cube, None);
device.destroy_shader_module(geo_shader_module_cube, None);
@ -1179,7 +1159,6 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
device.destroy_shader_module(compute_shader_module_grow_two, None);
device.destroy_shader_module(compute_shader_module_grow_three, None);
device.destroy_shader_module(compute_shader_module_mempos, None);
device.destroy_shader_module(compute_shader_module_visible, None);
Ok(())
}

View file

@ -1,6 +1,6 @@
use cgmath::{ElementWise, InnerSpace, Vector3};
use std::cell::RefCell;
use std::cell::{RefCell, Ref};
use std::rc::Rc;
use std::time::Instant;
@ -11,6 +11,8 @@ use crate::primitives::quad::Quad;
use crate::scene::oct_tree::OctTree;
use super::memorizable::Memorizable;
use super::light::LightSource;
use super::light::PointLight;
use super::volumetrics::ShapeComposition;
use super::AppData;
use super::LightsIter;
@ -993,24 +995,24 @@ impl EmptyVolume {
pub fn select_lights(&self, lights: LightsIter, light_number: u32, min_light_weight: f32) -> Vec<u32> {
let mut weighted_indices = vec![];
for light in lights {
//let mut has_hitable_side = false;
let mut has_hitable_side = false;
if self.color_bottom.len() > 0 {
let center = self.real_position + Vector3{x: self.size_x as f32 * 0.5, y: self.size_y as f32 * 0.5, z: self.size_z as f32 * 0.0 - 0.5} * self.scale;
let normal = Vector3 {x: 0.0, y: 0.0, z: 1.0};
let dir = light.borrow().get_direction(center);
/*if normal.dot(dir) < 0.0 {
if normal.dot(dir) < 0.0 {
has_hitable_side = true;
}*/
}
}
if self.color_top.len() > 0 {
let center = self.real_position + Vector3{x: self.size_x as f32 * 0.5, y: self.size_y as f32 * 0.5, z: self.size_z as f32 * 1.0 - 0.5} * self.scale;
let normal = Vector3 {x: 0.0, y: 0.0, z: -1.0};
let dir = light.borrow().get_direction(center);
/*if normal.dot(dir) < 0.0 {
if normal.dot(dir) < 0.0 {
has_hitable_side = true;
}*/
}
}
if self.color_front.len() > 0 {
@ -1018,9 +1020,9 @@ impl EmptyVolume {
let normal = Vector3 {x: 0.0, y: 1.0, z: 0.0};
let dir = light.borrow().get_direction(center);
/*if normal.dot(dir) < 0.0 {
if normal.dot(dir) < 0.0 {
has_hitable_side = true;
}*/
}
}
if self.color_back.len() > 0 {
@ -1028,9 +1030,9 @@ impl EmptyVolume {
let normal = Vector3 {x: 0.0, y: -1.0, z: 0.0};
let dir = light.borrow().get_direction(center);
/*if normal.dot(dir) < 0.0 {
if normal.dot(dir) < 0.0 {
has_hitable_side = true;
}*/
}
}
if self.color_left.len() > 0 {
@ -1038,9 +1040,9 @@ impl EmptyVolume {
let normal = Vector3 {x: 1.0, y: 0.0, z: 0.0};
let dir = light.borrow().get_direction(center);
/*if normal.dot(dir) < 0.0 {
if normal.dot(dir) < 0.0 {
has_hitable_side = true;
}*/
}
}
if self.color_right.len() > 0 {
@ -1048,9 +1050,9 @@ impl EmptyVolume {
let normal = Vector3 {x: -1.0, y: 0.0, z: 0.0};
let dir = light.borrow().get_direction(center);
/*if normal.dot(dir) < 0.0 {
if normal.dot(dir) < 0.0 {
has_hitable_side = true;
}*/
}
}
/*if !has_hitable_side {
@ -1104,8 +1106,8 @@ impl EmptyVolume {
}
pub fn combine_results(first: &Rc<RefCell<OctTree<Cube>>>,first_neighbors: &Rc<OctTree<Rc<RefCell<EmptyVolume>>>>, second: &Rc<RefCell<OctTree<Cube>>>, second_neighbors: &Rc<OctTree<Rc<RefCell<EmptyVolume>>>>, facing: vertex::Facing) {
let first_start;
let second_start;
let mut first_start;
let mut second_start;
let step_one;
let step_two;
@ -1166,7 +1168,7 @@ impl EmptyVolume {
if !done_volumes.contains(&volume) {
let mask = Vector3 {x: 1, y: 1, z: 1} - (step_one + step_two);
let negated_mask = step_one + step_two;
let negated_mask = (step_one + step_two);
let volume_start_first = negated_mask.mul_element_wise(volume.borrow().grid_position) + first_pos.mul_element_wise(mask);
let volume_start_second = negated_mask.mul_element_wise(volume.borrow().grid_position) + second_pos.mul_element_wise(mask);
@ -1641,7 +1643,7 @@ impl Memorizable for EmptyVolume {
}
else {
v[mem_index] = 0;
//mem_index += 1;
mem_index += 1;
}
self.dirty = false;

View file

@ -16,10 +16,10 @@ use cgmath::{vec2, vec3, Vector3, Point3};
use std::cell::RefCell;
use std::rc::Rc;
use super::light::PointLight;
use super::light::{DirectionalLight, PointLight};
pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<Point3<f32>> {
pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<(Point3<f32>)> {
let mut rng = rand::thread_rng();
let grid_size = CHUNK_SIZE as i32;
@ -60,7 +60,7 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<Poin
color: vec3(0.9, 0.9, 0.9),
tex_coord: vec2(0.0, 0.0),
transparent: true,
roughness: 0,
roughness: 32,
};
oct_tree1.set_cube(cube.clone());
@ -69,7 +69,7 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<Poin
color: vec3(0.9, 0.9, 0.9),
tex_coord: vec2(0.0, 0.0),
transparent: true,
roughness: 0,
roughness: 32,
};
oct_tree1.set_cube(cube.clone());
@ -123,25 +123,25 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<Poin
//comp.included_shapes.push(Rc::new(RefCell::new(Rect::new(Vector3 { x: 5.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 }, Vector3 { x: 5.0, y: 5.0, z: 5.0 },Vector3 { x: 0, y: 0, z: 255 }, 64, false))));
comp.included_shapes.push(Rc::new(RefCell::new(Sphere::new(Vector3 { x: 5.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: 5.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: 128, z: 0 }, 128, true))));
comp.included_shapes.push(Rc::new(RefCell::new(Sphere::new(Vector3 { x: 5.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: 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(Cone::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 }, 0.0, 2.5, Vector3 { x: 0.0, y: 10.0, z: 0.0 },Vector3 { x: 0, y: 255, z: 0 }, 64, false))));
comp.excluded_shapes.push(Rc::new(RefCell::new(Cone::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 }, 0.0, 1.5, Vector3 { x: 0.0, y: 10.0, z: 0.0 },Vector3 { x: 0, y: 255, z: 0 }, 64, false))));
//scene.volumetrics.push(Rc::new(RefCell::new(comp)));
scene.volumetrics.push(Rc::new(RefCell::new(comp)));
let mut comp = ShapeComposition::new(64);
comp.included_shapes.push(Rc::new(RefCell::new(Rect::new(Vector3 { x: -5.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 }, Vector3 { x: 5.0, y: 10.0, z: 2.0 },Vector3 { x: 0, y: 0, z: 255 }, 64, false))));
comp.excluded_shapes.push(Rc::new(RefCell::new(Rect::new(Vector3 { x: -5.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 }, Vector3 { x: 3.0, y: 8.0, z: 2.0 },Vector3 { x: 0, y: 0, z: 255 }, 64, false))));
//scene.volumetrics.push(Rc::new(RefCell::new(comp)));
Ok(cgmath::point3(11.0 + grid_size as f32, 11.0 + grid_size as f32, 10.0))
Ok((cgmath::point3(5.0, 5.0, 10.0)))
}
pub fn generate_test_scene2(scene: &mut Scene, data: &mut AppData, chunk_num_x: usize, chunk_num_y: usize, chunk_num_z: usize, num_gaussians: usize) -> Result<Point3<f32>> {
pub fn generate_test_scene2(scene: &mut Scene, data: &mut AppData, chunk_num_x: usize, chunk_num_y: usize, chunk_num_z: usize, num_gaussians: usize) -> Result<(Point3<f32>)> {
let mut rng = rand::thread_rng();
let scale = 1.0;

View file

@ -1,4 +1,5 @@
use cgmath::{InnerSpace, Vector3};
use cgmath::AbsDiffEq;
use cgmath::{InnerSpace, MetricSpace, Vector3};
use crate::vertex;
use super::memorizable::Memorizable;
@ -114,7 +115,7 @@ impl Light for PointLight {
new_diff.z += diff_high.z;
}
if (new_diff.x < new_diff.y || new_diff.y == 0.0) && (new_diff.x < new_diff.z || new_diff.z == 0.0) && new_diff.x != 0.0 {
if ((new_diff.x < new_diff.y || new_diff.y == 0.0) && (new_diff.x < new_diff.z || new_diff.z == 0.0) && new_diff.x != 0.0) {
offset_vec.x -= new_diff.x;
} else {
if (new_diff.y < new_diff.z || new_diff.z == 0.0) && new_diff.y != 0.0 {
@ -222,7 +223,7 @@ mod test {
let mem_size = p.get_buffer_mem_size(&data);
assert!(mem_size == 7);
let memory = vec![0; 7];
let mut memory = vec![0; 7];
assert!(!p.dirty);
p.insert_into_memory(memory, &data, &scene);
assert!(p.dirty);
@ -238,7 +239,7 @@ mod test {
let mem_size = p.get_buffer_mem_size(&data);
assert!(mem_size == 7);
let memory = vec![0; 6];
let mut memory = vec![0; 6];
assert!(!p.dirty);
p.insert_into_memory(memory, &data, &scene);
assert!(p.dirty);
@ -253,7 +254,7 @@ mod test {
let mem_size = p.get_buffer_mem_size(&data);
assert!(mem_size == 7);
let memory = vec![0; 7];
let mut memory = vec![0; 7];
assert!(!p.dirty);
p.insert_into_memory(memory, &data, &scene);
assert!(p.dirty);
@ -269,7 +270,7 @@ mod test {
let mem_size = p.get_buffer_mem_size(&data);
assert!(mem_size == 7);
let memory = vec![0; 6];
let mut memory = vec![0; 6];
assert!(!p.dirty);
p.insert_into_memory(memory, &data, &scene);
assert!(p.dirty);

View file

@ -1,3 +1,4 @@
use super::light::LightSource;
use super::AppData;
use super::Scene;

View file

@ -10,7 +10,7 @@ use light::{DirectionalLight, LightSource, PointLight};
use vulkanalia::prelude::v1_0::*;
use anyhow::Result;
use cgmath::Vector3;
use cgmath::{vec2, vec3, Vector3};
use std::cell::RefCell;
use std::rc::Rc;
@ -18,13 +18,15 @@ use std::rc::Rc;
use crate::scene::memorizable::{Memorizable, CompoundMemorizable};
use crate::app_data::AppData;
use crate::buffer;
use crate::primitives::rec_cuboid::Cuboid;
use crate::vertex;
use crate::primitives::cube::Cube;
use crate::primitives::drawable::Drawable;
use crate::scene::oct_tree::{OctTree, CHUNK_SIZE};
use crate::scene::oct_tree::{OctTree, OctTreeIter, CHUNK_SIZE};
use crate::scene::empty_volume::EmptyVolume;
extern crate rand;
use rand::Rng;
#[repr(C)]
#[derive(Clone, Debug, Default)]
@ -213,7 +215,6 @@ impl Scene {
let mut compute_task_one_out_size = 0;
let mut target_index = 1;
let mut node_count = 0;
let mut transparrent_index = 0;
for compound in &self.volumetrics {
// calculate the memory starts in the volumetrics memory
compound.borrow_mut().set_memory_start(compound_data_len);
@ -221,9 +222,6 @@ impl Scene {
// calculate the memory pos in the output memory
compound.borrow_mut().target_memory_start = target_index;
target_index += compound.borrow().get_target_buffer_mem_size();
// calculate the memory start for the transparency array
compound.borrow_mut().transparency_index = transparrent_index;
transparrent_index += compound.borrow().size.pow(3);
// calculate overall task sizes and oct tree node count
node_count += compound.borrow().get_num_nodes();
compute_task_one_size += compound.borrow().size.pow(2) as usize;

View file

@ -2,6 +2,7 @@ use crate::app_data::AppData;
use super::{Scene, memorizable::CompoundMemorizable};
use cgmath::{InnerSpace, Vector3};
use winit::dpi::Size;
use super::memorizable::Memorizable;
use std::cell::RefCell;
@ -40,12 +41,11 @@ pub struct ShapeComposition {
pub bbox_high: Vector3<f32>,
pub overlapping_volumes: Vec<u32>,
pub scale: f32,
pub transparency_index: u32,
}
impl ShapeComposition {
pub fn new(size: u32) -> Self {
Self { memory_start: 0, target_memory_start: 0, prev_memory_size: 0, size: size, included_shapes: vec![], excluded_shapes: vec![], dirty: true, bbox_low: Vector3 { x: 0.0, y: 0.0, z: 0.0 }, bbox_high: Vector3 { x: 0.0, y: 0.0, z: 0.0 }, scale: 0.0, overlapping_volumes: vec![], transparency_index: 0 }
Self { memory_start: 0, target_memory_start: 0, prev_memory_size: 0, size: size, included_shapes: vec![], excluded_shapes: vec![], dirty: true, bbox_low: Vector3 { x: 0.0, y: 0.0, z: 0.0 }, bbox_high: Vector3 { x: 0.0, y: 0.0, z: 0.0 }, scale: 0.0, overlapping_volumes: vec![] }
}
pub fn prepare_for_mem_insertion(&mut self) {
@ -100,8 +100,8 @@ impl CompoundMemorizable for ShapeComposition {
impl Memorizable for ShapeComposition {
fn get_buffer_mem_size(&self, data: &AppData) -> u32 {
//size, scale, memory_end, num_included, num_excluded, pos, target address, num_volumes, transparent start, included_address, excluded_address, overlapping volumes
1 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + self.included_shapes.len() as u32 + self.excluded_shapes.len() as u32 + self.overlapping_volumes.len() as u32
//size, scale, memory_end, num_included, num_excluded, pos, target address, num_volumes, included_address, excluded_address
1 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + self.included_shapes.len() as u32 + self.excluded_shapes.len() as u32 + self.overlapping_volumes.len() as u32
}
fn get_prev_buffer_mem_size(&self) -> u32 {
@ -129,7 +129,7 @@ impl Memorizable for ShapeComposition {
let mut shapes_memory = 0;
let shapes_index = self.memory_start + self.get_buffer_mem_size(data) as usize;
let mut element_offset = 11;
let mut element_offset = 10;
for volumetric in &self.included_shapes {
volumetric.borrow_mut().set_memory_start(shapes_index + shapes_memory);
shapes_memory += volumetric.borrow().get_buffer_mem_size(data) as usize;
@ -152,6 +152,7 @@ impl Memorizable for ShapeComposition {
element_offset += 1;
}
println!("Compound links to volumes:");
for volume_start in &self.overlapping_volumes {
v[self.memory_start + element_offset] = volume_start.clone();
element_offset += 1;
@ -166,8 +167,6 @@ impl Memorizable for ShapeComposition {
v[self.memory_start + 7] = u32::from_ne_bytes(self.bbox_low.z.to_ne_bytes());
v[self.memory_start + 8] = self.target_memory_start as u32;
v[self.memory_start + 9] = self.overlapping_volumes.len() as u32;
v[self.memory_start + 10] = self.transparency_index; // transparency mem start
println!("transparency index {}", self.transparency_index);
self.prev_memory_size = self.get_compound_buffer_mem_size(data);
self.dirty = false;

View file

@ -275,15 +275,14 @@ pub struct RTVolVertex {
pub volume_start: u32,
pub color_roughness: u32,
facing: Facing,
pub transparent: bool,
}
impl RTVolVertex {
pub const fn new(pos: Vec3, volume_start: u32, color_roughness: u32, facing: Facing, transparent: bool) -> Self {
Self { pos, volume_start, color_roughness, facing, transparent }
pub const fn new(pos: Vec3, volume_start: u32, color_roughness: u32, facing: Facing) -> Self {
Self { pos, volume_start, color_roughness, facing }
}
}
impl VertexContainer<5> for RTVolVertex {
impl VertexContainer<4> for RTVolVertex {
fn binding_description() -> vk::VertexInputBindingDescription {
vk::VertexInputBindingDescription::builder()
.binding(0)
@ -292,7 +291,7 @@ impl VertexContainer<5> for RTVolVertex {
.build()
}
fn attribute_descriptions() -> [vk::VertexInputAttributeDescription; 5] {
fn attribute_descriptions() -> [vk::VertexInputAttributeDescription; 4] {
let pos = vk::VertexInputAttributeDescription::builder()
.binding(0)
.location(0)
@ -321,14 +320,7 @@ impl VertexContainer<5> for RTVolVertex {
.offset((size_of::<Vec3>() + size_of::<u32>() * 2) as u32)
.build();
let flags = vk::VertexInputAttributeDescription::builder()
.binding(0)
.location(4)
.format(vk::Format::R32_UINT)
.offset((size_of::<Vec3>() + size_of::<u32>() * 3) as u32)
.build();
[pos, volume_start, color_roughness, facing, flags]
[pos, volume_start, color_roughness, facing]
}
}