Support non-sRGB image formats for RenderTarget::Image
#22031
+16
−32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
