Files
texturecraft/crates/render/src/neutral_material.rs
Rebornim dafbdf3ec7 Bake mode: the Baking Visualization panel and neutral material, as in the reference
Every overlay gets the reference's colour swatch and eyedropper: the high poly, its
matching error, the cage's surface and wireframe (separate, each with an opacity), the
missing seams and the project mesh. The panel opens as the reference's does at first
launch; its eye hides the baking meshes and greys their rows. Show for selected texture
set only filters the cage and the high poly; a hidden high poly leaves the GPU.

The UV seam overlay now marks the hard edges the UV layout does not split, on the low
poly and the cage, in the 3D and 2D views.

The project mesh can show the neutral material, picked in the 3D view's view menu:
colour, roughness, metallic, baked AO, an optional baked bent normal, and Quality as
importance-sampled reflections per pixel.
2026-11-12 04:33:37 +00:00

76 lines
3.2 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! The plain material bake mode can show the low poly with, so the bake reads without the painted colours
/// The highest Quality: reflection samples per pixel
pub const MAX_SAMPLES_PER_PIXEL: u32 = 256;
/// A plain material for the low poly in bake mode: its color comes from the low poly's overlay; its normal and occlusion are the texture set's as shown (the bake under any painted normal, height or AO)
#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(default)]
pub struct NeutralMaterial {
pub roughness: f32,
pub metallic: f32,
/// How much the texture set's ambient occlusion (baked × painted) darkens the material (0 none, 1 fully)
pub ao_intensity: f32,
/// Environment reflection samples per pixel, taken by every frame so a moving view looks like a still one
pub samples_per_pixel: u32,
/// Light the material along the baked bent normal: the open direction above each point
pub bent_normal: bool,
/// How far the diffuse light turns to the bent normal, and how much reflections facing away from it dim (0..1)
pub bent_normal_diffuse: f32,
pub bent_normal_specular: f32,
}
impl Default for NeutralMaterial {
/// Low quality (16 samples per pixel), a slightly rough half metal, most of the baked occlusion, no bent normal
fn default() -> Self {
Self {
roughness: 0.3,
metallic: 0.6,
ao_intensity: 0.75,
samples_per_pixel: 16,
bent_normal: false,
bent_normal_diffuse: 1.0,
bent_normal_specular: 1.0,
}
}
}
impl NeutralMaterial {
/// The material's shader globals: x roughness, y metallic, z AO intensity, w 1 (on)
pub(crate) fn globals(&self) -> [f32; 4] {
[self.roughness, self.metallic, self.ao_intensity, 1.0]
}
/// Reflection samples each frame takes: the whole quality, from 1 to [`MAX_SAMPLES_PER_PIXEL`] (a damaged settings file can't stall the GPU)
pub(crate) fn samples_per_frame(&self) -> u32 {
self.samples_per_pixel.clamp(1, MAX_SAMPLES_PER_PIXEL)
}
/// The bent normal's shader globals: x diffuse amount, y specular amount (both 0 while off), zw -
pub(crate) fn bent_normal_globals(&self) -> [f32; 4] {
if self.bent_normal { [self.bent_normal_diffuse, self.bent_normal_specular, 0.0, 0.0] } else { [0.0; 4] }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_frame_takes_the_whole_quality() {
let quality = |samples_per_pixel| NeutralMaterial { samples_per_pixel, ..NeutralMaterial::default() };
assert_eq!(quality(16).samples_per_frame(), 16);
assert_eq!(quality(256).samples_per_frame(), 256);
assert_eq!(quality(u32::MAX).samples_per_frame(), MAX_SAMPLES_PER_PIXEL, "a damaged file is held to the highest quality");
assert_eq!(quality(0).samples_per_frame(), 1);
}
#[test]
fn the_bent_normal_reaches_the_shader_only_when_on() {
let off = NeutralMaterial::default();
assert_eq!(off.bent_normal_globals(), [0.0; 4]);
let on = NeutralMaterial { bent_normal: true, bent_normal_diffuse: 0.5, bent_normal_specular: 0.25, ..off };
assert_eq!(on.bent_normal_globals(), [0.5, 0.25, 0.0, 0.0]);
}
}