clamp to quad
This commit is contained in:
parent
5bd181adc9
commit
1a30887a7d
7 changed files with 62 additions and 22 deletions
src
|
@ -24,28 +24,36 @@ impl Drawable for Quad {
|
|||
vec3(self.pos1.x as f32, self.pos1.y as f32, self.pos1.z as f32),
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 0, y: 0}),
|
||||
self.volume_index,
|
||||
self.facing
|
||||
self.facing,
|
||||
self.raster_pos,
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 1, y: 1}),
|
||||
));
|
||||
// 1 top right far
|
||||
scene.rt_vertices.push(vertex::RTVertex::new(
|
||||
vec3(self.pos2.x as f32, self.pos2.y as f32, self.pos2.z as f32),
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 0, y: 1}),
|
||||
self.volume_index,
|
||||
self.facing
|
||||
self.facing,
|
||||
self.raster_pos,
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 1, y: 1}),
|
||||
));
|
||||
// 2 top left near
|
||||
scene.rt_vertices.push(vertex::RTVertex::new(
|
||||
vec3(self.pos3.x as f32, self.pos3.y as f32, self.pos3.z as f32),
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 1, y: 1}),
|
||||
self.volume_index,
|
||||
self.facing
|
||||
self.facing,
|
||||
self.raster_pos,
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 1, y: 1}),
|
||||
));
|
||||
// 3 top right near
|
||||
scene.rt_vertices.push(vertex::RTVertex::new(
|
||||
vec3(self.pos4.x as f32, self.pos4.y as f32, self.pos4.z as f32),
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 1, y: 0}),
|
||||
self.volume_index,
|
||||
self.facing
|
||||
self.facing,
|
||||
self.raster_pos,
|
||||
self.raster_pos + self.size.mul_element_wise(cgmath::Vector2 {x: 1, y: 1}),
|
||||
));
|
||||
|
||||
// change node order while preserving texture coordinates
|
||||
|
|
|
@ -215,5 +215,5 @@ pub fn generate_test_scene2(scene: &mut Scene, data: &mut AppData, chunk_num_x:
|
|||
scene.directional_lights.push(Rc::new(RefCell::new(DirectionalLight { direction: vec3(0.0, 0.0, -1.0), color: vec3(0.1, 0.1, 0.1), memory_start: 0 })));
|
||||
scene.oct_trees = oct_trees;
|
||||
|
||||
Ok(cgmath::point3((max_x as f32 / 2.0) as f32, (max_y as f32 / 2.0) as f32, height_map[(max_x as f32 / 2.0).floor() as usize][(max_y as f32 / 2.0).floor() as usize] + 2.0))
|
||||
Ok(cgmath::point3((max_x as f32 / 2.0) as f32, (max_y as f32 / 2.0) as f32, height_map[(max_x as f32 / 2.0).floor() as usize][(max_y as f32 / 2.0).floor() as usize] + 2000.0))
|
||||
}
|
|
@ -181,14 +181,16 @@ pub struct RTVertex {
|
|||
pub raster_pos: cgmath::Vector2<u32>,
|
||||
pub volume_start: u32,
|
||||
facing: Facing,
|
||||
min_raster_pos: cgmath::Vector2<u32>,
|
||||
max_raster_pos: cgmath::Vector2<u32>,
|
||||
}
|
||||
|
||||
impl RTVertex {
|
||||
pub const fn new(pos: Vec3, raster_pos: cgmath::Vector2<u32>, volume_start: u32, facing: Facing) -> Self {
|
||||
Self { pos, raster_pos, volume_start, facing }
|
||||
pub const fn new(pos: Vec3, raster_pos: cgmath::Vector2<u32>, volume_start: u32, facing: Facing, min_raster_pos: cgmath::Vector2<u32>, max_raster_pos: cgmath::Vector2<u32>) -> Self {
|
||||
Self { pos, raster_pos, volume_start, facing, min_raster_pos, max_raster_pos }
|
||||
}
|
||||
}
|
||||
impl VertexContainer<4> for RTVertex {
|
||||
impl VertexContainer<6> for RTVertex {
|
||||
fn binding_description() -> vk::VertexInputBindingDescription {
|
||||
vk::VertexInputBindingDescription::builder()
|
||||
.binding(0)
|
||||
|
@ -197,7 +199,7 @@ impl VertexContainer<4> for RTVertex {
|
|||
.build()
|
||||
}
|
||||
|
||||
fn attribute_descriptions() -> [vk::VertexInputAttributeDescription; 4] {
|
||||
fn attribute_descriptions() -> [vk::VertexInputAttributeDescription; 6] {
|
||||
let pos = vk::VertexInputAttributeDescription::builder()
|
||||
.binding(0)
|
||||
.location(0)
|
||||
|
@ -226,7 +228,21 @@ impl VertexContainer<4> for RTVertex {
|
|||
.offset((size_of::<Vec3>() + size_of::<cgmath::Vector2<u32>>() + size_of::<u32>()) as u32)
|
||||
.build();
|
||||
|
||||
[pos, raster_pos, volume_start, facing]
|
||||
let min_raster_pos = vk::VertexInputAttributeDescription::builder()
|
||||
.binding(0)
|
||||
.location(4)
|
||||
.format(vk::Format::R32G32_UINT)
|
||||
.offset((size_of::<Vec3>() + size_of::<cgmath::Vector2<u32>>() + size_of::<u32>() + size_of::<u32>()) as u32)
|
||||
.build();
|
||||
|
||||
let max_raster_pos = vk::VertexInputAttributeDescription::builder()
|
||||
.binding(0)
|
||||
.location(5)
|
||||
.format(vk::Format::R32G32_UINT)
|
||||
.offset((size_of::<Vec3>() + size_of::<cgmath::Vector2<u32>>() + size_of::<u32>() + size_of::<u32>() + size_of::<cgmath::Vector2<u32>>()) as u32)
|
||||
.build();
|
||||
|
||||
[pos, raster_pos, volume_start, facing, min_raster_pos, max_raster_pos]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue