-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
MSAA for textures #3254
Description
What problem does this solve or what need does it fill?
MSAA is implemented when rendering to a window, but not when rendering to a texture.
What solution would you like?
To be able to render to a texture with MSAA enabled.
What alternative(s) have you considered?
I tried following the render_to_texture example to render a second camera to a texture, but it failed due to MSAA being enabled in my app.
Adding .insert_resource(Msaa { samples: 4 }) to the example will cause this error:
2021-12-05T10:27:57.789110Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error
Caused by:
In a RenderPass
note: encoder = `<CommandBuffer-(1, 2, Metal)>`
In a set_pipeline command
note: render pipeline = `<RenderPipeline-(0, 1, Metal)>`
Render pipeline targets are incompatible with render pass
Incompatible sample count: 1 != 4
I tried to mimic render graph setup code elsewhere that inserts a resolve target node, but have been unsuccessful, because Bevy doesn't seem to support multisampled textures:
https://github.com/bevyengine/bevy/blob/main/crates/bevy_render/src/shader/shader_reflect.rs#L135
which will cause this validation failure:
https://github.com/gfx-rs/wgpu/blob/master/wgpu-core/src/device/mod.rs#L1793-L1799
Additional context
In addition to the texture not being antialiased, I can't find a good way to use MSAA at all when rendering to a texture.