bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.13k stars 3.45k forks source link

SSAO does not work with orthographic projections #13838

Open aevyrie opened 3 months ago

aevyrie commented 3 months ago

Bevy version

0.13

What you did

Use an orthographic camera.

What went wrong

SSAO stopped working properly.

Additional information

This is visible in the bevy_editor_cam cad example. Switch between projections to see it.

https://github.com/bevyengine/bevy/assets/2632925/054d3ee7-d5ed-4a84-9e6a-1f5f4688c1e5

JMS55 commented 3 months ago

It's due to this https://github.com/bevyengine/bevy/blob/2cffd14923c9e217dc98881af6c8926fe4dc65ea/crates/bevy_pbr/src/ssao/gtao.wgsl#L76-L81.

We should probably switch this to use the view transformation code.

Affinator commented 1 month ago

It's due to this

https://github.com/bevyengine/bevy/blob/2cffd14923c9e217dc98881af6c8926fe4dc65ea/crates/bevy_pbr/src/ssao/gtao.wgsl#L76-L81 .

We should probably switch this to use the view transformation code.

Could you point me in the right direction, why this code is not working? Is t.w equal to zero? I am just starting to learn the purpose of the different transformation matrices, but I would be willing to invest some time to learn and fix this.

(all glory to orthographic projection)

Soulghost commented 1 month ago

The key of the GTAO is restoring the view space position with the assistance of the depth map. In this example, the zfar is too big, which results in very low accurary of the depth map for orthographic projection. By compare the depth texture from Bevy and Unity with the same depth format and the same scene parameters, it appears that the Unity one has higher accuracy because we can restore depth variations through normalization, but this is not possible with the Bevy one, where the z-values are almost identical across all areas. Perhaps there are differences due to various backends.