Skip to content

Commit bca1ba4

Browse files
committed
feat: ao
1 parent 4ebb2a4 commit bca1ba4

File tree

13 files changed

+283
-177
lines changed

13 files changed

+283
-177
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ glam = { version = "0.24.2", features = ["bytemuck"] }
1717
obj-rs = "0.7.1"
1818
lazy_static = "1.4.0"
1919
rand = "0.8.5"
20+
num-traits = "0.2.18"
2021

2122
[dependencies.image]
2223
version = "0.24.7"

src/blocks/block.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use bytemuck::{Pod, Zeroable};
2+
use std::collections::HashMap;
23

34
use super::block_type::BlockType;
45
use crate::chunk::BlockVec;
6+
use crate::effects::ao::{convert_ao_u8_to_f32, from_vertex_position};
57
use crate::world::CHUNK_SIZE;
68
use glam::Vec3;
79
use std::sync::{Arc, MutexGuard, RwLock};
@@ -43,7 +45,7 @@ impl FaceDirections {
4345
pub fn create_face_data(
4446
&self,
4547
block: Arc<RwLock<Block>>,
46-
blocks: &BlockVec,
48+
blocks: &Vec<((i32, i32), BlockVec)>,
4749
) -> (Vec<BlockVertexData>, Vec<u32>) {
4850
let indices = self.get_indices();
4951

@@ -74,13 +76,19 @@ impl FaceDirections {
7476
let normals = self.get_normal_vector();
7577

7678
unique_indices.iter().enumerate().for_each(|(i, index)| {
79+
let vertex_position = glam::vec3(
80+
CUBE_VERTEX[(*index as usize * 3 + 0) as usize] + block_read.absolute_position.x,
81+
CUBE_VERTEX[(*index as usize * 3 + 1) as usize] + block_read.absolute_position.y,
82+
CUBE_VERTEX[(*index as usize * 3 + 2) as usize] + block_read.absolute_position.z,
83+
);
84+
7785
vertex_data.push(BlockVertexData {
7886
position: [
7987
CUBE_VERTEX[(*index as usize * 3 + 0) as usize] + block_read.position.x,
8088
CUBE_VERTEX[(*index as usize * 3 + 1) as usize] + block_read.position.y,
8189
CUBE_VERTEX[(*index as usize * 3 + 2) as usize] + block_read.position.z,
8290
],
83-
ao: 0.0,
91+
ao: convert_ao_u8_to_f32(from_vertex_position(&vertex_position, &blocks)),
8492
normal: normals.into(),
8593
tex_coords: face_texcoords[i],
8694
})
@@ -166,6 +174,12 @@ impl Block {
166174
offset: std::mem::size_of::<[f32; 6]>() as wgpu::BufferAddress,
167175
shader_location: 2,
168176
},
177+
// Ao
178+
wgpu::VertexAttribute {
179+
format: wgpu::VertexFormat::Float32,
180+
offset: std::mem::size_of::<[f32; 8]>() as wgpu::BufferAddress,
181+
shader_location: 3,
182+
},
169183
],
170184
}
171185
}

0 commit comments

Comments
 (0)