alelievr / HDRP-Custom-Passes

A bunch of custom passes made for HDRP
MIT License
1.31k stars 138 forks source link

Transparency/depth management in FPS foreground pass #39

Open gewl opened 2 years ago

gewl commented 2 years ago

Hey—I'm very new to HDRP & custom passes, this repo has been a godsend. Thanks so much for putting it together.

I'm using your FPS foreground pass to handle rendering both 3D meshes and 2D UI elements to create a HUD. I adapted the pass a little to handle both ortho and perspectival cameras, which seems to be working great.

However, I've been having some trouble with both backface rendering and handling transparent materials in the foreground layer. With the original pass from your repo, I was (seemingly arbitrarily) seeing backfaces from some meshes writing over the same mesh's frontfaces. After checking that the model's normals were correct, I seem to have fixed this by changing line 72 from:

depthState = new DepthState(false, CompareFunction.Always), to depthState = new DepthState(true, CompareFunction.LessEqual)

Also, transparent objects in the foreground layer are showing as opaque. Nothing I do to ForegroundPass.cs seems to change this behavior. Turning my camera component on (for one frame, because ForegroundPass.cs immediately turns it back off) does make the material render as transparent, but it ZWrites over everything else in the foreground layer and only alpha blends with the base camera's output. Changing the material's rendering pass to Before refraction makes the object transparent & correctly alpha blend with both the foreground and background layers, but I'd prefer not to lose refraction if possible.

Did I break something somewhere? Do you have any recommended fixes for this?

Thanks, happy to provide more info if you need it.

alelievr commented 7 months ago

Hello,

Can you try the FPS pass V2 in the latest master? It should be an improvement from the V1 even though it consumes a bit more memory