|
1 | 1 | use bytemuck::{Pod, Zeroable};
|
| 2 | +use std::collections::HashMap; |
2 | 3 |
|
3 | 4 | use super::block_type::BlockType;
|
4 | 5 | use crate::chunk::BlockVec;
|
| 6 | +use crate::effects::ao::{convert_ao_u8_to_f32, from_vertex_position}; |
5 | 7 | use crate::world::CHUNK_SIZE;
|
6 | 8 | use glam::Vec3;
|
7 | 9 | use std::sync::{Arc, MutexGuard, RwLock};
|
@@ -43,7 +45,7 @@ impl FaceDirections {
|
43 | 45 | pub fn create_face_data(
|
44 | 46 | &self,
|
45 | 47 | block: Arc<RwLock<Block>>,
|
46 |
| - blocks: &BlockVec, |
| 48 | + blocks: &Vec<((i32, i32), BlockVec)>, |
47 | 49 | ) -> (Vec<BlockVertexData>, Vec<u32>) {
|
48 | 50 | let indices = self.get_indices();
|
49 | 51 |
|
@@ -74,13 +76,19 @@ impl FaceDirections {
|
74 | 76 | let normals = self.get_normal_vector();
|
75 | 77 |
|
76 | 78 | 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 | + |
77 | 85 | vertex_data.push(BlockVertexData {
|
78 | 86 | position: [
|
79 | 87 | CUBE_VERTEX[(*index as usize * 3 + 0) as usize] + block_read.position.x,
|
80 | 88 | CUBE_VERTEX[(*index as usize * 3 + 1) as usize] + block_read.position.y,
|
81 | 89 | CUBE_VERTEX[(*index as usize * 3 + 2) as usize] + block_read.position.z,
|
82 | 90 | ],
|
83 |
| - ao: 0.0, |
| 91 | + ao: convert_ao_u8_to_f32(from_vertex_position(&vertex_position, &blocks)), |
84 | 92 | normal: normals.into(),
|
85 | 93 | tex_coords: face_texcoords[i],
|
86 | 94 | })
|
@@ -166,6 +174,12 @@ impl Block {
|
166 | 174 | offset: std::mem::size_of::<[f32; 6]>() as wgpu::BufferAddress,
|
167 | 175 | shader_location: 2,
|
168 | 176 | },
|
| 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 | + }, |
169 | 183 | ],
|
170 | 184 | }
|
171 | 185 | }
|
|
0 commit comments