Skip to content

Commit

Permalink
mesh: Fix voxel mesh generation ignoring prefer_textures.
Browse files Browse the repository at this point in the history
Part of fixing <#504>.
This is the last of the bugs affecting the `emission_only` render test!
  • Loading branch information
kpreid committed Aug 12, 2024
1 parent ba0ba93 commit e106660
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion all-is-cubes-mesh/src/block_mesh/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub(super) fn compute_block_mesh<M: MeshTypes>(
}
let output_interior = &mut output.interior_vertices;

let texture_if_needed: Option<M::Tile> = if analysis.needs_texture {
let texture_if_needed: Option<M::Tile> = if prefer_textures || analysis.needs_texture {
texture::copy_voxels_to_new_texture(texture_allocator, voxels)
} else {
None
Expand Down
62 changes: 61 additions & 1 deletion all-is-cubes-mesh/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,36 @@ fn animated_atom_uses_texture() {
)
}

/// For relevantly animated blocks we always prefer textures, even if the voxels are currently all
/// identical.
#[test]
fn animated_voxels_uses_texture() {
let mut u = Universe::new();
let block = Block::builder()
.voxels_fn(R2, |_| const { &color_block!(Rgba::WHITE) })
.unwrap()
.animation_hint(block::AnimationHint::redefinition(
block::AnimationChange::ColorSameCategory,
))
.build_into(&mut u);

let (allocator, _, mesh) = mesh_blocks_and_space(
&Space::builder(GridAab::ORIGIN_CUBE)
.filled_with(block)
.build(),
);

assert_eq!(allocator.count_allocated(), 1);
assert_eq!(
mesh.vertices()[0].coloring,
Coloring::Texture {
pos: point3(0.5, 0., 0.),
clamp_min: point3(0.5, 0.5, 0.5),
clamp_max: point3(0.5, 1.5, 1.5)
}
)
}

/// We don't encode light emission in vertex colors (because that would lead to bloated vertices),
/// so a block with light emission will use a texture, even for resolution 1.
///
Expand Down Expand Up @@ -219,7 +249,7 @@ fn emissive_atom_uses_texture() {
}

/// Test handling of the case where `color` is transparent and `light_emission` is nonzero;
/// it should have a nonempty mesh.
/// for an atom (resolution-1) block; it should have a nonempty mesh.
#[test]
fn emissive_only_atom() {
let atom_block = Block::builder()
Expand All @@ -246,6 +276,36 @@ fn emissive_only_atom() {
)
}

/// Test handling of the case where `color` is transparent and `light_emission` is nonzero,
/// for a non-atom (non-resolution-1) block; it should have a nonempty mesh.
#[test]
fn emissive_only_voxels() {
let mut u = Universe::new();
let atom_block = Block::builder()
.color(Rgba::TRANSPARENT)
.light_emission(Rgb::ONE)
.build();
let voxel_block = Block::builder()
.voxels_fn(R2, |cube| {
if cube == Cube::ORIGIN {
&atom_block
} else {
&AIR
}
})
.unwrap()
.build_into(&mut u);
let (allocator, block_meshes, space_mesh) = mesh_blocks_and_space(
&Space::builder(GridAab::ORIGIN_CUBE)
.filled_with(voxel_block)
.build(),
);

assert!(!block_meshes[0].is_empty());
assert!(!space_mesh.is_empty());
assert_eq!(allocator.count_allocated(), 1);
}

/// [`SpaceMesh`] of a 1×1×1 space has the same geometry as the contents.
///
/// This test compares 3 different values:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 3 additions & 10 deletions test-renderers/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,9 @@ async fn emission_only(mut context: RenderTestContext, transparency_option: &str
};
let cameras = StandardCameras::from_constant_for_test(options, COMMON_VIEWPORT, &universe);

// TODO: This test doesn't currently work yet. In order to be able to run it and
// investigate its output, we mark the image as flawed so that comparison failures
// don't count.
{
let mut renderer = context.renderer(cameras);
renderer.update(None).await.unwrap();
let mut image = renderer.draw("").await.unwrap();
image.flaws.insert(Flaws::OTHER);
context.compare_image(1, image);
}
context
.render_comparison_test(1, cameras, Overlays::NONE)
.await;
}

/// Test what happens when the renderer's character goes away *after* the first frame.
Expand Down

0 comments on commit e106660

Please sign in to comment.