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

FPS Foreground clipping issues #58

Open
valorieschwartzdev opened this issue Mar 16, 2024 · 4 comments
Open

FPS Foreground clipping issues #58

valorieschwartzdev opened this issue Mar 16, 2024 · 4 comments

Comments

@valorieschwartzdev
Copy link

I need the near-clip of the camera to be low enough to prevent clipping when the weapon is very close to the screen (i.e. when recoil pushes the weapon back). I'm using a value of 0.03 which seems reasonable, but the custom pass seems to break and render only the a small section of the weapon, closest to the camera, as if it is being affected by a far-clip, but it's not.

I attempted to edit the custom pass to use different near and far clip values for the FPSForegroundCamera that's made at runtime, but no matter how I tweak the values, there's some kind of clipping error.

I don't know much about custom passes and I really don't know what could be causing this issue. Perhaps it can be solved with a certain configuration, but after an hour and a half of trying to figure it out myself, I decided to make this issue.

Thanks.

@alelievr
Copy link
Owner

Hello,

Can you try the V2 of the FPS effect I just pushed on master? fa6fd3c

The old version caused a bunch of issues with screen-space effects like AO, DoF, etc as well as some weird things happening with motion-based effects (motion blur, TAA reprojection, etc.) and this new version tries to fix most of these issues.

I can see why the first version had issues with depth, I needed to use a low value near the camera to avoid breaking several effects but it affects the rendering of the foreground layer itself and it's also probably causing the issue you're seeing. I'm talking specifically about this value: https://github.com/alelievr/HDRP-Custom-Passes/blob/master/Assets/CustomPasses/FPS%20Foreground/ForegroundDepthClear.shader#L58

The V2 will not have clipping issues because it doesn't touch the depth buffer of the frame before opaque objects are rendered. Instead, I'm using additional buffers to render the color of the foreground layer and then I composite the color just before post processing. The compositing overwrites the camera color, depth, and motion vectors as well as a stencil bit used to disable the temporal reprojection of TAA and TAAU that could cause ghosting because the motion vectors are wrong.
Still, some things are broken like:

  • Transparency in the foreground layer, the compositing only handles opaque objects that write depth, so any transparent object will be cut out or completely invisible. This is something you can fix at the compositing step if you need it but it depends on the game you're making since this also comes with other problems.
  • Motion blur still ghosts if you're behind a surface, I'm not too sure why but the issue is mitigated as the ghosting is only visible on the background layer and doesn't affect the foreground
  • Similarly, motion blur doesn't work near the foreground objects because it can't reproject the data as we zero out the motion vectors for all foreground objects. It ends up causing artifacts like this hallo around the foreground layer:
    image

@valorieschwartzdev
Copy link
Author

@alelievr Hey, thanks so much for working on this.

I played around with V2 a bit, and it is definitely an improvement. I can confirm that the near-clip issue is resolved, and the only sorta bummer is that transparency doesn't work in the foreground (however I think I can go without that for my game).

@alelievr
Copy link
Owner

I experimented a bit more to see how it worked with transparency support and as I thought more issues came with it but the main idea worked.

Transparent objects are composited correctly into the frame but due to the depth buffer being overwritten even for transparent objects, it creates artifacts for depth-based processes.

For example, this is the DoF that gets canceled when a transparent object is rendered in the foreground layer:
image

Similarly, motion blur is also canceled behind transparent objects.

@TimNedvyga
Copy link

@alelievr would it be possible to make it work with dynamic resolution and dlss/fsr?

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

No branches or pull requests

3 participants