Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃 #48 API cleanup #53

Merged
merged 1 commit into from
May 30, 2024
Merged

馃 #48 API cleanup #53

merged 1 commit into from
May 30, 2024

Conversation

KYovchevski
Copy link
Collaborator

@KYovchevski KYovchevski commented May 15, 2024

In #48 we added an alternative downsampling path specifically for normal maps which renormalizes them and allows for format that have the Z-component reconstructed from X and Y. Also, due to our app using 4-channel texture for the normal maps during asset building, we needed to introduce a pixel stride parameter so we can correctly sample the normal maps.

This lead to several API changes which, in hindsight, were not done the best, such as exposing a mandatory pixel stride parameter for the downsampling function and the format getting separated from the Image struct because of the existence of two different format enums.

This PR attempts to correct these issues by doing a few things:

  • A new trait ImagePixelFormat is added which establishes an interface that both NormalMapFormat and AlbedoFormat (Previously named only Format) need to fulfil.
  • struct Image now uses a generic F: ImagePixelFormat so that the struct can be reused for both regular images and for normal maps.
  • The pixel stride parameter was moved into the Image struct. Using Image::new() will assume the stride is the same as the Format's pixel side, while a newly added Image::new_with_pixel_stride() allows a specific value to be given to the stride.
  • The format and pixel stride parameters were removed from the downsampling function signatures, as they should now be accessed from the source Image instead. downsample_normal_map requires Image to use a NormalMapFormat, while downsample and scale_alpha_to_original_coverage require AlbedoFormat to be used instead.

Copy link
Contributor

@Athosvk Athosvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes look good. Unfortunately I can't find the original feedback by @MarijnS95 that requested these changes, so I can't really know whether all concenrs were addressed, but otherwise this seems fine to go.

@KYovchevski KYovchevski force-pushed the image-pixel-format branch 2 times, most recently from 3222d61 to 70c318c Compare May 29, 2024 15:22
Comment on lines -12 to +14
Format::Rgba8Unorm
AlbedoFormat::Rgba8Unorm
} else {
Format::Rgb8Unorm
AlbedoFormat::Rgb8Unorm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use your Srgb format?

Comment on lines -15 to +17
Format::Rgba8Unorm
AlbedoFormat::Rgba8Unorm
} else {
Format::Rgb8Unorm
AlbedoFormat::Rgb8Unorm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image crate outputs Srgb, even though we don't action on it yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Srgb8 is not treated differently from the Rgb8 formats.

Comment on lines +7 to +13
pub trait ImagePixelFormat {
fn num_channel_in_memory(&self) -> usize;
fn channel_size_in_bytes(&self) -> usize;

fn pixel_size(&self) -> usize {
self.channel_size_in_bytes() * self.num_channel_in_memory()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc-comments? I'll continue reading the PR, but already have to confess that I don't understand what num_channel_in_memory() is supposed to return from just this definition.

Copy link
Member

@MarijnS95 MarijnS95 May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For API-cleanliness, maybe the trait could require : Copy, and pass self by value.

width: u32,
height: u32,
format: F,
pixel_stride_in_bytes: usize,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is to skip pixels without a meaning, i.e. an (s)rgb(a)8 loaded PNG where only the RG channels are valid for an encoded normal? Could we achieve the same by having the input texture be a plain old (s)rgb(a)8 format, and the output an r8g8normal thing however it is called?

Just thinking out loud what could happen with ambiguity between Image::format and Image::pixel_stride_in_bytes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an exact case like this in Breda, which is the normal maps there. Our pipeline pads all textures to 4 channels, normal maps included, so we need to skip the 4th channel when downsampling then.

pixel_stride_in_bytes is meant as an override of the stride that the format would imply. I think having differing input and output formats makes this much more difficult than being able to specify the stride, while also limiting us more.

@KYovchevski KYovchevski merged commit 3e33eda into main May 30, 2024
10 checks passed
@KYovchevski
Copy link
Collaborator Author

Github didn't notify me of Marijn's comments until after I had clicked squash and merge. Thanks Github.

KYovchevski added a commit that referenced this pull request May 30, 2024
KYovchevski added a commit that referenced this pull request May 30, 2024
KYovchevski added a commit that referenced this pull request Jun 7, 2024
@MarijnS95 MarijnS95 deleted the image-pixel-format branch June 11, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants