Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flickering shadows #320

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assemblies/CombatExtended.dll
100644 → 100755
Binary file not shown.
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;
}
}
}