Просмотр исходного кода

Commit before night work, everything launch

Ghastrod 1 год назад
Родитель
Сommit
3d8a8baf26
2 измененных файлов с 43 добавлено и 2 удалено
  1. 1 1
      src/shaders/plane_shader.wgsl
  2. 42 1
      truc

+ 1 - 1
src/shaders/plane_shader.wgsl

@@ -23,7 +23,7 @@ fn vs_main(
 ) -> VertexOutput {
     var out: VertexOutput;
     out.color = model.color;
-    out.clip_position = camera.view_proj * vec4<f32>(model.position, 1.0);
+    out.clip_position = camera.view_proj * vec4<f32>(model.position.xyz, 1.0);
     return out;
 }
 

+ 42 - 1
truc

@@ -1 +1,42 @@
-rge
+// 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>,
+};
+
+struct VertexOutput {
+    @builtin(position) clip_position: vec4<f32>,
+    @location(0) color: vec3<f32>,
+};
+
+@group(0) @binding(0)
+var t_diffuse: texture_2d<f32>;
+@group(0) @binding(1)
+var s_diffuse: sampler;
+
+
+@vertex
+fn vs_main(
+    model: VertexInput,
+) -> VertexOutput {
+    let height_added = texturesample(t_diffuse,s_diffuse,in.tex_coords);
+    var out: VertexOutput;
+    out.color = model.color;
+    out.clip_position = camera.view_proj * vec4<f32>(model.position.x,model.position.y, model.position.z + height_added, 1.0);
+    return out;
+}
+
+// Fragment shader
+
+@fragment
+fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
+    return vec4<f32>(1.0,0.0,0.0, 1.0);
+}