소스 검색

Run, but sinusoid is not very visible

Ghastrod 1 년 전
부모
커밋
0c1798f4f1

+ 2 - 1
src/compute/compute_pipeline.rs

@@ -86,7 +86,8 @@ pub fn new_compute_pipeline(device: &wgpu::Device)-> (ComputePipeline,BindGroup,
         entry_point: "compute_main"
     });
 
-    let dispatch = compute_work_group_count((SIZE,SIZE), (16,16));
+    let dispatch = compute_work_group_count((SIZE,SIZE), (1,1));
+    //let dispatch = (1,1);
     return (compute_pipeline,heightmap_texture_bind_group,dispatch, output_texture)
 }
 

+ 1 - 1
src/compute/mod.rs

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

+ 2 - 1
src/lib.rs

@@ -202,7 +202,7 @@ impl<'a> State<'a> {
         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 wireframe = false;
 
         let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor{
             label: Some("Pipeline Layout"),
@@ -346,6 +346,7 @@ impl<'a> State<'a> {
             compute_pass.set_pipeline(&self.compute_pipeline);
             compute_pass.set_bind_group(0, &self.heightmap2_bindgroup, &[]);
             compute_pass.dispatch_workgroups(self.dispatch.0, self.dispatch.1, 1);
+            //compute_pass.dispatch_workgroups(256, 256, 1);
         }
 
         encoder.copy_texture_to_texture(wgpu::ImageCopyTextureBase{

+ 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(16,16)
+@compute @workgroup_size(1,1)
 fn compute_main(in: ComputeInput){
     let coordonnees = in.global_invocation_id.xy;
     let dimensions = textureDimensions(heightmap_texture);
 
-    let pixel_color_1_channel = f32(coordonnees.x + coordonnees.y);
+    let pixel_color_1_channel = sin(f32(coordonnees.x + coordonnees.y)/10.);
 
     let vec4_pixel_color = vec4<f32>(pixel_color_1_channel);
 

+ 2 - 2
src/shaders/plane_shader.wgsl

@@ -41,7 +41,7 @@ fn vs_main(
     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 + (5* grayscale_height_added), 1.0);
+    out.clip_position = camera.view_proj * vec4<f32>(model.position.x,model.position.y, model.position.z + ( grayscale_height_added), 1.0);
     return out;
 }
 
@@ -49,5 +49,5 @@ fn vs_main(
 
 @fragment
 fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
-    return vec4<f32>(1.0,0.0,0.0, 1.0);
+    return vec4<f32>(0.0,0.0,1.0, 1.0);
 }

+ 53 - 0
src/shaders/plane_shader_wireframe.wgsl

@@ -0,0 +1,53 @@
+// Vertex shader
+
+struct CameraUniform {
+    view_proj: mat4x4<f32>
+}
+
+@group(0) @binding(0)
+var<uniform> camera: CameraUniform;
+
+struct VertexInput {
+    @location(0) position: vec3<f32>,
+    @location(1) color: vec3<f32>,
+    @location(2) uv: vec2<f32>,
+};
+
+struct VertexOutput {
+    @builtin(position) clip_position: vec4<f32>,
+    @location(0) color: vec3<f32>,
+};
+
+@group(1) @binding(0)
+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 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 + ( grayscale_height_added), 1.0);
+    return out;
+}
+
+// Fragment shader
+
+@fragment
+fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
+    return vec4<f32>(0.0,0.0,1.0, 1.0);
+}

+ 1 - 1
src/wireframe/wireframe_pipeline.rs

@@ -14,7 +14,7 @@ pub fn new(device: &wgpu::Device, config: &SurfaceConfiguration,camera_bind_grou
         push_constant_ranges: &[]
     });
 
-    let shader_module = device.create_shader_module(include_wgsl!("../shaders/plane_shader.wgsl"));
+    let shader_module = device.create_shader_module(include_wgsl!("../shaders/plane_shader_wireframe.wgsl"));
 
     let wireframe_pipeline = device.create_render_pipeline(&RenderPipelineDescriptor{
         label: Some("Wireframe Pipeline"),