basic render distance
This commit is contained in:
@@ -95,8 +95,8 @@ fn update_camera_mouse(
|
||||
CursorGrabMode::None => (),
|
||||
_ => {
|
||||
// Using smallest of height or width ensures equal vertical and horizontal sensitivity
|
||||
pitch -= (ev.delta.y * time.delta_seconds() * 5.).to_radians();
|
||||
yaw -= (ev.delta.x * time.delta_seconds() * 5.).to_radians();
|
||||
pitch -= ev.delta.y.to_radians() * time.delta_seconds() * 5.;
|
||||
yaw -= ev.delta.x.to_radians() * time.delta_seconds() * 5.;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,24 +11,25 @@ use phos::PhosGamePlugin;
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((
|
||||
DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Phos".into(),
|
||||
name: Some("phos".into()),
|
||||
resolution: (1920.0, 1080.0).into(),
|
||||
resizable: true,
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
DefaultPlugins
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Phos".into(),
|
||||
name: Some("phos".into()),
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
mode: bevy::window::WindowMode::BorderlessFullscreen,
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
})
|
||||
.set(ImagePlugin {
|
||||
default_sampler: ImageSamplerDescriptor {
|
||||
address_mode_u: ImageAddressMode::Repeat,
|
||||
address_mode_v: ImageAddressMode::Repeat,
|
||||
mag_filter: ImageFilterMode::Nearest,
|
||||
..default()
|
||||
},
|
||||
}),
|
||||
..default()
|
||||
}).set(ImagePlugin {
|
||||
default_sampler: ImageSamplerDescriptor {
|
||||
address_mode_u: ImageAddressMode::Repeat,
|
||||
address_mode_v: ImageAddressMode::Repeat,
|
||||
mag_filter: ImageFilterMode::Nearest,
|
||||
..default()
|
||||
}
|
||||
}),
|
||||
WorldInspectorPlugin::new(),
|
||||
PhosGamePlugin,
|
||||
))
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use crate::prelude::*;
|
||||
use crate::shader_extensions::chunk_material::ChunkMaterial;
|
||||
use bevy::asset::LoadState;
|
||||
use bevy::core_pipeline::experimental::taa::TemporalAntiAliasPlugin;
|
||||
use bevy::pbr::ExtendedMaterial;
|
||||
use bevy::render::view::visibility;
|
||||
use bevy::{pbr::CascadeShadowConfig, prelude::*};
|
||||
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
||||
use bevy_rapier3d::render::RapierDebugRenderPlugin;
|
||||
use camera_system::prelude::PhosCamera;
|
||||
use camera_system::PhosCameraPlugin;
|
||||
use iyes_perf_ui::prelude::*;
|
||||
use world_generation::biome_painter::{
|
||||
@@ -25,12 +26,14 @@ impl Plugin for PhosGamePlugin {
|
||||
app.add_plugins(PhosCameraPlugin)
|
||||
.add_plugins(MaterialPlugin::<
|
||||
ExtendedMaterial<StandardMaterial, ChunkMaterial>,
|
||||
>::default())
|
||||
.add_plugins(TemporalAntiAliasPlugin);
|
||||
>::default());
|
||||
|
||||
//Systems - Startup
|
||||
app.add_systems(Startup, init_game)
|
||||
.add_systems(Startup, (load_textures, load_tiles, create_map).chain());
|
||||
|
||||
//Systems - PreUpdate
|
||||
app.add_systems(PreUpdate, render_distance_system);
|
||||
//Systems - Update
|
||||
app.add_systems(Update, (finalize_texture, spawn_map));
|
||||
|
||||
@@ -233,3 +236,18 @@ fn spawn_map(
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn render_distance_system(
|
||||
mut chunks: Query<(&Transform, &mut Visibility), With<PhosChunk>>,
|
||||
camera: Query<&Transform, With<PhosCamera>>,
|
||||
) {
|
||||
let cam = camera.single();
|
||||
for (transform, mut visibility) in chunks.iter_mut() {
|
||||
let dist = (transform.translation - cam.translation).length_squared();
|
||||
if dist > 1000000. {
|
||||
*visibility = Visibility::Hidden;
|
||||
} else {
|
||||
*visibility = Visibility::Visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use bevy::reflect::TypePath;
|
||||
use bevy::render::mesh::Mesh;
|
||||
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
||||
use bevy::render::texture::Image;
|
||||
use world_generation::prelude::ATTRIBUTE_PACKED_VERTEX_DATA;
|
||||
use world_generation::prelude::{ATTRIBUTE_PACKED_VERTEX_DATA, ATTRIBUTE_VERTEX_HEIGHT};
|
||||
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct ChunkMaterial {
|
||||
@@ -18,23 +18,24 @@ impl MaterialExtension for ChunkMaterial {
|
||||
"shaders/world/chunk.wgsl".into()
|
||||
}
|
||||
|
||||
fn vertex_shader() -> ShaderRef {
|
||||
"shaders/world/chunk_packed.wgsl".into()
|
||||
}
|
||||
// fn vertex_shader() -> ShaderRef {
|
||||
// "shaders/world/chunk_packed.wgsl".into()
|
||||
// }
|
||||
|
||||
fn specialize(
|
||||
_pipeline: &bevy::pbr::MaterialExtensionPipeline,
|
||||
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),
|
||||
])?;
|
||||
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>,
|
||||
// ) -> 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(())
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user