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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate possibility of a custom 'flipped depth' prepass in bevy #15

Open
Shfty opened this issue Mar 18, 2023 · 5 comments
Open

Investigate possibility of a custom 'flipped depth' prepass in bevy #15

Shfty opened this issue Mar 18, 2023 · 5 comments
Labels
upstream Issue lies in an upstream repo.

Comments

@Shfty
Copy link
Contributor

Shfty commented Mar 18, 2023

Since rasterized depth can be used as a free start / end distance for raymarching, using prepasses to make both front-side and back-side depth available would ensure maximum performance regardless of whether the camera is inside or outside a given SDF's bounding mesh. (Prepass perf overhead notwithstanding.)

@Shfty
Copy link
Contributor Author

Shfty commented Mar 18, 2023

This may be achievable without a custom prepass - since separate shaders can be specified for the main pass and prepass, using a vertex shader to flip normals in one of them would allow use of rasterized fragment depth in conjunction with the pre-rendered (flipped) depth texture.

In which case, would probably have to switch to front-face culling instead of no culling; ensures backsides are always available while allowing a vertex shader to control visibility via flip.

@Shfty
Copy link
Contributor Author

Shfty commented Mar 18, 2023

Also worth investigating prepass / shadow interaction; may be a route to making SDFs cast shadows.

@Shfty
Copy link
Contributor Author

Shfty commented Mar 19, 2023

Access to the depth prepass texture from Rust shaders is blocked on a combination of limited rust-gpu support for OpImageFetch * * * Sample * (needs to be manually emitted via asm!), and what appears to be a naga bug:

Required coordinate type should have been set up by 'parse_type_image'!

@Shfty Shfty added the upstream Issue lies in an upstream repo. label Mar 19, 2023
@Shfty
Copy link
Contributor Author

Shfty commented Mar 19, 2023

Might be able to work around this similarly to uniform vs storage buffers - i.e. by forcing bevy to use a simpler depth texture format.

@Shfty
Copy link
Contributor Author

Shfty commented Mar 19, 2023

Ended up being a naga bug - patching SPIR-V passthrough into bevy results in correct behaviour.

However, the flipped-depth operation is not achievable without a custom prepass, or specialized vertex shader logic that isn't general enough for the use case. Reprojection code is in place for when this becomes available, but a working implementation will have to wait on upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Issue lies in an upstream repo.
Projects
None yet
Development

No branches or pull requests

1 participant