feat: add UVs to shader pipeline

This commit is contained in:
alphafetus committed 2026-05-17 11:47:04 -04:00
1 parent 170a7ad645
commit b7e31732e6
4 files changed
+15 -6

No files matched your search

+3 -2
View File
@@ -69,8 +69,9 @@ impl MeshRegistry {
let all_norms = obj.normals(); let all_norms = obj.normals();
let obj_num_verts = all_verts.len(); let obj_num_verts = all_verts.len();
all_verts.iter().zip(all_norms.iter()) all_verts.iter().zip(all_norms.iter())
.for_each(|(pos, norm)| { .zip(obj.uvs().iter())
buf_verts.push(Vertex3::new(*pos, *norm)); .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()))); // buf_verts.extend(all_verts.map(|v| Vertex3::new(v.position(), v.normal().unwrap_or_default())));
+4
View File
@@ -8,16 +8,20 @@ pub struct Vertex3 {
pub(crate) position: [f32; 3], pub(crate) position: [f32; 3],
#[format(R32G32B32_SFLOAT)] #[format(R32G32B32_SFLOAT)]
pub(crate) normal: [f32; 3], pub(crate) normal: [f32; 3],
#[format(R32G32B32_SFLOAT)]
pub(crate) uv: [f32; 3],
} }
impl Vertex3 { impl Vertex3 {
pub fn new( pub fn new(
position: [f32; 3], position: [f32; 3],
normal: [f32; 3], normal: [f32; 3],
uv: [f32; 3],
) -> Self { ) -> Self {
Self { Self {
position, position,
normal, normal,
uv
} }
} }
} }
+1
View File
@@ -3,6 +3,7 @@
// Per-fragment - mesh dependent information. // Per-fragment - mesh dependent information.
layout(location = 0) in vec3 inFragPosition; layout(location = 0) in vec3 inFragPosition;
layout(location = 1) in vec3 inNormal; layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec3 inUv;
// Per-frame information - CameraUniform struct // Per-frame information - CameraUniform struct
layout(set = 0, binding = 0) uniform CameraUniform { layout(set = 0, binding = 0) uniform CameraUniform {
+7 -4
View File
@@ -3,12 +3,13 @@
// Per-vertex information - Vertex3 struct // Per-vertex information - Vertex3 struct
layout(location = 0) in vec3 position; layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal; layout(location = 1) in vec3 normal;
layout(location = 2) in vec3 uv;
// Per-instance information - GpuInstance struct // Per-instance information - GpuInstance struct
layout(location = 2) in vec4 transform_col1; layout(location = 3) in vec4 transform_col1;
layout(location = 3) in vec4 transform_col2; layout(location = 4) in vec4 transform_col2;
layout(location = 4) in vec4 transform_col3; layout(location = 5) in vec4 transform_col3;
layout(location = 5) in vec4 transform_col4; layout(location = 6) in vec4 transform_col4;
// Per-frame information - CameraUniform struct // Per-frame information - CameraUniform struct
layout(set = 0, binding = 0) uniform CameraUniform { layout(set = 0, binding = 0) uniform CameraUniform {
@@ -21,6 +22,7 @@ layout(set = 0, binding = 0) uniform CameraUniform {
// Outputs // Outputs
layout(location = 0) out vec3 outFragPosition; layout(location = 0) out vec3 outFragPosition;
layout(location = 1) out vec3 outNormal; layout(location = 1) out vec3 outNormal;
layout(location = 2) out vec3 outUv;
void main() { void main() {
// We then multiply each vertex by its transform to find the correct location in the scene. // 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); gl_Position = mvp * vec4(position, 1.0f);
outFragPosition = vec3(model * vec4(position, 1.0)); outFragPosition = vec3(model * vec4(position, 1.0));
outNormal = normal; outNormal = normal;
outUv = uv;
} }