normal rabbit
This commit is contained in:
+3
-3
@@ -2,9 +2,9 @@ use std::{fs::read_dir, io::Write, process::Command};
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
//let mut output = std::fs::File::create("output.txt").unwrap();
|
//let mut output = std::fs::File::create("output.txt").unwrap();
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo::rerun-if-changed=build.rs");
|
||||||
println!("cargo:rerun-if-changed=Cargo.lock");
|
println!("cargo::rerun-if-changed=Cargo.lock");
|
||||||
println!("cargo:rerun-if-changed=assemble_trace.py");
|
println!("cargo::rerun-if-changed=assemble_trace.py");
|
||||||
|
|
||||||
let paths = read_dir("src/shaders").unwrap();
|
let paths = read_dir("src/shaders").unwrap();
|
||||||
for path in paths {
|
for path in paths {
|
||||||
|
|||||||
+36
-4
@@ -535,6 +535,8 @@ impl App {
|
|||||||
},
|
},
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
let memory_allocator: Arc<dyn MemoryAllocator> = memory_allocator;
|
||||||
|
|
||||||
let pipeline_cache = get_pipeline_cache(device.clone());
|
let pipeline_cache = get_pipeline_cache(device.clone());
|
||||||
|
|
||||||
let mut gstate = GState::default();
|
let mut gstate = GState::default();
|
||||||
@@ -1108,8 +1110,22 @@ impl ApplicationHandler for App {
|
|||||||
WindowEvent::ScaleFactorChanged { .. } => {
|
WindowEvent::ScaleFactorChanged { .. } => {
|
||||||
rcx.recreate_swapchain = true;
|
rcx.recreate_swapchain = true;
|
||||||
},
|
},
|
||||||
WindowEvent::DroppedFile(_file) => {
|
WindowEvent::DroppedFile(path) => {
|
||||||
todo!()
|
if let Ok(file) = std::fs::File::open(path) {
|
||||||
|
if let Ok(mut mesh) = load_obj(
|
||||||
|
&self.memory_allocator,
|
||||||
|
&mut std::io::BufReader::new(file),
|
||||||
|
path.file_name().unwrap().to_string_lossy().into_owned(),
|
||||||
|
BufferUsage::SHADER_DEVICE_ADDRESS
|
||||||
|
| BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY,
|
||||||
|
) {
|
||||||
|
self.gstate.meshes.append(&mut mesh);
|
||||||
|
} else {
|
||||||
|
error!("Could not read .obj {}", path.display());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error!("Could not open path {}", path.display());
|
||||||
|
}
|
||||||
},
|
},
|
||||||
WindowEvent::MouseInput {
|
WindowEvent::MouseInput {
|
||||||
device_id: d,
|
device_id: d,
|
||||||
@@ -1317,6 +1333,7 @@ impl App {
|
|||||||
Arc<DescriptorSet>,
|
Arc<DescriptorSet>,
|
||||||
Arc<DescriptorSet>,
|
Arc<DescriptorSet>,
|
||||||
Arc<DescriptorSet>,
|
Arc<DescriptorSet>,
|
||||||
|
Arc<DescriptorSet>,
|
||||||
) {
|
) {
|
||||||
let trace_set1 = if self.csg_count > 0 {
|
let trace_set1 = if self.csg_count > 0 {
|
||||||
let trace_layout = &self.gstate.csg[0]
|
let trace_layout = &self.gstate.csg[0]
|
||||||
@@ -1450,6 +1467,18 @@ impl App {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let rt_layout4 = &rcx.rt_pipeline.layout().set_layouts()[3];
|
||||||
|
let rt_set4 = DescriptorSet::new(
|
||||||
|
self.descriptor_set_allocator.clone(),
|
||||||
|
rt_layout4.clone(),
|
||||||
|
[
|
||||||
|
WriteDescriptorSet::buffer(0, self.gstate.meshes[0].vertices.clone()),
|
||||||
|
WriteDescriptorSet::buffer(1, self.gstate.meshes[0].indices.clone()),
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
(
|
(
|
||||||
trace_set1,
|
trace_set1,
|
||||||
normals_set1,
|
normals_set1,
|
||||||
@@ -1459,6 +1488,7 @@ impl App {
|
|||||||
rt_set1,
|
rt_set1,
|
||||||
rt_set2,
|
rt_set2,
|
||||||
rt_set3,
|
rt_set3,
|
||||||
|
rt_set4,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1579,13 +1609,14 @@ impl App {
|
|||||||
rt_set1: Arc<DescriptorSet>,
|
rt_set1: Arc<DescriptorSet>,
|
||||||
rt_set2: Arc<DescriptorSet>,
|
rt_set2: Arc<DescriptorSet>,
|
||||||
rt_set3: Arc<DescriptorSet>,
|
rt_set3: Arc<DescriptorSet>,
|
||||||
|
rt_set4: Arc<DescriptorSet>,
|
||||||
) {
|
) {
|
||||||
builder
|
builder
|
||||||
.bind_descriptor_sets(
|
.bind_descriptor_sets(
|
||||||
PipelineBindPoint::RayTracing,
|
PipelineBindPoint::RayTracing,
|
||||||
rcx.rt_pipeline.layout().clone(),
|
rcx.rt_pipeline.layout().clone(),
|
||||||
0,
|
0,
|
||||||
vec![rt_set1, rt_set2, rt_set3],
|
vec![rt_set1, rt_set2, rt_set3, rt_set4],
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_pipeline_ray_tracing(rcx.rt_pipeline.clone())
|
.bind_pipeline_ray_tracing(rcx.rt_pipeline.clone())
|
||||||
@@ -1995,6 +2026,7 @@ impl App {
|
|||||||
rt_set1,
|
rt_set1,
|
||||||
rt_set2,
|
rt_set2,
|
||||||
rt_set3,
|
rt_set3,
|
||||||
|
rt_set4,
|
||||||
) = self.get_descriptor_sets(rcx, image_index);
|
) = self.get_descriptor_sets(rcx, image_index);
|
||||||
|
|
||||||
let mut builder = AutoCommandBufferBuilder::primary(
|
let mut builder = AutoCommandBufferBuilder::primary(
|
||||||
@@ -2017,7 +2049,7 @@ impl App {
|
|||||||
let mut futures = camera_and_lights.boxed();
|
let mut futures = camera_and_lights.boxed();
|
||||||
|
|
||||||
if RUN_RT_PIPELINE {
|
if RUN_RT_PIPELINE {
|
||||||
self.add_commands_raytrace(&mut builder, rcx, rt_set1, rt_set2, rt_set3);
|
self.add_commands_raytrace(&mut builder, rcx, rt_set1, rt_set2, rt_set3, rt_set4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if RUN_STANDARD_PIPELINE {
|
if RUN_STANDARD_PIPELINE {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use vulkano::{
|
|||||||
buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer},
|
buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer},
|
||||||
descriptor_set::DescriptorSet,
|
descriptor_set::DescriptorSet,
|
||||||
memory::allocator::{
|
memory::allocator::{
|
||||||
AllocationCreateInfo, MemoryAllocatePreference, MemoryTypeFilter, StandardMemoryAllocator,
|
AllocationCreateInfo, MemoryAllocatePreference, MemoryAllocator, MemoryTypeFilter,
|
||||||
},
|
},
|
||||||
pipeline::{GraphicsPipeline, graphics::vertex_input::Vertex},
|
pipeline::{GraphicsPipeline, graphics::vertex_input::Vertex},
|
||||||
shader::ShaderModule,
|
shader::ShaderModule,
|
||||||
@@ -61,7 +61,7 @@ pub(crate) struct CSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn load_obj(
|
pub(crate) fn load_obj(
|
||||||
memory_allocator: &Arc<StandardMemoryAllocator>,
|
memory_allocator: &Arc<dyn MemoryAllocator>,
|
||||||
input: &mut dyn Read,
|
input: &mut dyn Read,
|
||||||
name: String,
|
name: String,
|
||||||
additional_usage: BufferUsage,
|
additional_usage: BufferUsage,
|
||||||
@@ -104,7 +104,7 @@ pub(crate) fn load_obj(
|
|||||||
let vertex_buffer = Buffer::from_iter(
|
let vertex_buffer = Buffer::from_iter(
|
||||||
memory_allocator.clone(),
|
memory_allocator.clone(),
|
||||||
BufferCreateInfo {
|
BufferCreateInfo {
|
||||||
usage: BufferUsage::VERTEX_BUFFER | additional_usage,
|
usage: BufferUsage::STORAGE_BUFFER | additional_usage,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
AllocationCreateInfo {
|
AllocationCreateInfo {
|
||||||
@@ -120,7 +120,7 @@ pub(crate) fn load_obj(
|
|||||||
let index_buffer = Buffer::from_iter(
|
let index_buffer = Buffer::from_iter(
|
||||||
memory_allocator.clone(),
|
memory_allocator.clone(),
|
||||||
BufferCreateInfo {
|
BufferCreateInfo {
|
||||||
usage: BufferUsage::INDEX_BUFFER | additional_usage,
|
usage: BufferUsage::STORAGE_BUFFER | additional_usage,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
AllocationCreateInfo {
|
AllocationCreateInfo {
|
||||||
|
|||||||
@@ -11,34 +11,32 @@ struct OVertex {
|
|||||||
vec4 normal;
|
vec4 normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(set = 3, binding = 0, std140) restrict readonly buffer Verts {
|
layout(set = 3, binding = 0, std430) restrict readonly buffer Verts {
|
||||||
OVertex verts[];
|
OVertex verts[];
|
||||||
} verts;
|
} verts;
|
||||||
|
|
||||||
layout(set = 3, binding = 1, std140) restrict readonly buffer Indicies {
|
layout(set = 3, binding = 1, std430) restrict readonly buffer Indicies {
|
||||||
uint indicies[];
|
uint indicies[];
|
||||||
} indicies;
|
} indicies;
|
||||||
|
|
||||||
|
OVertex load_vert(uint index) {
|
||||||
|
return verts.verts[indicies.indicies[index]];
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// get mesh vertex data in object space
|
// get mesh vertex data in object space
|
||||||
vec3 p0, p1, p2;
|
OVertex v0 = load_vert((gl_PrimitiveID * 3) + 0);
|
||||||
//gsnGetPositions(gl_InstanceID, gl_PrimitiveID, p0, p1, p2);
|
OVertex v1 = load_vert((gl_PrimitiveID * 3) + 1);
|
||||||
vec3 n0, n1, n2;
|
OVertex v2 = load_vert((gl_PrimitiveID * 3) + 2);
|
||||||
//gsnGetNormals(gl_InstanceID, gl_PrimitiveID, n0, n1, n2);
|
|
||||||
vec2 t0, t1, t2;
|
|
||||||
//gsnGetTexCoords(gl_InstanceID, gl_PrimitiveID, t0, t1, t2);
|
|
||||||
|
|
||||||
// interpolate with barycentric coordinates
|
// interpolate with barycentric coordinates
|
||||||
vec3 barys = vec3(1.0f - baryCoord.x - baryCoord.y, baryCoord.x, baryCoord.y);
|
vec3 barys = vec3(1.0f - baryCoord.x - baryCoord.y, baryCoord.x, baryCoord.y);
|
||||||
vec3 localNormal = normalize(n0 * barys.x + n1 * barys.y + n2 * barys.z);
|
vec3 localNormal = normalize(v0.normal * barys.x + v1.normal * barys.y + v2.normal * barys.z).xyz;
|
||||||
vec3 localPosition = p0 * barys.x + p1 * barys.y + p2 * barys.z;
|
vec3 localPosition = (v0.pos * barys.x + v1.pos * barys.y + v2.pos * barys.z).xyz;
|
||||||
vec2 texCoords = t0 * barys.x + t1 * barys.y + t2 * barys.z;
|
|
||||||
|
|
||||||
// transform to world space
|
// transform to world space
|
||||||
mat3 normalMat;
|
vec3 normal = normalize((gl_ObjectToWorldEXT * vec4(localNormal, 1.0)).xyz);
|
||||||
//gsnGetNormal3x3Matrix(gl_InstanceID, normalMat);
|
|
||||||
vec3 normal = normalize(normalMat * localNormal);
|
|
||||||
vec3 position = gl_ObjectToWorldEXT * vec4(localPosition, 1.0);
|
vec3 position = gl_ObjectToWorldEXT * vec4(localPosition, 1.0);
|
||||||
|
|
||||||
hit_value = normal;
|
hit_value = normal * 0.5 + 0.5;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user