Quellcode durchsuchen

Optimize debug and release builds, update vertex and fragment shaders

Ghastrod vor 1 Jahr
Ursprung
Commit
0c03f0ecd4
3 geänderte Dateien mit 42 neuen und 25 gelöschten Zeilen
  1. 0 10
      Cargo.toml
  2. 2 2
      src/lib.rs
  3. 40 13
      src/shader.wgsl

+ 0 - 10
Cargo.toml

@@ -5,16 +5,6 @@ edition = "2021"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
-# Add optimizations for debug builds
-[profile.dev]
-opt-level = 3
-
-
-
-# Add optimizations for release builds
-[profile.release]
-opt-level = 3
-
 [dependencies]
 cfg-if = "1.0.0"
 winit = "0.29.15"

+ 2 - 2
src/lib.rs

@@ -352,12 +352,12 @@ impl<'a> State<'a> {
         //let vert = generate_simple_plane(0.5, 1);
         //let vert = generate_square();
 
-        let vert = DEBUG_VERT;
+        //let vert = DEBUG_VERT;
         //println!("{:?}", vert);
 
         //let vert = generate_jamie_plane(3);
 
-        //let vert = very_simple_plane(1, 0.5);
+        let vert = very_simple_plane(1, 0.5);
         println!("{:?}", vert);
 
         // Create a buffer with the vertex data

+ 40 - 13
src/shader.wgsl

@@ -1,28 +1,55 @@
 // Vertex shader
 
+// struct VertexInput {
+//     @location(0) position: vec3<f32>,
+//     @location(1) color: vec3<f32>,
+// };
+
+// struct VertexOutput {
+//     @builtin(position) clip_position: vec4<f32>,
+//     @location(0) color: vec3<f32>,
+// };
+
+// @vertex
+// fn vs_main(
+//     model: VertexInput,
+// ) -> VertexOutput {
+//     var out: VertexOutput;
+//     out.color = model.color;
+//     out.clip_position = vec4<f32>(model.position, 1.0);
+//     return out;
+// }
+
+// Fragment shader
+
+@fragment
+fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
+    return vec4<f32>(0.5,0.2,0.7, 1.0);
+}
+
+// Vertex shader
+struct CameraUniform {
+    view_proj: mat4x4<f32>,
+};
+@group(1) @binding(0) // 1.
+var<uniform> camera: CameraUniform;
+
 struct VertexInput {
     @location(0) position: vec3<f32>,
-    @location(1) color: vec3<f32>,
-};
+    @location(1) tex_coords: vec2<f32>,
+}
 
 struct VertexOutput {
     @builtin(position) clip_position: vec4<f32>,
-    @location(0) color: vec3<f32>,
-};
+    @location(0) tex_coords: vec2<f32>,
+}
 
 @vertex
 fn vs_main(
     model: VertexInput,
 ) -> VertexOutput {
     var out: VertexOutput;
-    out.color = model.color;
-    out.clip_position = vec4<f32>(model.position, 1.0);
+    out.tex_coords = model.tex_coords;
+    out.clip_position = camera.view_proj * vec4<f32>(model.position, 1.0); // 2.
     return out;
 }
-
-// Fragment shader
-
-@fragment
-fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
-    return vec4<f32>(0.5,0.2,0.7, 1.0);
-}