Compare commits
No commits in common. "master" and "volumetrics" have entirely different histories.
master
...
volumetric
28 changed files with 140 additions and 309 deletions
build.rs
shaders
compile.batcompile.sh
compiled
frag_rt_quad.spvfrag_volumetric.spvrt_compute_mempos.spvrt_compute_rasterize.spvrt_compute_visible.spvvert_volumetric.spv
rt_compute_mempos.comprt_compute_rasterize.comprt_compute_visible.comprt_quad.fragrt_quad_placeholder.fragvolumetric.fragvolumetric.vertvolumetric_placeholder.fragsrc
4
build.rs
4
build.rs
|
@ -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(());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -67,120 +67,103 @@ vec3 unpack_color(uint val) {
|
|||
return vec3(val4 / 255.0, val3 / 255.0, val2 / 255.0);
|
||||
}
|
||||
|
||||
void add_cube(uint cube_num, float scale, vec3 pos, uint color, uint start_volume, bool transparent) {
|
||||
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
|
||||
|
@ -244,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++) {
|
||||
|
@ -388,81 +381,37 @@ void main() {
|
|||
//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)]);
|
||||
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)]);
|
||||
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)]);
|
||||
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)]);
|
||||
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)]);
|
||||
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)]);
|
||||
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)]);
|
||||
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)]);
|
||||
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 {
|
||||
|
|
|
@ -13,7 +13,7 @@ layout(binding = 3) readonly buffer CompoundBuffer {
|
|||
uint compounds[];
|
||||
};
|
||||
|
||||
layout(binding = 8) buffer SceneInfoBuffer2 {
|
||||
layout(binding = 4) buffer SceneInfoBuffer2 {
|
||||
uint grid[];
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -484,9 +484,12 @@ 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 = 70;
|
||||
uint max_check_it = 80;
|
||||
uint prev_child = 0;
|
||||
uint prev_prev_child = 0;
|
||||
|
||||
|
@ -887,14 +890,14 @@ void main() {
|
|||
//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);
|
||||
//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_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;
|
||||
|
@ -902,7 +905,7 @@ void main() {
|
|||
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);
|
||||
//color_sum = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_sum);
|
||||
}
|
||||
|
||||
outColor = vec4(color_sum, 1.0);
|
||||
|
|
|
@ -29,14 +29,14 @@ void main() {
|
|||
//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);
|
||||
//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_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;
|
||||
|
@ -44,7 +44,7 @@ void main() {
|
|||
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);
|
||||
//color_sum = add_reflection(normalize(clamped_pos - ubo.camera_pos), facing, fragVolumeStart, clamped_pos, color_roughness, color_sum);
|
||||
}
|
||||
|
||||
outColor = vec4(color_sum, 1.0);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -483,9 +482,12 @@ 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 = 70;
|
||||
uint max_check_it = 80;
|
||||
uint prev_child = 0;
|
||||
uint prev_prev_child = 0;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -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
|
||||
|
@ -491,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);
|
||||
|
@ -897,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
|
||||
|
@ -908,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
|
||||
|
@ -1121,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);
|
||||
|
@ -1141,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];
|
||||
|
@ -1153,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);
|
||||
|
@ -1174,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(())
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -137,11 +137,11 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<Poin
|
|||
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(5.0, 5.0, 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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use super::light::LightSource;
|
||||
use super::AppData;
|
||||
use super::Scene;
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
@ -151,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;
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue