Random triangle color render mode

This commit is contained in:
Connor Slade
2025-02-15 18:58:28 -05:00
parent de034afefa
commit 506c0db84e
4 changed files with 29 additions and 13 deletions

View File

@@ -94,4 +94,4 @@
- [x] Fix requiring viewport to be visible to render preview image
- [x] Visulize mesh outside of bounging box
- [ ] Save panel layout
- [ ] Random triangle color render mode
- [x] Random triangle color render mode

View File

@@ -43,6 +43,7 @@ struct ModelUniforms {
#[repr(u8)]
pub enum RenderStyle {
Normals,
RandomTriangle,
Rended,
}
@@ -187,9 +188,16 @@ impl ModelPipeline {
}
impl RenderStyle {
pub const ALL: [RenderStyle; 3] = [
RenderStyle::Normals,
RenderStyle::RandomTriangle,
RenderStyle::Rended,
];
pub fn name(&self) -> &'static str {
match self {
RenderStyle::Normals => "Normals",
RenderStyle::RandomTriangle => "Triangles",
RenderStyle::Rended => "Rended",
}
}

View File

@@ -11,15 +11,14 @@ struct Context {
}
struct VertexInput {
@location(0)
position: vec4<f32>
@builtin(vertex_index) index: u32,
@location(0) position: vec4<f32>
}
struct VertexOutput {
@builtin(position)
position: vec4<f32>,
@location(1)
world_position: vec3<f32>
@builtin(position) position: vec4<f32>,
@location(1) world_position: vec3<f32>,
@location(2) vertex_index: u32
};
@vertex
@@ -27,6 +26,7 @@ fn vert(in: VertexInput) -> VertexOutput {
var out: VertexOutput;
out.position = context.transform * in.position;
out.world_position = (context.model_transform * in.position).xyz;
out.vertex_index = in.index;
return out;
}
@@ -42,6 +42,9 @@ fn frag(in: VertexOutput) -> @location(0) vec4<f32> {
if context.render_style == 0 {
return vec4<f32>(normal, 1.0);
} else if context.render_style == 1 {
seed = in.vertex_index;
return vec4f(rand(), rand(), rand(), 1.0);
} else {
let camera_direction = normalize(context.camera_position + context.camera_target);
@@ -61,3 +64,11 @@ fn outside_build_volume(pos: vec3<f32>) -> bool {
|| pos.y < -build.y || pos.y > build.y
|| pos.z < 0.0 || pos.x > context.build_volume.z;
}
var<private> seed: u32 = 0u;
fn rand() -> f32 {
seed = seed * 747796405u + 2891336453u;
let f = f32(seed >> 9u) / f32(1u << 23u);
return fract(f);
}

View File

@@ -35,12 +35,9 @@ pub fn ui(app: &mut App, ui: &mut Ui, _ctx: &Context) {
ComboBox::new("render_style", "Render Style")
.selected_text(app.config.render_style.name())
.show_ui(ui, |ui| {
ui.selectable_value(
&mut app.config.render_style,
RenderStyle::Normals,
"Normals",
);
ui.selectable_value(&mut app.config.render_style, RenderStyle::Rended, "Rended");
for style in RenderStyle::ALL {
ui.selectable_value(&mut app.config.render_style, style, style.name());
}
});
ComboBox::new("theme", "Theme")