Merge branch 'master' into lunex
This commit is contained in:
@@ -41,9 +41,9 @@ pub const HEX_NORMALS: [Vec3; 6] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
pub const ATTRIBUTE_PACKED_VERTEX_DATA: MeshVertexAttribute =
|
pub const ATTRIBUTE_PACKED_VERTEX_DATA: MeshVertexAttribute =
|
||||||
MeshVertexAttribute::new("PackedVertexData", 988540817, VertexFormat::Uint32);
|
MeshVertexAttribute::new("PackedVertexData", 7, VertexFormat::Uint32);
|
||||||
pub const ATTRIBUTE_VERTEX_HEIGHT: MeshVertexAttribute =
|
pub const ATTRIBUTE_VERTEX_HEIGHT: MeshVertexAttribute =
|
||||||
MeshVertexAttribute::new("VertexHeight", 988540717, VertexFormat::Float32);
|
MeshVertexAttribute::new("VertexHeight", 8, VertexFormat::Float32);
|
||||||
|
|
||||||
pub const ATTRIBUTE_TEXTURE_INDEX: MeshVertexAttribute =
|
pub const ATTRIBUTE_TEXTURE_INDEX: MeshVertexAttribute =
|
||||||
MeshVertexAttribute::new("TextureIndex", 988540917, VertexFormat::Uint32);
|
MeshVertexAttribute::new("TextureIndex", 988540917, VertexFormat::Uint32);
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
use crate::hex_utils::HexCoord;
|
use crate::hex_utils::{offset3d_to_world, HexCoord};
|
||||||
use crate::map::biome_map::BiomeChunk;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::tile_manager::TileAsset;
|
|
||||||
use crate::tile_mapper::TileMapperAsset;
|
|
||||||
use crate::{biome_asset::BiomeAsset, biome_painter::BiomePainterAsset};
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::{
|
render::{
|
||||||
@@ -12,15 +8,7 @@ use bevy::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn generate_packed_chunk_mesh(
|
pub fn generate_packed_chunk_mesh(chunk: &MeshChunkData) -> Mesh {
|
||||||
chunk: &Chunk,
|
|
||||||
map: &Map,
|
|
||||||
biome_chunk: &BiomeChunk,
|
|
||||||
painter: &BiomePainterAsset,
|
|
||||||
tiles: &Res<Assets<TileAsset>>,
|
|
||||||
biomes: &Res<Assets<BiomeAsset>>,
|
|
||||||
mappers: &Res<Assets<TileMapperAsset>>,
|
|
||||||
) -> Mesh {
|
|
||||||
let vertex_count: usize = Chunk::SIZE * Chunk::SIZE * 6;
|
let vertex_count: usize = Chunk::SIZE * Chunk::SIZE * 6;
|
||||||
let mut packed_data = Vec::with_capacity(vertex_count);
|
let mut packed_data = Vec::with_capacity(vertex_count);
|
||||||
let mut indices = Vec::with_capacity(vertex_count);
|
let mut indices = Vec::with_capacity(vertex_count);
|
||||||
@@ -28,16 +16,10 @@ pub fn generate_packed_chunk_mesh(
|
|||||||
|
|
||||||
for z in 0..Chunk::SIZE {
|
for z in 0..Chunk::SIZE {
|
||||||
for x in 0..Chunk::SIZE {
|
for x in 0..Chunk::SIZE {
|
||||||
let height = chunk.heights[x + z * Chunk::SIZE];
|
let idx = x + z * Chunk::SIZE;
|
||||||
let data = biome_chunk.data[x + z * Chunk::SIZE];
|
let height = chunk.heights[idx];
|
||||||
let coord =
|
let coord = HexCoord::from_grid_pos(x, z);
|
||||||
HexCoord::from_offset(IVec2::new(x as i32, z as i32) + (chunk.chunk_offset * Chunk::SIZE as i32));
|
let n = chunk.get_neighbors(&coord);
|
||||||
let n = map.get_neighbors(&coord);
|
|
||||||
let biome = biomes.get(painter.sample_biome(biomes, &data)).unwrap();
|
|
||||||
|
|
||||||
let mapper = mappers.get(biome.tile_mapper.id());
|
|
||||||
let tile_handle = mapper.unwrap().sample_tile(height);
|
|
||||||
let tile = tiles.get(tile_handle).unwrap();
|
|
||||||
|
|
||||||
create_packed_tile(
|
create_packed_tile(
|
||||||
UVec2::new(x as u32, z as u32),
|
UVec2::new(x as u32, z as u32),
|
||||||
@@ -46,8 +28,8 @@ pub fn generate_packed_chunk_mesh(
|
|||||||
&mut packed_data,
|
&mut packed_data,
|
||||||
&mut indices,
|
&mut indices,
|
||||||
&mut heights,
|
&mut heights,
|
||||||
tile.texture_id,
|
chunk.textures[idx][0],
|
||||||
tile.side_texture_id,
|
chunk.textures[idx][1],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +47,7 @@ pub fn generate_packed_chunk_mesh(
|
|||||||
fn create_packed_tile(
|
fn create_packed_tile(
|
||||||
offset: UVec2,
|
offset: UVec2,
|
||||||
height: f32,
|
height: f32,
|
||||||
neighbors: &[Option<f32>; 6],
|
neighbors: &[f32; 6],
|
||||||
packed_data: &mut Vec<u32>,
|
packed_data: &mut Vec<u32>,
|
||||||
indices: &mut Vec<u32>,
|
indices: &mut Vec<u32>,
|
||||||
heights: &mut Vec<f32>,
|
heights: &mut Vec<f32>,
|
||||||
@@ -85,23 +67,18 @@ fn create_packed_tile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..neighbors.len() {
|
for i in 0..neighbors.len() {
|
||||||
let cur_n = neighbors[i];
|
let n_height = neighbors[i];
|
||||||
match cur_n {
|
if n_height < height {
|
||||||
Some(n_height) => {
|
create_packed_tile_wall(
|
||||||
if n_height < height {
|
offset,
|
||||||
create_packed_tile_wall(
|
height,
|
||||||
offset,
|
n_height,
|
||||||
height,
|
i,
|
||||||
n_height,
|
packed_data,
|
||||||
i,
|
indices,
|
||||||
packed_data,
|
heights,
|
||||||
indices,
|
side_texture_index,
|
||||||
heights,
|
);
|
||||||
side_texture_index,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule game/main/assets updated: 3606ca0324...4082df18e0
@@ -14,6 +14,7 @@ mod prelude;
|
|||||||
mod shader_extensions;
|
mod shader_extensions;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod utlis;
|
mod utlis;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use bevy::log::*;
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
pbr::{ExtendedMaterial, NotShadowCaster},
|
pbr::{ExtendedMaterial, NotShadowCaster},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
render::render_resource::{ColorTargetState, FragmentState, RenderPipelineDescriptor},
|
||||||
};
|
};
|
||||||
use bevy_asset_loader::prelude::*;
|
use bevy_asset_loader::prelude::*;
|
||||||
|
|
||||||
@@ -219,6 +220,7 @@ fn spawn_map(
|
|||||||
) {
|
) {
|
||||||
paint_map(&mut heightmap, &biome_painter, &tile_assets, &tile_mappers);
|
paint_map(&mut heightmap, &biome_painter, &tile_assets, &tile_mappers);
|
||||||
|
|
||||||
|
//Prepare Mesh Data
|
||||||
let map_size = UVec2::new(heightmap.width as u32, heightmap.height as u32);
|
let map_size = UVec2::new(heightmap.width as u32, heightmap.height as u32);
|
||||||
let chunk_meshes: Vec<_> = heightmap
|
let chunk_meshes: Vec<_> = heightmap
|
||||||
.chunks
|
.chunks
|
||||||
@@ -236,6 +238,8 @@ fn spawn_map(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut registry = PhosChunkRegistry::new(chunk_meshes.len());
|
let mut registry = PhosChunkRegistry::new(chunk_meshes.len());
|
||||||
|
|
||||||
|
//Spawn Chunks
|
||||||
{
|
{
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
let _spawn_span = info_span!("Spawn Chunks").entered();
|
let _spawn_span = info_span!("Spawn Chunks").entered();
|
||||||
@@ -277,20 +281,6 @@ fn spawn_map(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// commands.spawn((
|
|
||||||
// MaterialMeshBundle {
|
|
||||||
// transform: Transform::from_translation(heightmap.get_center()),
|
|
||||||
// mesh: meshes.add(
|
|
||||||
// Plane3d::default()
|
|
||||||
// .mesh()
|
|
||||||
// .size(heightmap.get_world_width(), heightmap.get_world_height()),
|
|
||||||
// ),
|
|
||||||
// material: atlas.water_material.clone(),
|
|
||||||
// ..default()
|
|
||||||
// },
|
|
||||||
// NotShadowCaster,
|
|
||||||
// ));
|
|
||||||
|
|
||||||
commands.insert_resource(registry);
|
commands.insert_resource(registry);
|
||||||
generator_state.set(GeneratorState::Idle);
|
generator_state.set(GeneratorState::Idle);
|
||||||
if cur_game_state.get() != &MenuState::InGame {
|
if cur_game_state.get() != &MenuState::InGame {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use bevy::asset::{Asset, Handle};
|
use bevy::asset::{Asset, Handle};
|
||||||
use bevy::pbr::MaterialExtension;
|
use bevy::pbr::{Material, MaterialExtension};
|
||||||
use bevy::reflect::TypePath;
|
use bevy::reflect::TypePath;
|
||||||
|
use bevy::render::mesh::{MeshVertexAttribute, MeshVertexBufferLayoutRef};
|
||||||
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
||||||
use bevy::render::texture::Image;
|
use bevy::render::texture::Image;
|
||||||
|
use world_generation::consts::{ATTRIBUTE_PACKED_VERTEX_DATA, ATTRIBUTE_VERTEX_HEIGHT};
|
||||||
|
|
||||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||||
pub struct ChunkMaterial {
|
pub struct ChunkMaterial {
|
||||||
@@ -15,25 +17,50 @@ impl MaterialExtension for ChunkMaterial {
|
|||||||
fn fragment_shader() -> ShaderRef {
|
fn fragment_shader() -> ShaderRef {
|
||||||
"shaders/world/chunk.wgsl".into()
|
"shaders/world/chunk.wgsl".into()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fn vertex_shader() -> ShaderRef {
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||||
|
pub struct PackedChunkMaterial {
|
||||||
|
#[texture(100, dimension = "2d_array")]
|
||||||
|
#[sampler(101)]
|
||||||
|
pub array_texture: Handle<Image>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Material for PackedChunkMaterial {
|
||||||
|
fn fragment_shader() -> ShaderRef {
|
||||||
|
"shaders/world/chunk.wgsl".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vertex_shader() -> ShaderRef {
|
||||||
|
"shaders/world/chunk_packed.wgsl".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prepass_vertex_shader() -> ShaderRef {
|
||||||
|
"shaders/world/chunk_packed.wgsl".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn deferred_vertex_shader() -> ShaderRef {
|
||||||
// "shaders/world/chunk_packed.wgsl".into()
|
// "shaders/world/chunk_packed.wgsl".into()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// fn specialize(
|
// fn opaque_render_method(&self) -> bevy::pbr::OpaqueRendererMethod {
|
||||||
// _pipeline: &bevy::pbr::MaterialExtensionPipeline,
|
// return OpaqueRendererMethod::Auto;
|
||||||
// descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
|
|
||||||
// layout: &bevy::render::mesh::MeshVertexBufferLayout,
|
|
||||||
// _key: bevy::pbr::MaterialExtensionKey<Self>,
|
|
||||||
// ) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> {
|
|
||||||
// let vertex_layout = layout.get_layout(&[
|
|
||||||
// // Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
|
||||||
// // Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
|
||||||
// // Mesh::ATTRIBUTE_NORMAL.at_shader_location(2),
|
|
||||||
// ATTRIBUTE_PACKED_VERTEX_DATA.at_shader_location(7),
|
|
||||||
// ATTRIBUTE_VERTEX_HEIGHT.at_shader_location(8),
|
|
||||||
// ])?;
|
|
||||||
// descriptor.vertex.buffers = vec![vertex_layout];
|
|
||||||
// Ok(())
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
fn specialize(
|
||||||
|
_pipeline: &bevy::pbr::MaterialPipeline<Self>,
|
||||||
|
descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
|
||||||
|
layout: &MeshVertexBufferLayoutRef,
|
||||||
|
_key: bevy::pbr::MaterialPipelineKey<Self>,
|
||||||
|
) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> {
|
||||||
|
let vertex_layout = layout.0.get_layout(&[
|
||||||
|
// Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
|
||||||
|
// Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
|
||||||
|
// Mesh::ATTRIBUTE_NORMAL.at_shader_location(2),
|
||||||
|
ATTRIBUTE_PACKED_VERTEX_DATA.at_shader_location(7),
|
||||||
|
ATTRIBUTE_VERTEX_HEIGHT.at_shader_location(8),
|
||||||
|
])?;
|
||||||
|
descriptor.vertex.buffers = vec![vertex_layout];
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use world_generation::{
|
|||||||
generators::{
|
generators::{
|
||||||
chunk_colliders::generate_chunk_collider,
|
chunk_colliders::generate_chunk_collider,
|
||||||
mesh_generator::{generate_chunk_mesh, generate_chunk_water_mesh},
|
mesh_generator::{generate_chunk_mesh, generate_chunk_water_mesh},
|
||||||
|
packed_mesh_generator::generate_packed_chunk_mesh,
|
||||||
},
|
},
|
||||||
hex_utils::offset_to_world,
|
hex_utils::offset_to_world,
|
||||||
prelude::{Chunk, Map, MeshChunkData},
|
prelude::{Chunk, Map, MeshChunkData},
|
||||||
|
|||||||
Reference in New Issue
Block a user