hecrj / coffee

An opinionated 2D game engine for Rust
https://docs.rs/coffee
MIT License
1.08k stars 55 forks source link

Circles are ugly when scaled #98

Closed Ralith closed 4 years ago

Ralith commented 4 years ago

The first thing I do when drawing is scale such that graphics units match my world units, meaning that 1 unit covers many pixels on my 4k screen. Circles seem to be drawn under the assumption that no scaling is applied, so they're very polygonal.

hecrj commented 4 years ago

Graphical resources are currently unaware of transformations (this also includes Font and Text). In this particular case, Mesh tessellates shapes in stroke and fill calls by using lyon with the default tolerance.

A quick fix could be adding a Mesh::new_with_tolerance method to build a Mesh with a custom tolerance. Would you be okay with this?

However, I imagine the best kind of fix would be to defer tessellation and make it target-aware. This would make draw performance a bit unpredictable though, and we would also probably need to add limits to the Transformation type (how would we deal with non-uniform scaling?) and keep track of them in Target. I am not sure it is worth the hassle.

Another possibility would be to make Mesh have a width and height and choose a tolerance based on the shape relative size. Or maybe just directly configure a scale value on construction.

Any other ideas?

Ralith commented 4 years ago

Explicit tolerance seems like a reasonable compromise between convenience and magic, particularly if you want to hold on to a complex Mesh for reuse in later frames.

hecrj commented 4 years ago

I have implemented the Mesh::new_with_tolerance method in #100.