Skip to content

Commit

Permalink
Fix texture wrapping
Browse files Browse the repository at this point in the history
The original client seems to have used texture wrapping, for values that are "clearly bigger" than 1.0. We chose the cutoff value between wrapping and clamping to be 1.1 arbitrarily.
  • Loading branch information
hasenbanck committed Jan 4, 2025
1 parent f2bbc1e commit a4e478f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions korangar_util/src/texture_atlas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ pub struct AtlasAllocation {
impl AtlasAllocation {
/// Maps normalized input coordinates to normalized atlas coordinates.
pub fn map_to_atlas(&self, normalized_coordinates: Point2<f32>) -> Point2<f32> {
let x = ((normalized_coordinates.x * self.rectangle.width() as f32) + self.rectangle.min.x as f32) / self.atlas_size.x as f32;
let y = ((normalized_coordinates.y * self.rectangle.height() as f32) + self.rectangle.min.y as f32) / self.atlas_size.y as f32;
// Textured coordinates, that are "clearly bigger" than 1.0 are wrapping. There
// are some values, even though they are for example "1.0112", which are not
// wrapped in the original client. So we chose "1.1" arbitrarily as a cutoff
// point.
let wrapped = normalized_coordinates.map(|value: f32| if value > 1.1 { value.fract() } else { value });
let x = ((wrapped.x * self.rectangle.width() as f32) + self.rectangle.min.x as f32) / self.atlas_size.x as f32;
let y = ((wrapped.y * self.rectangle.height() as f32) + self.rectangle.min.y as f32) / self.atlas_size.y as f32;
Point2::new(x, y)
}
}

0 comments on commit a4e478f

Please sign in to comment.