Skip to content

Commit

Permalink
Merge pull request #320 from perkinslr/fix-flickering-shadows
Browse files Browse the repository at this point in the history
Fix flickering shadows
  • Loading branch information
N7Huntsman authored Oct 13, 2020
2 parents 1bf9ab7 + e9ea8a1 commit 822a8af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Binary file modified Assemblies/CombatExtended.dll
100644 → 100755
Binary file not shown.
26 changes: 23 additions & 3 deletions Source/CombatExtended/CombatExtended/Projectiles/ProjectileCE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,27 @@ private float GravityFactor
}
}

private Material shadowMaterial;
private Material[] shadowMaterial;
private Material ShadowMaterial
{
get
{
if (shadowMaterial == null)
{
//Get fully black version of this.Graphic
shadowMaterial = Graphic.GetColoredVersion(ShaderDatabase.Transparent, Color.black, Color.black).MatSingle;
var g = Graphic as Graphic_Collection;
if (g!=null)
{
shadowMaterial = GetShadowMaterial(g);
}

else
{
shadowMaterial = new Material[1];
shadowMaterial[0] = Graphic.GetColoredVersion(ShaderDatabase.Transparent, Color.black, Color.black).MatSingle;
}
}
return shadowMaterial;
return shadowMaterial[Rand.Range(0, this.shadowMaterial.Length)];
}
}
#endregion
Expand Down Expand Up @@ -1003,5 +1013,15 @@ public static float GetShotAngle(float velocity, float range, float heightDiffer
#endregion

#endregion

public static Material[] GetShadowMaterial(Graphic_Collection g) {
FieldInfo subGraphics = typeof(Graphic_Collection).GetField("subGraphics", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
Graphic[] collection = (Graphic[]) subGraphics.GetValue(g);
Material[] shadows = new Material[collection.Length];
for (int i=0; i<collection.Length; i++) {
shadows[i] = collection[i].GetColoredVersion(ShaderDatabase.Transparent, Color.black, Color.black).MatSingle;
}
return shadows;
}
}
}

0 comments on commit 822a8af

Please sign in to comment.