Is it possible to Anti Alias a single camera?

Hello, I am using the anti-aliasing from the new Unity Post Processing stack because built-in MSAA doesn’t give the quality I need, and the performance hit is not nearly worth the quality gain. In my game I have 3 cameras: bottom UI camera, 3D mesh camera, and top UI camera.

The problem:
I need to anti-alias ONLY the 3D mesh camera, but the effect applies to everything on-screen when this camera finishes rendering and makes UI text look absolutely terrible.

To solve this, I’ve attempted to render the camera to a RenderTexture and blit the results to the screen. Running the post process behaviour will make all pixels in the RenderTexture opaque, which will cause the blit to overwrite output from other cameras.

To solve THIS, I have all objects from my intended camera write to the stencil buffer so I can only blit the pixels that were rendered to before the FXAA was applied. I was not able to apply a post process to a RenderTexture and blit the same texture to the screen on a single camera, so I do the blit on another camera. Before the other camera has a chance to blit, all stencil information is cleared. I’ve even ensured the stencil information does get written to the back buffer and not a renderTexture.

I’m at a dead end, I feel like applying AA to only a single camera should not be this difficult. Does anyone have any ideas? I’d like to avoid having to write my own AA shader, but it’s looking like that may be the only option.

Technically you are only applying FXAA to a single camera. What you’re trying to do is apply FXAA to only part of what the camera is showing, or composite into a scene after a post process AA has been applied. Neither of these are going to work very well. Even if you do get it to work you’re going to get a hard aliased edge & fringing where ever the “bottom” UI and your 3d objects overlap.

The best option I can think of is render your 3D geometry first, and then render all of your UI afterwards. Any UI you need to be behind the geometry you should use shaders that clip against the geometry with _CameraDepthTexture.

You could also try rendering the geometry to a render texture and copying just the alpha from that to another render texture and use that to composite the UI back in without AA. By default all opaque objects render 1.0 to the alpha (including the skybox), so you’d either have to make all your geometry shaders render 0.0 or make sure your background / skybox renders 0.0.