-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Support non-sRGB image formats for RenderTarget::Image
#22031
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support non-sRGB image formats for RenderTarget::Image
#22031
Conversation
I believe it was a bug that ManualTextureView::format could be different from the format of the actual wgpu::Texture.
I believe it was a bug that OutputColorAttachment::format could have been different from the actual format of the wgpu::Texture. This also fixes bevyengine#15201
|
CI failure doesn't immediately seem relevant to my changes https://github.com/bevyengine/bevy/actions/runs/19949128748/job/57205300759?pr=22031 |
We know that main_texture_format cannot be anything but Rgba16Float or Rgba8UnormSrgb.
mate-h
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice overall cleanup! Code changes look good to me, don't really have nitpicks. Can you open a github issue for the future work on gamma correction?
| #[inline] | ||
| pub fn out_texture_format(&self) -> TextureFormat { | ||
| self.out_texture.format | ||
| self.out_texture.view.texture().format() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an important distinction here
| .cloned() | ||
| .zip(target.get_texture_format(&windows, &images, &manual_texture_views)) | ||
| .map(|(view, format)| { | ||
| OutputColorAttachment::new(view.clone(), format.add_srgb_suffix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for the linked issue, no longer include the sRGB suffix.
Objective
RenderTarget::Imagedoesn't supportRgba8UnormandBgra8Unormtexture formats (non-srgb formats) #15201Solution
OutputColorAttachment::formatcould be different from the actual underlying texture format (ofOutputColorAttachment::view). This would eventually lead to a texture format mismatch on theBlitPipeline. I removed theOutputColorAttachment::formatfield to resolve this conflict.ManualTextureView.Testing
RenderTarget::Imagedoesn't supportRgba8UnormandBgra8Unormtexture formats (non-srgb formats) #15201 no longer cause a WGPU validation error.pbrexample on native and WebGPU and it still works as before.Future Work
Although the WGPU validation error is fixed, when using a non-sRGB texture format for the GPU image in the
headless_rendererexample, the output image seems to have incorrect gamma. I think this is because the example does a byte-for-byte copy from the GPU image to the CPU image without any gamma correction; and theimagecrate saves the image assuming a nonlinear color space.I don't think we need to fix this as part of this PR, but it might be nice for
bevy_image::Image::try_into_dynamicto eventually handle the gamma correction when saving linear color images.Here you can see a comparison
With sRGBNo sRGB
