remove per-vertex color

This commit is contained in:
numzero 2026-10-19 02:08:10 +03:00
parent bde8936ad0
commit ec22c4a6e4
5 changed files with 12 additions and 24 deletions

View File

@ -24,7 +24,6 @@ pub fn make_mesh_smooth(
desc: &CrownGearDesc,
visual: &CrownGearVisual,
sides: usize,
color: Vec3,
) -> MeshIndexed {
let teeth = 2.0 * desc.pitch_radius;
let inner_scale = visual.inner_radius / desc.pitch_radius;
@ -50,7 +49,6 @@ pub fn make_mesh_smooth(
let vertex = |x, z, n| Vertex {
position: rot * vec3(x, 0.0, z),
color,
normal: n,
};
mesh.vertices.extend([

View File

@ -111,7 +111,7 @@ impl Core {
600,
)
.to_mesh()
.to_standard_mesh(vec3(0.5, 0.5, 0.5))
.to_standard_mesh()
.into_indexed();
let bevel_gear_desc = bevel_gear::BevelGearDesc {
@ -128,7 +128,7 @@ impl Core {
&bevel_gear::BevelGearShape::new_blank(&bevel_gear_desc, 60),
)
.to_mesh()
.to_standard_mesh(vec3(0.5, 0.5, 0.5))
.to_standard_mesh()
.into_indexed();
let mesh_gray = render::mesh::GpuMeshIndexed::new(&device, &bevel_gear_mesh);
@ -168,6 +168,7 @@ impl Core {
mvp: proj * view,
light: vec3(0.7, 0.5, 1.0).normalize(),
_zero: 0.,
color: vec4(0.5, 0.5, 0.5, 1.0),
},
);
self.queue.submit([]); // flush buffer updates

View File

@ -1,7 +1,7 @@
use std::mem::offset_of;
use bytemuck::{Pod, Zeroable, bytes_of, cast_slice};
use glam::{Mat4, Vec3};
use glam::{Mat4, Vec3, Vec4};
use wgpu::util::DeviceExt;
pub use cpu::*;
@ -14,7 +14,6 @@ static SHADER: &str = include_str!("mesh.wgsl");
#[repr(C)]
pub struct Vertex {
pub position: Vec3,
pub color: Vec3,
pub normal: Vec3,
}
@ -24,6 +23,7 @@ pub struct Params {
pub mvp: Mat4,
pub light: Vec3,
pub _zero: f32,
pub color: Vec4,
}
pub struct GpuMesh {
@ -121,11 +121,6 @@ impl Pipeline {
},
wgpu::VertexAttribute {
shader_location: 1,
offset: offset_of!(Vertex, color) as u64,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
shader_location: 2,
offset: offset_of!(Vertex, normal) as u64,
format: wgpu::VertexFormat::Float32x3,
},

View File

@ -2,18 +2,17 @@ struct Params {
mvp: mat4x4f,
light: vec3f,
_zero: f32,
color: vec4f,
}
struct Vertex {
@location(0) position: vec3f,
@location(1) color: vec3f,
@location(2) normal: vec3f,
@location(1) normal: vec3f,
}
struct Varying {
@builtin(position) screen: vec4f,
@location(0) color: vec4f,
@location(1) normal: vec3f,
@location(0) normal: vec3f,
}
@group(0) @binding(0) var<uniform> params: Params;
@ -21,9 +20,8 @@ struct Varying {
@vertex
fn on_vertex(in: Vertex) -> Varying {
let position = params.mvp * vec4f(in.position, 1.0);
let color = vec4f(in.color, 1.0);
let normal = in.normal;
return Varying(position, color, normal);
return Varying(position, normal);
}
@fragment
@ -31,6 +29,6 @@ fn on_fragment(in: Varying) -> @location(0) vec4f {
let normal = normalize(in.normal);
let light = dot(params.light, normal);
let u = 0.5 + 0.5 * light;
let color = vec4f(u * in.color.xyz, in.color.w);
let color = vec4f(u * params.color.xyz, params.color.w);
return color;
}

View File

@ -46,7 +46,7 @@ impl<T: Copy> Mesh<T> {
}
impl Mesh<Vec3> {
pub fn to_standard_mesh(&self, color: Vec3) -> CpuMesh {
pub fn to_standard_mesh(&self) -> CpuMesh {
CpuMesh {
faces: self
.faces
@ -54,11 +54,7 @@ impl Mesh<Vec3> {
.map(|face| {
let [a, b, c] = face;
let normal = (b - a).cross(c - a).normalize();
face.map(|position| Vertex {
position,
color,
normal,
})
face.map(|position| Vertex { position, normal })
})
.collect(),
}