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] Fix requiring viewport to be visible to render preview image
- [x] Visulize mesh outside of bounging box - [x] Visulize mesh outside of bounging box
- [ ] Save panel layout - [ ] Save panel layout
- [ ] Random triangle color render mode - [x] Random triangle color render mode

View File

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

View File

@@ -11,15 +11,14 @@ struct Context {
} }
struct VertexInput { struct VertexInput {
@location(0) @builtin(vertex_index) index: u32,
position: vec4<f32> @location(0) position: vec4<f32>
} }
struct VertexOutput { struct VertexOutput {
@builtin(position) @builtin(position) position: vec4<f32>,
position: vec4<f32>, @location(1) world_position: vec3<f32>,
@location(1) @location(2) vertex_index: u32
world_position: vec3<f32>
}; };
@vertex @vertex
@@ -27,6 +26,7 @@ fn vert(in: VertexInput) -> VertexOutput {
var out: VertexOutput; var out: VertexOutput;
out.position = context.transform * in.position; out.position = context.transform * in.position;
out.world_position = (context.model_transform * in.position).xyz; out.world_position = (context.model_transform * in.position).xyz;
out.vertex_index = in.index;
return out; return out;
} }
@@ -42,6 +42,9 @@ fn frag(in: VertexOutput) -> @location(0) vec4<f32> {
if context.render_style == 0 { if context.render_style == 0 {
return vec4<f32>(normal, 1.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 { } else {
let camera_direction = normalize(context.camera_position + context.camera_target); 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.y < -build.y || pos.y > build.y
|| pos.z < 0.0 || pos.x > context.build_volume.z; || 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") ComboBox::new("render_style", "Render Style")
.selected_text(app.config.render_style.name()) .selected_text(app.config.render_style.name())
.show_ui(ui, |ui| { .show_ui(ui, |ui| {
ui.selectable_value( for style in RenderStyle::ALL {
&mut app.config.render_style, ui.selectable_value(&mut app.config.render_style, style, style.name());
RenderStyle::Normals, }
"Normals",
);
ui.selectable_value(&mut app.config.render_style, RenderStyle::Rended, "Rended");
}); });
ComboBox::new("theme", "Theme") ComboBox::new("theme", "Theme")