- Home /
Focal Cange + Switch FXAA to TAA -> glitch with transparent materials
Hello,
About Antialiasing, I have this script that can switch from FXAA to TAA.
(to compare results at runtime from differents angles mostly...)
And I also have a script to switch the camera focal.
Now, I noticed a funny glitch with those 2 scripts and transparent materials :
when I enter play mode already in FXAA :
I can switch the focal and everything's fine.I switch to TAA :
The focal switch still works fine.now I switch back to FXAA and I switch the focal again :
the Glitch appears here : Transparent materials are out of place
I guess you're not supposed to switch the AA method like that :) to begin with.
now why does it glitch ? why does it happen ?
top : at start
below : the glitchlink text
and small package to reproduce the "glitch"
thx !
Answer by glitchers · Jun 01, 2020 at 04:57 PM
I found the cause and fix for this. It's to do with the camera and it's projection matrix(s). Here is the git commit that fixes the issues for PostProcessing v2 - https://github.com/Unity-Technologies/PostProcessing/commit/08b1319cd47862e2837fbf1273ff32b974cfed76
I am still using V1 however for a few reasons so I needed the fix v1. It was pretty simple to get it working for changing to FAA but still using the post-processing behaviour.
I added this function to PostProcessingBehaviour
[ContextMenu("Reset Camera Projection Matrices")]
public void ResetCameraProjectionMatrices()
{
if (m_Camera)
{
m_Camera.ResetProjectionMatrix();
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
}
else
{
Debug.LogWarning("Cannot ResetCameraProjectionMatrices - no camera", this);
}
}
I then call this method just before the end of OnPreCull
, before it does the TAA jittered matrix setup. I also removed OnPostRender
as it's now obsolete.
However! These changes work until you turn off post processing altogether and then they re-appear. I tried adding the ResetCameraProjectionMatrices
function call inside OnDisable
but it doesn't work.
Changing the projection matrix stops it from updating when fieldOfView changes until you call camera.ResetProjectionMatrix()
. However calling ResetProjectionMatrix()
the issue remains. I tried calling it without also touching the nonJitteredProjectionMatrix
but that also does not work.
What I have found which does work is to set camera.useJitteredProjectionMatrixForTransparentRendering
to true inside OnDisable
. I'm not sure if it is needed but you can set it to false inside OnEnable
.
Hey @glitchers , amazing !
Thank you for your time and research.
Although, those days we're using PostProcess V3 and HDRP at work.
And this glitch doesn't happen at all with V3, I checked, switch TAA/FXAA + focal change, no glitch.
It will prove useful to some people I'm sure.
Cheers !
realized it was the same issue as this older post
https://forum.unity.com/threads/cutting-between-vcams-with-different-fovs-leaves-wrong-fov-on-the-alpha-renderstage.485865/
Answer by Symmetron · Oct 08, 2018 at 08:47 AM
I have the same problem. I want to use TAA in the high setting and FXAA for the medium setting. I start at TAA, go down to FXAA (and optionally back up to TAA) and it continues to work. But the next time I go back down to FXAA it breaks. So specifically the suspects in the code are changes to
AntialiasingModel.Method
and
PostProcessingProfile.antialiasing.settings
coupled with a change to
Camera.fieldOfView
.
As for the FOV change, I have experimented with different values and even just dropping from 90 (my default setting) to 80 causes the glitch, albeit more subtly. It gets worse the bigger the difference is.
(My current workaround is to just not mess with the AA "settings" or "method" and to instead scale from TAA on the higher settings directly down to no AA on the lowest.)
EDIT: Quick update, this does not resolve the issue. The glitch now still happens on the "no AA" setting, not on the two settings using TAA though. Since using TAA on all is not a solution this means I have no working solution right now. Will investigate more.
EDIT2: Switching between no AA and various presets of FXAA works just fine. TAA is definitely the culprit. Specifically switching to TAA and then away from TAA seems to "dirty" some system which then produces the FOV glitch whenever you're NOT using TAA.