Преглед изворни кода

add missing normals info to meshes

narodnik пре 5 година
родитељ
комит
26347389c0
3 измењених фајлова са 11 додато и 1 уклоњено
  1. 1 1
      res/shader/shader.frag
  2. 4 0
      src/bin/dfg.rs
  3. 6 0
      src/gfx/model.rs

+ 1 - 1
res/shader/shader.frag

@@ -44,4 +44,4 @@ void main() {
     // Since lights don't typically (afaik) cast transparency, so we use
     // the alpha here at the end.
     f_color = vec4(result, object_color.a);
-}
+}

+ 4 - 0
src/bin/dfg.rs

@@ -166,21 +166,25 @@ const VERTICES: &[model::ModelVertex] = &[
     model::ModelVertex {
         position: [-1.0, 1.0, VERTEX_Z],
         tex_coords: [0.0, 0.0],
+        normal: [0.0, 0.0, -1.0],
     },
     // bottom left
     model::ModelVertex {
         position: [-1.0, 0.5, VERTEX_Z],
         tex_coords: [0.0, 1.0],
+        normal: [0.0, 0.0, -1.0],
     },
     // bottom right
     model::ModelVertex {
         position: [-0.5, 0.5, VERTEX_Z],
         tex_coords: [1.0, 1.0],
+        normal: [0.0, 0.0, -1.0],
     },
     // top right
     model::ModelVertex {
         position: [-0.5, 1.0, VERTEX_Z],
         tex_coords: [1.0, 0.0],
+        normal: [0.0, 0.0, -1.0],
     },
 ];
 

+ 6 - 0
src/gfx/model.rs

@@ -14,6 +14,7 @@ pub trait Vertex {
 pub struct ModelVertex {
     pub position: [f32; 3],
     pub tex_coords: [f32; 2],
+    pub normal: [f32; 3],
 }
 
 impl Vertex for ModelVertex {
@@ -113,6 +114,11 @@ impl Model {
                         m.mesh.positions[i * 3 + 2],
                     ],
                     tex_coords: [1.0 - m.mesh.texcoords[i * 2], m.mesh.texcoords[i * 2 + 1]],
+                    normal: [
+                        m.mesh.normals[i * 3],
+                        m.mesh.normals[i * 3 + 1],
+                        m.mesh.normals[i * 3 + 2],
+                    ],
                 });
             }