diff --git a/src/common/mesh.rs b/src/common/mesh.rs index 77a7ecd..43886b1 100644 --- a/src/common/mesh.rs +++ b/src/common/mesh.rs @@ -69,8 +69,9 @@ impl MeshRegistry { let all_norms = obj.normals(); let obj_num_verts = all_verts.len(); all_verts.iter().zip(all_norms.iter()) - .for_each(|(pos, norm)| { - buf_verts.push(Vertex3::new(*pos, *norm)); + .zip(obj.uvs().iter()) + .for_each(|((pos, norm), uv)| { + buf_verts.push(Vertex3::new(*pos, *norm, *uv)); }); // buf_verts.extend(all_verts.map(|v| Vertex3::new(v.position(), v.normal().unwrap_or_default()))); diff --git a/src/gpu/vertex3.rs b/src/gpu/vertex3.rs index e043055..78c60d9 100644 --- a/src/gpu/vertex3.rs +++ b/src/gpu/vertex3.rs @@ -8,16 +8,20 @@ pub struct Vertex3 { pub(crate) position: [f32; 3], #[format(R32G32B32_SFLOAT)] pub(crate) normal: [f32; 3], + #[format(R32G32B32_SFLOAT)] + pub(crate) uv: [f32; 3], } impl Vertex3 { pub fn new( position: [f32; 3], normal: [f32; 3], + uv: [f32; 3], ) -> Self { Self { position, normal, + uv } } } diff --git a/src/shaders/triangle_frag.glsl b/src/shaders/triangle_frag.glsl index ef2cdb7..c348e44 100644 --- a/src/shaders/triangle_frag.glsl +++ b/src/shaders/triangle_frag.glsl @@ -3,6 +3,7 @@ // Per-fragment - mesh dependent information. layout(location = 0) in vec3 inFragPosition; layout(location = 1) in vec3 inNormal; +layout(location = 2) in vec3 inUv; // Per-frame information - CameraUniform struct layout(set = 0, binding = 0) uniform CameraUniform { diff --git a/src/shaders/triangle_vert.glsl b/src/shaders/triangle_vert.glsl index 81d83f7..7a0cd17 100644 --- a/src/shaders/triangle_vert.glsl +++ b/src/shaders/triangle_vert.glsl @@ -3,12 +3,13 @@ // Per-vertex information - Vertex3 struct layout(location = 0) in vec3 position; layout(location = 1) in vec3 normal; +layout(location = 2) in vec3 uv; // Per-instance information - GpuInstance struct -layout(location = 2) in vec4 transform_col1; -layout(location = 3) in vec4 transform_col2; -layout(location = 4) in vec4 transform_col3; -layout(location = 5) in vec4 transform_col4; +layout(location = 3) in vec4 transform_col1; +layout(location = 4) in vec4 transform_col2; +layout(location = 5) in vec4 transform_col3; +layout(location = 6) in vec4 transform_col4; // Per-frame information - CameraUniform struct layout(set = 0, binding = 0) uniform CameraUniform { @@ -21,6 +22,7 @@ layout(set = 0, binding = 0) uniform CameraUniform { // Outputs layout(location = 0) out vec3 outFragPosition; layout(location = 1) out vec3 outNormal; +layout(location = 2) out vec3 outUv; void main() { // We then multiply each vertex by its transform to find the correct location in the scene. @@ -31,4 +33,5 @@ void main() { gl_Position = mvp * vec4(position, 1.0f); outFragPosition = vec3(model * vec4(position, 1.0)); outNormal = normal; + outUv = uv; }