Skip to content

Commit e106660

Browse files
committed
mesh: Fix voxel mesh generation ignoring prefer_textures.
Part of fixing <#504>. This is the last of the bugs affecting the `emission_only` render test!
1 parent ba0ba93 commit e106660

File tree

5 files changed

+65
-12
lines changed

5 files changed

+65
-12
lines changed

Diff for: all-is-cubes-mesh/src/block_mesh/compute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub(super) fn compute_block_mesh<M: MeshTypes>(
134134
}
135135
let output_interior = &mut output.interior_vertices;
136136

137-
let texture_if_needed: Option<M::Tile> = if analysis.needs_texture {
137+
let texture_if_needed: Option<M::Tile> = if prefer_textures || analysis.needs_texture {
138138
texture::copy_voxels_to_new_texture(texture_allocator, voxels)
139139
} else {
140140
None

Diff for: all-is-cubes-mesh/src/tests.rs

+61-1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,36 @@ fn animated_atom_uses_texture() {
190190
)
191191
}
192192

193+
/// For relevantly animated blocks we always prefer textures, even if the voxels are currently all
194+
/// identical.
195+
#[test]
196+
fn animated_voxels_uses_texture() {
197+
let mut u = Universe::new();
198+
let block = Block::builder()
199+
.voxels_fn(R2, |_| const { &color_block!(Rgba::WHITE) })
200+
.unwrap()
201+
.animation_hint(block::AnimationHint::redefinition(
202+
block::AnimationChange::ColorSameCategory,
203+
))
204+
.build_into(&mut u);
205+
206+
let (allocator, _, mesh) = mesh_blocks_and_space(
207+
&Space::builder(GridAab::ORIGIN_CUBE)
208+
.filled_with(block)
209+
.build(),
210+
);
211+
212+
assert_eq!(allocator.count_allocated(), 1);
213+
assert_eq!(
214+
mesh.vertices()[0].coloring,
215+
Coloring::Texture {
216+
pos: point3(0.5, 0., 0.),
217+
clamp_min: point3(0.5, 0.5, 0.5),
218+
clamp_max: point3(0.5, 1.5, 1.5)
219+
}
220+
)
221+
}
222+
193223
/// We don't encode light emission in vertex colors (because that would lead to bloated vertices),
194224
/// so a block with light emission will use a texture, even for resolution 1.
195225
///
@@ -219,7 +249,7 @@ fn emissive_atom_uses_texture() {
219249
}
220250

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

279+
/// Test handling of the case where `color` is transparent and `light_emission` is nonzero,
280+
/// for a non-atom (non-resolution-1) block; it should have a nonempty mesh.
281+
#[test]
282+
fn emissive_only_voxels() {
283+
let mut u = Universe::new();
284+
let atom_block = Block::builder()
285+
.color(Rgba::TRANSPARENT)
286+
.light_emission(Rgb::ONE)
287+
.build();
288+
let voxel_block = Block::builder()
289+
.voxels_fn(R2, |cube| {
290+
if cube == Cube::ORIGIN {
291+
&atom_block
292+
} else {
293+
&AIR
294+
}
295+
})
296+
.unwrap()
297+
.build_into(&mut u);
298+
let (allocator, block_meshes, space_mesh) = mesh_blocks_and_space(
299+
&Space::builder(GridAab::ORIGIN_CUBE)
300+
.filled_with(voxel_block)
301+
.build(),
302+
);
303+
304+
assert!(!block_meshes[0].is_empty());
305+
assert!(!space_mesh.is_empty());
306+
assert_eq!(allocator.count_allocated(), 1);
307+
}
308+
249309
/// [`SpaceMesh`] of a 1×1×1 space has the same geometry as the contents.
250310
///
251311
/// This test compares 3 different values:
332 Bytes
Loading
1.36 KB
Loading

Diff for: test-renderers/src/test_cases.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,9 @@ async fn emission_only(mut context: RenderTestContext, transparency_option: &str
332332
};
333333
let cameras = StandardCameras::from_constant_for_test(options, COMMON_VIEWPORT, &universe);
334334

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

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

0 commit comments

Comments
 (0)