|
@@ -1,7 +1,8 @@
|
|
|
use std::{iter, time::{Duration, Instant}};
|
|
use std::{iter, time::{Duration, Instant}};
|
|
|
|
|
|
|
|
use camera::{camera_buffer, camera_controller, camera_struct::Camera, camera_uniform};
|
|
use camera::{camera_buffer, camera_controller, camera_struct::Camera, camera_uniform};
|
|
|
-use wgpu::{include_wgsl, util::DeviceExt, BlendState, ColorTargetState, ComputePipeline, PipelineLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor};
|
|
|
|
|
|
|
+use compute::SIZE;
|
|
|
|
|
+use wgpu::{include_wgsl, util::DeviceExt, BlendState, ColorTargetState, ComputePipeline, PipelineLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor, Texture, TextureView};
|
|
|
use winit::{
|
|
use winit::{
|
|
|
event::*,
|
|
event::*,
|
|
|
event_loop::EventLoop,
|
|
event_loop::EventLoop,
|
|
@@ -48,10 +49,13 @@ struct State<'a> {
|
|
|
last_fps: Instant,
|
|
last_fps: Instant,
|
|
|
//Heightmap Stuff
|
|
//Heightmap Stuff
|
|
|
texture_bind_group: wgpu::BindGroup,
|
|
texture_bind_group: wgpu::BindGroup,
|
|
|
- diffuse_texture: texture::texture_struct::Texture,
|
|
|
|
|
|
|
+ diffuse_texture: texture::texture_struct::Texture2,
|
|
|
compute_pipeline: ComputePipeline,
|
|
compute_pipeline: ComputePipeline,
|
|
|
heightmap2_bindgroup: wgpu::BindGroup,
|
|
heightmap2_bindgroup: wgpu::BindGroup,
|
|
|
dispatch: (u32,u32),
|
|
dispatch: (u32,u32),
|
|
|
|
|
+ heightmap2_texture: wgpu::Texture,
|
|
|
|
|
+ visualisation_texture: Texture,
|
|
|
|
|
+ visualisation_texture_view: TextureView,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl<'a> State<'a> {
|
|
impl<'a> State<'a> {
|
|
@@ -151,7 +155,7 @@ impl<'a> State<'a> {
|
|
|
|
|
|
|
|
//Heightmap texture
|
|
//Heightmap texture
|
|
|
let diffuse_bytes = include_bytes!("./images/heightmap.jpg");
|
|
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_texture = texture::texture_struct::Texture2::from_bytes(&device, &queue, diffuse_bytes, "Heightmap texture").unwrap();
|
|
|
let diffuse_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor{
|
|
let diffuse_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor{
|
|
|
label: Some("Heightmap bind group layout"),
|
|
label: Some("Heightmap bind group layout"),
|
|
|
entries:&[
|
|
entries:&[
|
|
@@ -239,6 +243,7 @@ impl<'a> State<'a> {
|
|
|
let wireframe = true;
|
|
let wireframe = true;
|
|
|
|
|
|
|
|
let x = compute::compute_pipeline::new_compute_pipeline(&device);
|
|
let x = compute::compute_pipeline::new_compute_pipeline(&device);
|
|
|
|
|
+ let y = compute::visualisation::new(&device);
|
|
|
//Compute
|
|
//Compute
|
|
|
Self {
|
|
Self {
|
|
|
wireframe,
|
|
wireframe,
|
|
@@ -271,7 +276,10 @@ impl<'a> State<'a> {
|
|
|
texture_bind_group: diffuse_bind_group,
|
|
texture_bind_group: diffuse_bind_group,
|
|
|
compute_pipeline: x.0,
|
|
compute_pipeline: x.0,
|
|
|
heightmap2_bindgroup: x.1,
|
|
heightmap2_bindgroup: x.1,
|
|
|
- dispatch: x.2
|
|
|
|
|
|
|
+ dispatch: x.2,
|
|
|
|
|
+ heightmap2_texture: x.3,
|
|
|
|
|
+ visualisation_texture: y.0,
|
|
|
|
|
+ visualisation_texture_view: y.1,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -333,6 +341,24 @@ impl<'a> State<'a> {
|
|
|
compute_pass.dispatch_workgroups(self.dispatch.0, self.dispatch.1, 1);
|
|
compute_pass.dispatch_workgroups(self.dispatch.0, self.dispatch.1, 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ encoder.copy_texture_to_texture(wgpu::ImageCopyTextureBase{
|
|
|
|
|
+ texture: &self.heightmap2_texture,
|
|
|
|
|
+ mip_level: 1,
|
|
|
|
|
+ origin: wgpu::Origin3d::ZERO,
|
|
|
|
|
+ aspect: wgpu::TextureAspect::All
|
|
|
|
|
+ },
|
|
|
|
|
+ wgpu::ImageCopyTextureBase{
|
|
|
|
|
+ texture: &self.visualisation_texture,
|
|
|
|
|
+ mip_level: 1,
|
|
|
|
|
+ origin: wgpu::Origin3d::ZERO,
|
|
|
|
|
+ aspect: wgpu::TextureAspect::All
|
|
|
|
|
+ },
|
|
|
|
|
+ wgpu::Extent3d{
|
|
|
|
|
+ width: SIZE,
|
|
|
|
|
+ height: SIZE,
|
|
|
|
|
+ depth_or_array_layers: 1
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
|
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|