|
|
@@ -12,6 +12,7 @@ mod camera;
|
|
|
mod object;
|
|
|
mod sky;
|
|
|
mod wireframe;
|
|
|
+mod texture;
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
@@ -37,14 +38,16 @@ struct State<'a> {
|
|
|
// unsafe references to the window's resources.
|
|
|
window: &'a Window,
|
|
|
num_vertices: u32,
|
|
|
+ //FPS Stuff, could be transformed to its own module
|
|
|
last_frame: Instant,
|
|
|
framecount: u64,
|
|
|
-
|
|
|
frametime: f64,
|
|
|
old_frame_times: Vec<f64>,
|
|
|
max_history_size: usize,
|
|
|
- //sky_pipeline: wgpu::RenderPipeline,
|
|
|
last_fps: Instant,
|
|
|
+ //Heightmap Stuff
|
|
|
+ texture_bind_group: wgpu::BindGroup,
|
|
|
+ diffuse_texture: texture::texture_struct::Texture,
|
|
|
}
|
|
|
|
|
|
impl<'a> State<'a> {
|
|
|
@@ -131,10 +134,63 @@ impl<'a> State<'a> {
|
|
|
let (camera, camera_uniform, camera_buffer,camera_bind_group, camera_bind_group_layout) = camera_buffer::new(&device, &config);
|
|
|
let camera_controller = camera_controller::CameraController::new(0.1);
|
|
|
|
|
|
+
|
|
|
+ let last_frame: Instant = Instant::now();
|
|
|
+ let delta: f64 = 0.2;
|
|
|
+
|
|
|
+ //let sky_pipeline = sky::sky_pipeline::new_sky_pipeline(&device, &config);
|
|
|
+ let framecount: u64 = 0;
|
|
|
+ let old_frame_times : Vec<f64> = vec![];
|
|
|
+ let max_history: usize = 60;
|
|
|
+ let last_fps = Instant::now();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //Heightmap texture
|
|
|
+ let diffuse_bytes = include_bytes!("./images/heightmap.jpg");
|
|
|
+ let diffuse_texture = texture::texture_struct::Texture::from_bytes(&device, &queue, diffuse_bytes, "Heightmap texture").unwrap();
|
|
|
+ let diffuse_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor{
|
|
|
+ label: Some("Heightmap bind group layout"),
|
|
|
+ entries:&[
|
|
|
+ wgpu::BindGroupLayoutEntry{
|
|
|
+ binding: 0,
|
|
|
+ visibility: wgpu::ShaderStages::VERTEX,
|
|
|
+ ty: wgpu::BindingType::Texture{
|
|
|
+ sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
|
|
+ view_dimension: wgpu::TextureViewDimension::D2,
|
|
|
+ multisampled: false
|
|
|
+ },
|
|
|
+ count: None
|
|
|
+ },
|
|
|
+ wgpu::BindGroupLayoutEntry{
|
|
|
+ binding: 1,
|
|
|
+ visibility: wgpu::ShaderStages::VERTEX,
|
|
|
+ ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
|
|
+ count: None
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+ let diffuse_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor{
|
|
|
+ label: Some("Heightmap bind group"),
|
|
|
+ layout: &diffuse_bind_group_layout,
|
|
|
+ entries: &[
|
|
|
+ wgpu::BindGroupEntry{
|
|
|
+ binding: 0,
|
|
|
+ resource: wgpu::BindingResource::TextureView(&diffuse_texture.view)
|
|
|
+ },
|
|
|
+ wgpu::BindGroupEntry{
|
|
|
+ binding: 1,
|
|
|
+ resource: wgpu::BindingResource::Sampler(&diffuse_texture.sampler)
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor{
|
|
|
label: Some("Pipeline Layout"),
|
|
|
bind_group_layouts: &[
|
|
|
&camera_bind_group_layout,
|
|
|
+ &diffuse_bind_group_layout,
|
|
|
],
|
|
|
push_constant_ranges: &[]
|
|
|
});
|
|
|
@@ -176,16 +232,7 @@ impl<'a> State<'a> {
|
|
|
multiview: None
|
|
|
});
|
|
|
|
|
|
- let last_frame: Instant = Instant::now();
|
|
|
- let delta: f64 = 0.2;
|
|
|
-
|
|
|
- //let sky_pipeline = sky::sky_pipeline::new_sky_pipeline(&device, &config);
|
|
|
- let framecount: u64 = 0;
|
|
|
- let old_frame_times : Vec<f64> = vec![];
|
|
|
- let max_history: usize = 60;
|
|
|
- let last_fps = Instant::now();
|
|
|
-
|
|
|
- let wireframe_pipeline = wireframe::wireframe_pipeline::new(&device, &config, &camera_bind_group_layout);
|
|
|
+ let wireframe_pipeline = wireframe::wireframe_pipeline::new(&device, &config, &camera_bind_group_layout, &diffuse_bind_group_layout);
|
|
|
let wireframe = false;
|
|
|
Self {
|
|
|
wireframe,
|
|
|
@@ -204,13 +251,18 @@ impl<'a> State<'a> {
|
|
|
camera_uniform,
|
|
|
camera_controller,
|
|
|
num_vertices: num_vertices,
|
|
|
- last_frame: last_frame,
|
|
|
- frametime: delta,
|
|
|
+
|
|
|
//sky_pipeline: sky_pipeline
|
|
|
+ //FPS Struct, could be transformed to its own module
|
|
|
framecount,
|
|
|
old_frame_times: old_frame_times,
|
|
|
max_history_size: max_history,
|
|
|
- last_fps: last_fps
|
|
|
+ last_fps: last_fps,
|
|
|
+ last_frame: last_frame,
|
|
|
+ frametime: delta,
|
|
|
+ //Heightmap Stuff
|
|
|
+ diffuse_texture: diffuse_texture,
|
|
|
+ texture_bind_group: diffuse_bind_group,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -295,6 +347,7 @@ impl<'a> State<'a> {
|
|
|
|
|
|
render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
|
|
|
render_pass.set_bind_group(0, &self.camera_bind_group, &[]);
|
|
|
+ render_pass.set_bind_group(1, &self.texture_bind_group, &[]);
|
|
|
render_pass.draw(0..self.num_vertices, 0..1);
|
|
|
//render_pass.draws
|
|
|
}
|