Merge branch 'master' into texture-index
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -7,7 +7,7 @@
|
|||||||
{
|
{
|
||||||
"type": "cppvsdbg",
|
"type": "cppvsdbg",
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"console": "externalTerminal",
|
// "console": "externalTerminal",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Debug",
|
"name": "Debug",
|
||||||
"program": "${workspaceRoot}/target/debug/phos.exe",
|
"program": "${workspaceRoot}/target/debug/phos.exe",
|
||||||
|
|||||||
@@ -32,12 +32,10 @@ pub fn generate_chunk(chunk_x: f64, chunk_z: f64, cfg: &GenerationConfig, seed:
|
|||||||
&noise,
|
&noise,
|
||||||
);
|
);
|
||||||
result[x + z * Chunk::SIZE] = sample;
|
result[x + z * Chunk::SIZE] = sample;
|
||||||
moisture[x + z * Chunk::SIZE] = sample_simple(
|
moisture[x + z * Chunk::SIZE] = noise.get([
|
||||||
x as f64 + chunk_x * Chunk::SIZE as f64,
|
(x as f64 + chunk_x * Chunk::SIZE as f64) / &cfg.noise_scale,
|
||||||
z as f64 + chunk_z * Chunk::SIZE as f64,
|
(z as f64 + chunk_z * Chunk::SIZE as f64) / &cfg.noise_scale,
|
||||||
&cfg.layers[0],
|
]) as f32;
|
||||||
&noise,
|
|
||||||
) as f32;
|
|
||||||
temp[x + z * Chunk::SIZE] = sample_tempurature(
|
temp[x + z * Chunk::SIZE] = sample_tempurature(
|
||||||
z as f32 + chunk_z as f32 * Chunk::SIZE as f32,
|
z as f32 + chunk_z as f32 * Chunk::SIZE as f32,
|
||||||
sample,
|
sample,
|
||||||
@@ -57,10 +55,10 @@ pub fn generate_chunk(chunk_x: f64, chunk_z: f64, cfg: &GenerationConfig, seed:
|
|||||||
fn sample_tempurature(z: f32, height: f32, cfg: &GenerationConfig, equator: f32) -> f32 {
|
fn sample_tempurature(z: f32, height: f32, cfg: &GenerationConfig, equator: f32) -> f32 {
|
||||||
let d = (equator - z).abs();
|
let d = (equator - z).abs();
|
||||||
let max_d = equator.max(cfg.get_total_height() as f32 - equator);
|
let max_d = equator.max(cfg.get_total_height() as f32 - equator);
|
||||||
let t_mod = d.remap(0., max_d, 0., 1.);
|
let t_mod = d.remap(0., max_d, 0., 1.).clamp(0., 1.);
|
||||||
|
|
||||||
// let max_d = d.max()
|
// let max_d = d.max()
|
||||||
return height.remap(0., 100., 0., 1.).clamp(0., 1.) * t_mod;
|
return (height.remap(0., 50., 0., 1.).clamp(0., 1.) + t_mod) / 2.;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sample_point(x: f64, z: f64, cfg: &GenerationConfig, noise: &impl NoiseFn<f64, 2>) -> f32 {
|
fn sample_point(x: f64, z: f64, cfg: &GenerationConfig, noise: &impl NoiseFn<f64, 2>) -> f32 {
|
||||||
|
|||||||
@@ -32,6 +32,31 @@ const HEX_NORMALS: [Vec3; 6] = [
|
|||||||
Vec3::new(-INNER_RADIUS, 0., 0.5 * OUTER_RADIUS),
|
Vec3::new(-INNER_RADIUS, 0., 0.5 * OUTER_RADIUS),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const HEX_NORMALS: [Vec3; 6] = [
|
||||||
|
Vec3::new(
|
||||||
|
INNER_RADIUS / 2.,
|
||||||
|
0.,
|
||||||
|
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / 2.,
|
||||||
|
),
|
||||||
|
Vec3::Z,
|
||||||
|
Vec3::new(
|
||||||
|
INNER_RADIUS / -2.,
|
||||||
|
0.,
|
||||||
|
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / 2.,
|
||||||
|
),
|
||||||
|
Vec3::new(
|
||||||
|
INNER_RADIUS / -2.,
|
||||||
|
0.,
|
||||||
|
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / -2.,
|
||||||
|
),
|
||||||
|
Vec3::NEG_Z,
|
||||||
|
Vec3::new(
|
||||||
|
INNER_RADIUS / 2.,
|
||||||
|
0.,
|
||||||
|
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / -2.,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
pub fn generate_chunk_mesh(
|
pub fn generate_chunk_mesh(
|
||||||
chunk: &Chunk,
|
chunk: &Chunk,
|
||||||
map: &Map,
|
map: &Map,
|
||||||
@@ -43,6 +68,7 @@ pub fn generate_chunk_mesh(
|
|||||||
let mut verts = Vec::with_capacity(vertex_count);
|
let mut verts = Vec::with_capacity(vertex_count);
|
||||||
let mut uvs = Vec::with_capacity(vertex_count);
|
let mut uvs = Vec::with_capacity(vertex_count);
|
||||||
let mut indices = Vec::with_capacity(vertex_count);
|
let mut indices = Vec::with_capacity(vertex_count);
|
||||||
|
let mut normals = Vec::with_capacity(vertex_count);
|
||||||
let mut texture_indicies = Vec::with_capacity(vertex_count);
|
let mut texture_indicies = Vec::with_capacity(vertex_count);
|
||||||
|
|
||||||
for z in 0..Chunk::SIZE {
|
for z in 0..Chunk::SIZE {
|
||||||
@@ -66,6 +92,7 @@ pub fn generate_chunk_mesh(
|
|||||||
&mut verts,
|
&mut verts,
|
||||||
&mut uvs,
|
&mut uvs,
|
||||||
&mut indices,
|
&mut indices,
|
||||||
|
&mut normals,
|
||||||
&mut texture_indicies,
|
&mut texture_indicies,
|
||||||
// &mut tex,
|
// &mut tex,
|
||||||
tile.texture_id,
|
tile.texture_id,
|
||||||
@@ -81,18 +108,19 @@ pub fn generate_chunk_mesh(
|
|||||||
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, verts)
|
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, verts)
|
||||||
.with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, uvs)
|
.with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, uvs)
|
||||||
.with_inserted_attribute(ATTRIBUTE_TEXTURE_INDEX, texture_indicies)
|
.with_inserted_attribute(ATTRIBUTE_TEXTURE_INDEX, texture_indicies)
|
||||||
.with_inserted_indices(Indices::U32(indices))
|
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
|
||||||
.with_duplicated_vertices()
|
.with_inserted_indices(Indices::U32(indices));
|
||||||
.with_computed_flat_normals();
|
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TEX_MULTI: Vec2 = Vec2::new(1000., 1.);
|
||||||
fn create_tile(
|
fn create_tile(
|
||||||
pos: Vec3,
|
pos: Vec3,
|
||||||
neighbors: &[Option<f32>; 6],
|
neighbors: &[Option<f32>; 6],
|
||||||
verts: &mut Vec<Vec3>,
|
verts: &mut Vec<Vec3>,
|
||||||
uvs: &mut Vec<Vec2>,
|
uvs: &mut Vec<Vec2>,
|
||||||
indices: &mut Vec<u32>,
|
indices: &mut Vec<u32>,
|
||||||
|
normals: &mut Vec<Vec3>,
|
||||||
texture_indices: &mut Vec<u32>,
|
texture_indices: &mut Vec<u32>,
|
||||||
texture_index: u32,
|
texture_index: u32,
|
||||||
side_texture_index: u32,
|
side_texture_index: u32,
|
||||||
@@ -100,17 +128,20 @@ fn create_tile(
|
|||||||
let uv_offset = Vec2::splat(0.5);
|
let uv_offset = Vec2::splat(0.5);
|
||||||
|
|
||||||
let idx = verts.len() as u32;
|
let idx = verts.len() as u32;
|
||||||
uvs.push(uv_offset);
|
|
||||||
texture_indices.push(texture_index);
|
texture_indices.push(texture_index);
|
||||||
|
uvs.push((uv_offset / TEX_MULTI) + tex_off);
|
||||||
verts.push(pos);
|
verts.push(pos);
|
||||||
|
normals.push(Vec3::Y);
|
||||||
|
|
||||||
for i in 0..6 {
|
for i in 0..6 {
|
||||||
let p = pos + HEX_CORNERS[i];
|
let p = pos + HEX_CORNERS[i];
|
||||||
verts.push(p);
|
verts.push(p);
|
||||||
let uv = (HEX_CORNERS[i].xz() / 2.) + uv_offset;
|
let uv = (HEX_CORNERS[i].xz() / 2.) + uv_offset;
|
||||||
uvs.push(uv);
|
uvs.push((uv / TEX_MULTI) + tex_off);
|
||||||
indices.push(idx);
|
indices.push(idx);
|
||||||
indices.push(idx + 1 + i as u32);
|
indices.push(idx + 1 + i as u32);
|
||||||
indices.push(idx + 1 + ((i as u32 + 1) % 6));
|
indices.push(idx + 1 + ((i as u32 + 1) % 6));
|
||||||
|
normals.push(Vec3::Y);
|
||||||
texture_indices.push(texture_index);
|
texture_indices.push(texture_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +157,7 @@ fn create_tile(
|
|||||||
verts,
|
verts,
|
||||||
uvs,
|
uvs,
|
||||||
indices,
|
indices,
|
||||||
|
normals,
|
||||||
texture_indices,
|
texture_indices,
|
||||||
side_texture_index,
|
side_texture_index,
|
||||||
);
|
);
|
||||||
@@ -143,8 +175,10 @@ fn create_tile_wall(
|
|||||||
verts: &mut Vec<Vec3>,
|
verts: &mut Vec<Vec3>,
|
||||||
uvs: &mut Vec<Vec2>,
|
uvs: &mut Vec<Vec2>,
|
||||||
indices: &mut Vec<u32>,
|
indices: &mut Vec<u32>,
|
||||||
|
normals: &mut Vec<Vec3>,
|
||||||
texture_indices: &mut Vec<u32>,
|
texture_indices: &mut Vec<u32>,
|
||||||
texture_index: u32,
|
texture_index: u32,
|
||||||
|
tex_off: Vec2,
|
||||||
) {
|
) {
|
||||||
let p1 = HEX_CORNERS[(dir) % 6] + pos;
|
let p1 = HEX_CORNERS[(dir) % 6] + pos;
|
||||||
let p2 = HEX_CORNERS[(dir + 1) % 6] + pos;
|
let p2 = HEX_CORNERS[(dir + 1) % 6] + pos;
|
||||||
@@ -163,6 +197,12 @@ fn create_tile_wall(
|
|||||||
texture_indices.push(texture_index);
|
texture_indices.push(texture_index);
|
||||||
texture_indices.push(texture_index);
|
texture_indices.push(texture_index);
|
||||||
|
|
||||||
|
let n = HEX_NORMALS[dir].normalize();
|
||||||
|
normals.push(n);
|
||||||
|
normals.push(n);
|
||||||
|
normals.push(n);
|
||||||
|
normals.push(n);
|
||||||
|
|
||||||
indices.push(idx);
|
indices.push(idx);
|
||||||
indices.push(idx + 2);
|
indices.push(idx + 2);
|
||||||
indices.push(idx + 1);
|
indices.push(idx + 1);
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ impl Plugin for PhosCameraPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, mut msaa: ResMut<Msaa>) {
|
fn setup(mut commands: Commands) {
|
||||||
*msaa = Msaa::Off;
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Camera3dBundle {
|
Camera3dBundle {
|
||||||
transform: Transform::from_xyz(0., 30., 0.)
|
transform: Transform::from_xyz(0., 30., 0.)
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
|||||||
|
|
||||||
mod phos;
|
mod phos;
|
||||||
mod prelude;
|
mod prelude;
|
||||||
mod shaders;
|
mod shader_extensions;
|
||||||
|
|
||||||
use phos::PhosGamePlugin;
|
use phos::PhosGamePlugin;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::shaders::chunk::ChunkMaterial;
|
use crate::shader_extensions::chunk_material::ChunkMaterial;
|
||||||
use bevy::asset::LoadState;
|
use bevy::asset::LoadState;
|
||||||
use bevy::core_pipeline::experimental::taa::TemporalAntiAliasPlugin;
|
use bevy::core_pipeline::experimental::taa::TemporalAntiAliasPlugin;
|
||||||
use bevy::pbr::ExtendedMaterial;
|
use bevy::pbr::ExtendedMaterial;
|
||||||
@@ -9,7 +9,7 @@ use bevy_rapier3d::render::RapierDebugRenderPlugin;
|
|||||||
use camera_system::PhosCameraPlugin;
|
use camera_system::PhosCameraPlugin;
|
||||||
use iyes_perf_ui::prelude::*;
|
use iyes_perf_ui::prelude::*;
|
||||||
use world_generation::biome_painter::{
|
use world_generation::biome_painter::{
|
||||||
self, BiomePainterAsset, BiomePainterLoadState, BiomePainterPlugin,
|
BiomePainterAsset, BiomePainterLoadState, BiomePainterPlugin,
|
||||||
};
|
};
|
||||||
use world_generation::hex_utils::offset_to_world;
|
use world_generation::hex_utils::offset_to_world;
|
||||||
use world_generation::tile_manager::{TileAsset, TileAssetLoadState, TileAssetPlugin, TileManager};
|
use world_generation::tile_manager::{TileAsset, TileAssetLoadState, TileAssetPlugin, TileManager};
|
||||||
|
|||||||
18
game/main/src/shader_extensions/chunk_material.rs
Normal file
18
game/main/src/shader_extensions/chunk_material.rs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
use bevy::asset::{Asset, Handle};
|
||||||
|
use bevy::pbr::MaterialExtension;
|
||||||
|
use bevy::reflect::TypePath;
|
||||||
|
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
||||||
|
use bevy::render::texture::Image;
|
||||||
|
|
||||||
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||||
|
pub struct ChunkMaterial {
|
||||||
|
#[texture(100, dimension = "2d_array")]
|
||||||
|
#[sampler(101)]
|
||||||
|
pub array_texture: Handle<Image>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MaterialExtension for ChunkMaterial {
|
||||||
|
fn fragment_shader() -> ShaderRef {
|
||||||
|
"shaders/world/chunk.wgsl".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
1
game/main/src/shader_extensions/mod.rs
Normal file
1
game/main/src/shader_extensions/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod chunk_material;
|
||||||
Reference in New Issue
Block a user