sebcrozet/kiss3d

Incorrect Quad Rendering

Closed this issue · 2 comments

The following code should produce a flat quad. However, the quad appears to be folded in on itself. The problem does not appear to manifest for smaller values of nodes - I first start noticing issues in my code with nodes = (1 << 6) + 1. I am using kiss3d v0.25 on Ubuntu 18.04.

fn main()
{
	let mut window = Window::new("Diamond-Square Demo");
	window.set_light(Light::StickToCamera);

	let (width, height, nodes) = (20.0, 20.0, (1 << 9) + 1);
	let mut c = window.add_quad(width, height, nodes, nodes);
	c.modify_vertices(&mut |coords| {
		coords.iter_mut().for_each(|c| c.z = 0.0);
	});
	c.recompute_normals();
	c.set_color(0.2, 0.7, 0.1);

	window.render_loop(());
}

incorrectly rendered quad

This is likely because Kiss3d uses 16-bit index buffers for maximal platform compatibility (WebGL 1.0 in particular). This means that if you have more than 65.535 distinct vertices, you will end up seeing weird artifacts like this because the extra vertices won't be addressed (the 16 bit indices will overflow).

Unfortunately the only way of working around this is to split your quad into smaller quads with less vertices.

That would be it! I had an off-by-one error that was causing artifacts to appear when using fewer vertices, but solving that showed that rendering issues happened at the 16 bit overflow.