Kaynağa Gözat

Works, now i have to try to use the computed texture

Ghastrod 1 yıl önce
ebeveyn
işleme
1db518aa90
2 değiştirilmiş dosya ile 61 ekleme ve 6 silme
  1. 28 3
      src/compute/visualisation.rs
  2. 33 3
      src/lib.rs

+ 28 - 3
src/compute/visualisation.rs

@@ -1,10 +1,10 @@
-use wgpu::{Texture, TextureView};
+use wgpu::{BindGroupLayout, Texture, TextureView};
 
 use super::SIZE;
 
 
 
-pub fn new(device: &wgpu::Device)-> (Texture,TextureView){
+pub fn new(device: &wgpu::Device)-> (Texture,TextureView, BindGroupLayout){
 
     let visualisation_texture_size = wgpu::Extent3d{
         width: SIZE,
@@ -29,5 +29,30 @@ pub fn new(device: &wgpu::Device)-> (Texture,TextureView){
         ..Default::default()
     });
     
-    return (visualization_texture,visualization_texture_view)
+    let visualisation_texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor{
+        label: Some("Visu bind group layout"),
+        entries: &[
+            wgpu::BindGroupLayoutEntry{
+                binding: 0,
+                visibility: wgpu::ShaderStages::VERTEX,
+                ty: wgpu::BindingType::Texture{
+                    sample_type: wgpu::TextureSampleType::Float { filterable: false },
+                    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
+            }
+        ]
+    });
+
+
+
+
+    return (visualization_texture,visualization_texture_view, visualisation_texture_bind_group_layout)
 }

+ 33 - 3
src/lib.rs

@@ -2,7 +2,7 @@ use std::{iter, time::{Duration, Instant}};
 
 use camera::{camera_buffer, camera_controller, camera_struct::Camera, camera_uniform};
 use compute::SIZE;
-use wgpu::{include_wgsl, util::DeviceExt, BlendState, ColorTargetState, ComputePipeline, PipelineLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor, Texture, TextureView};
+use wgpu::{include_wgsl, util::DeviceExt, BindGroupLayout, BlendState, ColorTargetState, ComputePipeline, PipelineLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor, Texture, TextureView};
 use winit::{
     event::*,
     event_loop::EventLoop,
@@ -56,6 +56,7 @@ struct State<'a> {
     heightmap2_texture: wgpu::Texture,
     visualisation_texture: Texture,
     visualisation_texture_view: TextureView,
+    visualisation_texture_bind_group_layout: BindGroupLayout,
 }
 
 impl<'a> State<'a> {
@@ -280,6 +281,7 @@ impl<'a> State<'a> {
             heightmap2_texture: x.3,
             visualisation_texture: y.0,
             visualisation_texture_view: y.1,
+            visualisation_texture_bind_group_layout: y.2,
         }
     }
 
@@ -343,13 +345,13 @@ impl<'a> State<'a> {
 
         encoder.copy_texture_to_texture(wgpu::ImageCopyTextureBase{
             texture: &self.heightmap2_texture,
-            mip_level: 1,
+            mip_level: 0,
             origin: wgpu::Origin3d::ZERO,
             aspect: wgpu::TextureAspect::All
         },
         wgpu::ImageCopyTextureBase{
             texture: &self.visualisation_texture,
-            mip_level: 1,
+            mip_level: 0,
             origin: wgpu::Origin3d::ZERO,
             aspect: wgpu::TextureAspect::All
         },
@@ -360,6 +362,33 @@ impl<'a> State<'a> {
         }
         );
 
+        let visu_view = self.visualisation_texture.create_view(&wgpu::TextureViewDescriptor::default());
+
+        let sampler_visu = self.device.create_sampler(&wgpu::SamplerDescriptor {
+            address_mode_u: wgpu::AddressMode::ClampToEdge,
+            address_mode_v: wgpu::AddressMode::ClampToEdge,
+            address_mode_w: wgpu::AddressMode::ClampToEdge,
+            mag_filter: wgpu::FilterMode::Linear,
+            min_filter: wgpu::FilterMode::Nearest,
+            mipmap_filter: wgpu::FilterMode::Nearest,
+            ..Default::default()
+        });
+        let visu_bind_group = self.device.create_bind_group(&wgpu::BindGroupDescriptor{
+            label: Some("Visu bind group"),
+            layout: &self.visualisation_texture_bind_group_layout,
+            entries: &[
+                wgpu::BindGroupEntry{
+                    binding: 0,
+                    resource: wgpu::BindingResource::TextureView(&visu_view)
+                },
+                wgpu::BindGroupEntry{
+                    binding:1,
+                    resource: wgpu::BindingResource::Sampler(&sampler_visu)
+                }
+            ]
+        });
+
+
         {
             let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
                 label: Some("Render Pass"),
@@ -394,6 +423,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.set_bind_group(2, &visu_bind_group, &[]);
             render_pass.draw(0..self.num_vertices, 0..1);
             //render_pass.draws
         }