HDRP first person camera with custom passes

Hi all,

so recently I started to make some test in HDRP with an FPS I already made in built-in and URP. Of course I’m facing the gun clipping problem without the double camera option to sort it out.

I’ve read this post here where @ristetutureski shows an easy work around for this problem. It’s working mostly, but the problem is that when I move the camera (in every direction) I have a strange gun flickering, like if the gun is leaving a trail for few moments. This is happening at every injection point, except for the last one, “after post process”, but of course it’s very visible that the gun/hands are strange due to the lack of post processing effects. I’m almost a newbie and never heard of custom passes before. I’ve tried everything (change custom pass parameters, change camera and materials options but nothing seems to work.
Anyone experienced a similar problem or knows a solution for this?
Thanks

Hi,

We are faced the same issues in our HDRP FPS game. For preventing wall clipping we are stack to custom passes, because two camera setup are not feathable and custom shaders not solve our problems either.

We are managed to avoid flickering, but there are another problem: ambient occlusion from objects behind passes through first person objects.

First setup for no flickering and no ambient occlusion:

I. Create separate layer for first person objects; exclude it form camera culling mask.

II. Create CustomPassVolume game object with Before Post Process injection point.

III. Inherit DrawRenderersCustomPass and override Execute method:

protected override void Execute(CustomPassContext context)
{
	int ambientOcclusionTextureID = Shader.PropertyToID("_AmbientOcclusionTexture");
	context.cmd.SetGlobalTexture(ambientOcclusionTextureID , TextureXR.GetBlackTexture());
	base.Execute(context);
}

IV. Add this custom pass to previously created CustomPassVolume.

V. Set Filters Layer Mask to first person objects layer.

First setup is ready and working fine, but we don’t want to disable ambient occlusion on our arms and weapons.

Second setup, that should work fine, but it’s don’t:

I. Create separate layer for first person objects; exclude it form camera culling mask.

II. Create CustomPassVolume game object with After Opaque Depth And Normal injection point.

III. Add to it two DrawRenderersCustomPass.

IV. On both passes set Filters Layer Mask to first person objects layer.

V. On first pass set Target Color Buffer to None and Target Depth Buffer to Camera. Check Override Depth and set Depth Test to Always. Enable Write Depth.

VI. On second pass set Target Color Buffer to Camera and Target Depth Buffer to Camera. Check Override Depth and set Depth Test to Less Equal. Enable Write Depth.

This setup should just draw opaque geometry with overrided depth on top of other opaque geometry, but it is has flickering shadows and lighting and also have ambient occlusion on top of first person geometry. Seems to me like a bug, because Ambient Occlusion in HDRP code base calculated after After Opaque Depth And Normal injection point.