Browse Source

Run, but there is a problem between shaders

Ghastrod 1 năm trước cách đây
mục cha
commit
975691b6a3

+ 1 - 1
src/compute/mod.rs

@@ -1,4 +1,4 @@
 pub mod compute_pipeline;
 pub mod visualisation;
 
-pub const SIZE:u32 = 256;
+pub const SIZE:u32 = 128;

+ 12 - 7
src/lib.rs

@@ -129,7 +129,7 @@ impl<'a> State<'a> {
         );
         
 
-        let plan1 = object::generate_plane(512,512,100.,100.);
+        let plan1 = object::generate_plane(SIZE,SIZE,100.,100.);
         //println!("{:?}", plan1.positions_list());
         let plan2 = plan1.clone();
         let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
@@ -194,11 +194,22 @@ impl<'a> State<'a> {
         });
 
 
+
+
+
+
+        let x = compute::compute_pipeline::new_compute_pipeline(&device);
+        let y = compute::visualisation::new(&device);
+
+        let wireframe_pipeline = wireframe::wireframe_pipeline::new(&device, &config, &camera_bind_group_layout, &diffuse_bind_group_layout,&y.2);
+        let wireframe = true;
+
         let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor{
             label: Some("Pipeline Layout"),
             bind_group_layouts: &[
                 &camera_bind_group_layout,
                 &diffuse_bind_group_layout,
+                &y.2
             ],
             push_constant_ranges: &[]
         });
@@ -239,12 +250,6 @@ impl<'a> State<'a> {
             }),
             multiview: None
         });
-
-        let wireframe_pipeline = wireframe::wireframe_pipeline::new(&device, &config, &camera_bind_group_layout, &diffuse_bind_group_layout);
-        let wireframe = true;
-
-        let x = compute::compute_pipeline::new_compute_pipeline(&device);
-        let y = compute::visualisation::new(&device);
         //Compute
         Self {
             wireframe,

+ 2 - 2
src/shaders/Heightmap_compute.wgsl

@@ -50,12 +50,12 @@ fn gaussian(x: f32, y:f32)-> f32{
     return (1 / (sqrt(2 * PI)* spread)) * exp(-((actual_x * actual_x) + (actual_y * actual_y)) / (2 * sigma_squared));
 }
 
-@compute @workgroup_size(1,1)
+@compute @workgroup_size(16,16)
 fn compute_main(in: ComputeInput){
     let coordonnees = in.global_invocation_id.xy;
     let dimensions = textureDimensions(heightmap_texture);
 
-    let pixel_color_1_channel = sin(f32(coordonnees.x) + f32(coordonnees.y));
+    let pixel_color_1_channel = f32(coordonnees.x + coordonnees.y);
 
     let vec4_pixel_color = vec4<f32>(pixel_color_1_channel);
 

+ 11 - 3
src/shaders/plane_shader.wgsl

@@ -23,17 +23,25 @@ var t_diffuse: texture_2d<f32>;
 @group(1) @binding(1)
 var s_diffuse: sampler;
 
+@group(2) @binding(0)
+var h_diffuse: texture_2d<f32>;
+@group(2) @binding(1)
+var hs_diffuse: sampler;
 
 @vertex
 fn vs_main(
     model: VertexInput,
 ) -> VertexOutput {
-    let normalized_uv_coordinates = model.uv * vec2<f32>(textureDimensions(t_diffuse));
-    let height_added = textureLoad(t_diffuse,vec2<u32>(normalized_uv_coordinates),0);
+    //let normalized_uv_coordinates = model.uv * vec2<f32>(textureDimensions(t_diffuse));
+    let normalized_uv_coordinates = model.uv * vec2<f32>(textureDimensions(h_diffuse));
+
+    //let height_added = textureLoad(t_diffuse,vec2<u32>(normalized_uv_coordinates),0);
+    let height_added = textureLoad(h_diffuse,vec2<u32>(normalized_uv_coordinates),0);
+
     let grayscale_height_added = height_added.x;
     var out: VertexOutput;
     out.color = model.color;
-    out.clip_position = camera.view_proj * vec4<f32>(model.position.x,model.position.y, model.position.z + (100* grayscale_height_added), 1.0);
+    out.clip_position = camera.view_proj * vec4<f32>(model.position.x,model.position.y, model.position.z + (5* grayscale_height_added), 1.0);
     return out;
 }
 

+ 2 - 1
src/wireframe/wireframe_pipeline.rs

@@ -2,13 +2,14 @@ use wgpu::{include_wgsl, BlendState, ColorTargetState, RenderPipeline, RenderPip
 
 use crate::object;
 
-pub fn new(device: &wgpu::Device, config: &SurfaceConfiguration,camera_bind_group_layout: &wgpu::BindGroupLayout, diffuse_bind_group_layout: &wgpu::BindGroupLayout)-> RenderPipeline{
+pub fn new(device: &wgpu::Device, config: &SurfaceConfiguration,camera_bind_group_layout: &wgpu::BindGroupLayout, diffuse_bind_group_layout: &wgpu::BindGroupLayout, visu_bind_group_layout: &wgpu::BindGroupLayout)-> RenderPipeline{
 
     let wireframe_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor{
         label: Some("Wireframe Pipeline Layout"),
         bind_group_layouts: &[
             &camera_bind_group_layout,
             &diffuse_bind_group_layout,
+            &visu_bind_group_layout,
         ],
         push_constant_ranges: &[]
     });