shader testing
This commit is contained in:
@@ -74,7 +74,7 @@ fn create_tile(
|
||||
let y_min = tex_y as f32 / 8.;
|
||||
const TX_UNIT: Vec2 = Vec2::new(1. / 11., 1. / 8.);
|
||||
|
||||
let uv_offset = Vec2::new(x_min + TX_UNIT.x / 2., y_min + TX_UNIT.y / 2.);
|
||||
let uv_offset = Vec2::splat(0.5);
|
||||
|
||||
let idx = verts.len() as u32;
|
||||
uvs.push(uv_offset);
|
||||
@@ -82,7 +82,7 @@ fn create_tile(
|
||||
for i in 0..6 {
|
||||
let p = pos + HEX_CORNERS[i];
|
||||
verts.push(p);
|
||||
let uv = (HEX_CORNERS[i].xz() * TX_UNIT / 2.) + uv_offset;
|
||||
let uv = (HEX_CORNERS[i].xz() / 2.) + uv_offset;
|
||||
uvs.push(uv);
|
||||
indices.push(idx);
|
||||
indices.push(idx + 1 + i as u32);
|
||||
@@ -94,16 +94,7 @@ fn create_tile(
|
||||
match cur_n {
|
||||
Some(n_height) => {
|
||||
if n_height < pos.y {
|
||||
create_tile_wall(
|
||||
pos,
|
||||
i,
|
||||
n_height,
|
||||
verts,
|
||||
uvs,
|
||||
indices,
|
||||
Vec2::new(x_min, y_min),
|
||||
Vec2::new(x_min + TX_UNIT.x, y_min + TX_UNIT.y),
|
||||
);
|
||||
create_tile_wall(pos, i, n_height, verts, uvs, indices, Vec2::ZERO, Vec2::ONE);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
BIN
game/main/assets/textures/world/stack.png
Normal file
BIN
game/main/assets/textures/world/stack.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -1,4 +1,4 @@
|
||||
use bevy::pbr::MaterialExtension;
|
||||
use bevy::pbr::{ExtendedMaterial, MaterialExtension};
|
||||
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
||||
use bevy::{pbr::CascadeShadowConfig, prelude::*};
|
||||
use camera_system::PhosCameraPlugin;
|
||||
@@ -47,11 +47,22 @@ fn init_game(mut commands: Commands) {
|
||||
});
|
||||
}
|
||||
|
||||
fn load_textures(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
let main_tex = asset_server.load("textures/world/test2.png");
|
||||
fn load_textures(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
) {
|
||||
let main_tex = asset_server.load("textures/world/stack.png");
|
||||
commands.insert_resource(ChunkAtlas {
|
||||
handle: main_tex.clone(),
|
||||
});
|
||||
|
||||
//todo: wait for texture to load
|
||||
let image = images.get_mut(&main_tex).unwrap();
|
||||
|
||||
// Create a new array texture asset from the loaded texture.
|
||||
let array_layers = 7;
|
||||
image.reinterpret_stacked_2d_as_array(array_layers);
|
||||
}
|
||||
|
||||
fn draw_gizmos(mut gizmos: Gizmos, hm: Res<Map>) {
|
||||
@@ -84,9 +95,10 @@ fn draw_gizmos(mut gizmos: Gizmos, hm: Res<Map>) {
|
||||
}
|
||||
}
|
||||
|
||||
//todo: run after textures are ready
|
||||
fn create_map(
|
||||
mut commands: Commands,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
mut materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, ChunkMaterial>>>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
atlas: Res<ChunkAtlas>,
|
||||
) {
|
||||
@@ -150,15 +162,20 @@ fn create_map(
|
||||
2,
|
||||
);
|
||||
|
||||
let chunk_material = materials.add(StandardMaterial {
|
||||
base_color_texture: Some(atlas.handle.clone()),
|
||||
let chunk_material = materials.add(ExtendedMaterial {
|
||||
base: StandardMaterial {
|
||||
base_color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
extension: ChunkMaterial {
|
||||
array_texture: atlas.handle.clone(),
|
||||
},
|
||||
});
|
||||
|
||||
for chunk in &heightmap.chunks {
|
||||
let mesh = generate_chunk_mesh(&chunk, &heightmap);
|
||||
let pos = offset_to_world(chunk.chunk_offset * Chunk::SIZE as i32, 0.);
|
||||
commands.spawn(PbrBundle {
|
||||
commands.spawn(MaterialMeshBundle {
|
||||
mesh: meshes.add(mesh),
|
||||
material: chunk_material.clone(),
|
||||
transform: Transform::from_translation(pos),
|
||||
|
||||
Reference in New Issue
Block a user