Skip to content

Commit

Permalink
Fix jittering icons/transparencies with TAA
Browse files Browse the repository at this point in the history
  • Loading branch information
LGhassen committed Aug 13, 2022
1 parent ca58efc commit 4dcbbcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 8 additions & 3 deletions scatterer/Effects/AntiAliasing/TemporalAntiAliasing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ public Matrix4x4 GetJitteredProjectionMatrix(Camera camera)
/// Prepares the jittered and non jittered projection matrices
public void ConfigureJitteredProjectionMatrix()
{
targetCamera.ResetProjectionMatrix();

targetCamera.nonJitteredProjectionMatrix = targetCamera.projectionMatrix;
targetCamera.projectionMatrix = GetJitteredProjectionMatrix(targetCamera);
targetCamera.useJitteredProjectionMatrixForTransparentRendering = jitterTransparencies;

Expand Down Expand Up @@ -209,8 +206,16 @@ public void OnPreCull()

public void OnPostRender()
{
ResetProjection();
targetCamera.RemoveCommandBuffer (CameraEvent.AfterForwardAlpha, temporalAACommandBuffer);
}

// This is needed otherwise transparencies jitter
public void ResetProjection()
{
targetCamera.ResetProjectionMatrix();
targetCamera.nonJitteredProjectionMatrix = targetCamera.projectionMatrix;
}

public override void Cleanup()
{
Expand Down
15 changes: 6 additions & 9 deletions scatterer/Scatterer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,17 @@ void Init()

if (mainSettings.useDepthBufferMode && (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.SPACECENTER))
{
if(mainSettings.useSubpixelMorphologicalAntialiasing || mainSettings.useTemporalAntiAliasing) //think about combining SMAA and TAA cause TAA isn't perfect either
//cleanup any forgotten/glitched AA scripts
foreach (GenericAntiAliasing AA in Resources.FindObjectsOfTypeAll(typeof(GenericAntiAliasing)))
{
//cleanup any forgotten/glitched AA scripts
foreach (GenericAntiAliasing AA in Resources.FindObjectsOfTypeAll(typeof(GenericAntiAliasing)))
if (AA)
{
if (AA)
{
AA.Cleanup();
Component.DestroyImmediate(AA);
}
AA.Cleanup();
Component.DestroyImmediate(AA);
}
}

if(mainSettings.useSubpixelMorphologicalAntialiasing)
if (mainSettings.useSubpixelMorphologicalAntialiasing)
{
SubpixelMorphologicalAntialiasing nearAA = nearCamera.gameObject.AddComponent<SubpixelMorphologicalAntialiasing>();
antiAliasingScripts.Add(nearAA);
Expand Down

0 comments on commit 4dcbbcc

Please sign in to comment.