packed testing
This commit is contained in:
Submodule game/main/assets updated: 3606ca0324...4082df18e0
@@ -3,6 +3,7 @@ use bevy::log::*;
|
||||
use bevy::{
|
||||
pbr::{ExtendedMaterial, NotShadowCaster},
|
||||
prelude::*,
|
||||
render::render_resource::{ColorTargetState, FragmentState, RenderPipelineDescriptor},
|
||||
};
|
||||
use bevy_asset_loader::prelude::*;
|
||||
|
||||
@@ -49,7 +50,7 @@ impl Plugin for MapInitPlugin {
|
||||
app.add_plugins((
|
||||
ChunkRebuildPlugin,
|
||||
// TerraFormingTestPlugin,
|
||||
MaterialPlugin::<ExtendedMaterial<StandardMaterial, ChunkMaterial>>::default(),
|
||||
MaterialPlugin::<ChunkMaterial>::default(),
|
||||
MaterialPlugin::<ExtendedMaterial<StandardMaterial, WaterMaterial>> {
|
||||
prepass_enabled: false,
|
||||
..Default::default()
|
||||
@@ -122,7 +123,7 @@ fn finalize_biome_painter(
|
||||
fn finalize_texture(
|
||||
mut atlas: ResMut<PhosAssets>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
mut chunk_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, ChunkMaterial>>>,
|
||||
mut chunk_materials: ResMut<Assets<ChunkMaterial>>,
|
||||
mut next_load_state: ResMut<NextState<AssetLoadState>>,
|
||||
) {
|
||||
let image = images.get_mut(atlas.handle.id()).unwrap();
|
||||
@@ -130,11 +131,8 @@ fn finalize_texture(
|
||||
let array_layers = image.height() / image.width();
|
||||
image.reinterpret_stacked_2d_as_array(array_layers);
|
||||
|
||||
let chunk_material = chunk_materials.add(ExtendedMaterial {
|
||||
base: StandardMaterial::default(),
|
||||
extension: ChunkMaterial {
|
||||
array_texture: atlas.handle.clone(),
|
||||
},
|
||||
let chunk_material = chunk_materials.add(ChunkMaterial {
|
||||
array_texture: atlas.handle.clone(),
|
||||
});
|
||||
atlas.chunk_material_handle = chunk_material;
|
||||
|
||||
@@ -219,6 +217,7 @@ fn spawn_map(
|
||||
) {
|
||||
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 chunk_meshes: Vec<_> = heightmap
|
||||
.chunks
|
||||
@@ -236,6 +235,8 @@ fn spawn_map(
|
||||
.collect();
|
||||
|
||||
let mut registry = PhosChunkRegistry::new(chunk_meshes.len());
|
||||
|
||||
//Spawn Chunks
|
||||
{
|
||||
#[cfg(feature = "tracing")]
|
||||
let _spawn_span = info_span!("Spawn Chunks").entered();
|
||||
@@ -277,20 +278,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);
|
||||
generator_state.set(GeneratorState::Idle);
|
||||
if cur_game_state.get() != &MenuState::InGame {
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::shader_extensions::water_material::WaterMaterial;
|
||||
pub struct PhosAssets {
|
||||
#[asset(key = "chunk_atlas")]
|
||||
pub handle: Handle<Image>,
|
||||
pub chunk_material_handle: Handle<ExtendedMaterial<StandardMaterial, ChunkMaterial>>,
|
||||
pub chunk_material_handle: Handle<ChunkMaterial>,
|
||||
pub water_material: Handle<ExtendedMaterial<StandardMaterial, WaterMaterial>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use bevy::asset::{Asset, Handle};
|
||||
use bevy::pbr::MaterialExtension;
|
||||
use bevy::pbr::{Material, MaterialExtension, OpaqueRendererMethod};
|
||||
use bevy::prelude::Mesh;
|
||||
use bevy::reflect::TypePath;
|
||||
use bevy::render::mesh::{MeshVertexAttribute, MeshVertexBufferLayoutRef};
|
||||
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
||||
use bevy::render::texture::Image;
|
||||
use world_generation::consts::{ATTRIBUTE_PACKED_VERTEX_DATA, ATTRIBUTE_VERTEX_HEIGHT};
|
||||
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct ChunkMaterial {
|
||||
@@ -11,25 +14,53 @@ pub struct ChunkMaterial {
|
||||
pub array_texture: Handle<Image>,
|
||||
}
|
||||
|
||||
impl MaterialExtension for ChunkMaterial {
|
||||
impl Material for ChunkMaterial {
|
||||
fn fragment_shader() -> ShaderRef {
|
||||
"shaders/world/chunk.wgsl".into()
|
||||
"shaders/world/chunk_packed.wgsl".into()
|
||||
}
|
||||
|
||||
// fn vertex_shader() -> ShaderRef {
|
||||
// "shaders/world/chunk_packed.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()
|
||||
}
|
||||
|
||||
fn opaque_render_method(&self) -> bevy::pbr::OpaqueRendererMethod {
|
||||
return OpaqueRendererMethod::Auto;
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
// fn specialize(
|
||||
// _pipeline: &bevy::pbr::MaterialExtensionPipeline,
|
||||
// descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
|
||||
// layout: &bevy::render::mesh::MeshVertexBufferLayout,
|
||||
// _key: bevy::pbr::MaterialExtensionKey<Self>,
|
||||
// layout: &MeshVertexBufferLayoutRef,
|
||||
// _key: bevy::pbr::MaterialPipelineKey<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),
|
||||
// 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),
|
||||
// ])?;
|
||||
|
||||
@@ -13,6 +13,7 @@ use world_generation::{
|
||||
generators::{
|
||||
chunk_colliders::generate_chunk_collider,
|
||||
mesh_generator::{generate_chunk_mesh, generate_chunk_water_mesh},
|
||||
packed_mesh_generator::generate_packed_chunk_mesh,
|
||||
},
|
||||
hex_utils::offset_to_world,
|
||||
prelude::{Chunk, Map, MeshChunkData},
|
||||
@@ -60,7 +61,7 @@ pub fn prepare_chunk_mesh(
|
||||
) -> (Mesh, Mesh, (Vec<Vec3>, Vec<[u32; 3]>), Vec3, usize) {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _gen_mesh = info_span!("Generate Chunk").entered();
|
||||
let chunk_mesh = generate_chunk_mesh(chunk);
|
||||
let chunk_mesh = generate_packed_chunk_mesh(chunk);
|
||||
let water_mesh = generate_chunk_water_mesh(chunk, sealevel, map_size.x as usize, map_size.y as usize);
|
||||
let col_data = generate_chunk_collider(chunk);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user