alelievr / HDRP-Custom-Passes

A bunch of custom passes made for HDRP
MIT License
1.25k stars 136 forks source link

FPS Foreground clipping issues #58

Open chrisschwartzdev opened 4 months ago

chrisschwartzdev commented 4 months ago

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 commented 4 months ago

Hello,

Can you try the V2 of the FPS effect I just pushed on master? https://github.com/alelievr/HDRP-Custom-Passes/commit/fa6fd3c8a94d845d2178381af42ecc1158271f76

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:

chrisschwartzdev commented 4 months ago

@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 commented 4 months ago

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.