Procházet zdrojové kódy

Last commit before tuesday work

Ghastrod před 1 rokem
rodič
revize
093c8797a7
2 změnil soubory, kde provedl 15 přidání a 7 odebrání
  1. 5 6
      src/lib.rs
  2. 10 1
      src/shaders/plane_shader.wgsl

+ 5 - 6
src/lib.rs

@@ -1,7 +1,7 @@
 use std::{iter, time::{Duration, Instant}};
 
 use camera::{camera_buffer, camera_controller, camera_struct::Camera, camera_uniform};
-use wgpu::{util::DeviceExt, BlendState, ColorTargetState, PipelineLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor};
+use wgpu::{include_wgsl, util::DeviceExt, BlendState, ColorTargetState, PipelineLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor};
 use winit::{
     event::*,
     event_loop::EventLoop,
@@ -115,10 +115,9 @@ impl<'a> State<'a> {
             view_formats: vec![],
         };
 
-        let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
-            label: Some("Shader 1 from shader.wgsl"),
-            source: wgpu::ShaderSource::Wgsl(include_str!("./shaders/plane_shader.wgsl").into()),
-        });
+        let shader = device.create_shader_module(
+            include_wgsl!("./shaders/plane_shader.wgsl")
+        );
         
 
         let plan1 = object::generate_plane(512,512,100.,100.);
@@ -233,7 +232,7 @@ impl<'a> State<'a> {
         });
 
         let wireframe_pipeline = wireframe::wireframe_pipeline::new(&device, &config, &camera_bind_group_layout, &diffuse_bind_group_layout);
-        let wireframe = false;
+        let wireframe = true;
         Self {
             wireframe,
             surface,

+ 10 - 1
src/shaders/plane_shader.wgsl

@@ -18,13 +18,22 @@ struct VertexOutput {
     @location(0) color: vec3<f32>,
 };
 
+@group(1) @binding(0)
+var t_diffuse: texture_2d<f32>;
+@group(1) @binding(1)
+var s_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 grayscale_height_added = height_added.x;
     var out: VertexOutput;
     out.color = model.color;
-    out.clip_position = camera.view_proj * vec4<f32>(model.position.xyz, 1.0);
+    out.clip_position = camera.view_proj * vec4<f32>(model.position.x,model.position.y, model.position.z + (100* grayscale_height_added), 1.0);
     return out;
 }