From 6cb70a2f9ffeb74507e6f555e536172855d7ff5f Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 12 Feb 2022 21:44:39 -0600 Subject: [PATCH 1/4] Removed the abyss NPC damage effect --- NPCs/CalamityGlobalNPC.cs | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index 0dba6642c3..a4e3041507 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -378,30 +378,6 @@ namespace CalamityMod.NPCs #region Life Regen public override void UpdateLifeRegen(NPC npc, ref int damage) { - int genLimit = Main.maxTilesX / 2; - int abyssChasmX = CalamityWorld.abyssSide ? genLimit - (genLimit - 135) : genLimit + (genLimit - 135); - bool abyssPosX = false; - - if (CalamityWorld.abyssSide) - { - if ((double)(npc.position.X / 16f) < abyssChasmX + 80) - abyssPosX = true; - } - else - { - if ((double)(npc.position.X / 16f) > abyssChasmX - 80) - abyssPosX = true; - } - - bool inAbyss = (npc.position.Y / 16f > (Main.rockLayer - Main.maxTilesY * 0.05)) && ((double)(npc.position.Y / 16f) <= Main.maxTilesY - 250) && abyssPosX; - bool hurtByAbyss = npc.wet && npc.damage > 0 && !npc.boss && !npc.friendly && !npc.dontTakeDamage && inAbyss && !npc.buffImmune[BuffType()] && !CalamityLists.enemyImmunityList.Contains(npc.type); - if (hurtByAbyss) - { - npc.AddBuff(BuffType(), 2); - npc.DeathSound = null; - npc.HitSound = null; - } - if (npc.damage > 0 && !npc.boss && !npc.friendly && !npc.dontTakeDamage && CalamityWorld.sulphurTiles > 30 && !npc.buffImmune[BuffID.Poisoned] && !npc.buffImmune[BuffType()]) { @@ -815,7 +791,7 @@ namespace CalamityMod.NPCs // Crush Depth if (cDepth > 0) { - int baseCrushDepthDoTValue = (int)(((hurtByAbyss ? 300 : Main.hardMode ? 36 : 12) - npc.defense) * 5 * waterDamageMult); + int baseCrushDepthDoTValue = (int)(((Main.hardMode ? 36 : 12) - npc.defense) * 5 * waterDamageMult); if (baseCrushDepthDoTValue > 0) ApplyDPSDebuff(baseCrushDepthDoTValue, baseCrushDepthDoTValue / 5, ref npc.lifeRegen, ref damage); } From ad4ad693fe024fe5b0add5958b1f894b303e8d49 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 12 Feb 2022 21:50:23 -0600 Subject: [PATCH 2/4] Fixed Crescent Moon drawcode --- Projectiles/Melee/CrescentMoonFlail.png | Bin 2346 -> 928 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Projectiles/Melee/CrescentMoonFlail.png b/Projectiles/Melee/CrescentMoonFlail.png index b9ea952ecf1e4fd65dc6b8dbdce9b93fc9b03493..8fbf7747c31d119005d008ea1d54fb4a381a00c1 100644 GIT binary patch literal 928 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 Date: Sat, 12 Feb 2022 23:30:33 -0600 Subject: [PATCH 3/4] Optional primitive Bezier edge smoothening --- Projectiles/Magic/FabRay.cs | 13 +- TrailGeneration/PrimitiveTrail.cs | 433 +++++++++++++++--------------- 2 files changed, 231 insertions(+), 215 deletions(-) diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs index 02ca07f9ee..b8210ea4fc 100644 --- a/Projectiles/Magic/FabRay.cs +++ b/Projectiles/Magic/FabRay.cs @@ -79,17 +79,22 @@ namespace CalamityMod.Projectiles.Magic return MathHelper.Lerp(0f, 32f * projectile.Opacity, expansionCompletion); } - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + { + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]) + { + DegreeOfBezierCurveCornerSmoothening = 4 + }; + } GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 32); return false; - } + } - public override bool OnTileCollide(Vector2 oldVelocity) + public override bool OnTileCollide(Vector2 oldVelocity) { projectile.penetrate--; if (projectile.penetrate <= 0) diff --git a/TrailGeneration/PrimitiveTrail.cs b/TrailGeneration/PrimitiveTrail.cs index 75ea803c74..5508905c8f 100644 --- a/TrailGeneration/PrimitiveTrail.cs +++ b/TrailGeneration/PrimitiveTrail.cs @@ -9,259 +9,270 @@ using Terraria.Graphics.Shaders; namespace CalamityMod { - public class PrimitiveTrail - { - public struct VertexPosition2DColor : IVertexType - { - public Vector2 Position; - public Color Color; - public Vector2 TextureCoordinates; - public VertexDeclaration VertexDeclaration => _vertexDeclaration; + public class PrimitiveTrail + { + public struct VertexPosition2DColor : IVertexType + { + public Vector2 Position; + public Color Color; + public Vector2 TextureCoordinates; + public VertexDeclaration VertexDeclaration => _vertexDeclaration; - private static readonly VertexDeclaration _vertexDeclaration = new VertexDeclaration(new VertexElement[] - { - new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0), - new VertexElement(8, VertexElementFormat.Color, VertexElementUsage.Color, 0), - new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), - }); - public VertexPosition2DColor(Vector2 position, Color color, Vector2 textureCoordinates) - { - Position = position; - Color = color; - TextureCoordinates = textureCoordinates; - } - } + private static readonly VertexDeclaration _vertexDeclaration = new VertexDeclaration(new VertexElement[] + { + new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0), + new VertexElement(8, VertexElementFormat.Color, VertexElementUsage.Color, 0), + new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), + }); + public VertexPosition2DColor(Vector2 position, Color color, Vector2 textureCoordinates) + { + Position = position; + Color = color; + TextureCoordinates = textureCoordinates; + } + } - public delegate float VertexWidthFunction(float completionRatio); - public delegate Color VertexColorFunction(float completionRatio); + public delegate float VertexWidthFunction(float completionRatio); + public delegate Color VertexColorFunction(float completionRatio); - public VertexWidthFunction WidthFunction; - public VertexColorFunction ColorFunction; + public int DegreeOfBezierCurveCornerSmoothening; + public VertexWidthFunction WidthFunction; + public VertexColorFunction ColorFunction; - public BasicEffect BaseEffect; - public MiscShaderData SpecialShader; - public TrailPointRetrievalFunction TrailPointFunction; + public BasicEffect BaseEffect; + public MiscShaderData SpecialShader; + public TrailPointRetrievalFunction TrailPointFunction; - public Vector2 OverridingStickPointStart = Vector2.Zero; - public Vector2 OverridingStickPointEnd = Vector2.Zero; + public Vector2 OverridingStickPointStart = Vector2.Zero; + public Vector2 OverridingStickPointEnd = Vector2.Zero; - public delegate List TrailPointRetrievalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null); + public delegate List TrailPointRetrievalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null); - public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, TrailPointRetrievalFunction pointFunction = null, MiscShaderData specialShader = null) - { - if (widthFunction is null || colorFunction is null) - throw new NullReferenceException($"In order to create a primitive trail, a non-null {(widthFunction is null ? "width" : "color")} function must be specified."); - WidthFunction = widthFunction; - ColorFunction = colorFunction; + public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, TrailPointRetrievalFunction pointFunction = null, MiscShaderData specialShader = null) + { + if (widthFunction is null || colorFunction is null) + throw new NullReferenceException($"In order to create a primitive trail, a non-null {(widthFunction is null ? "width" : "color")} function must be specified."); + WidthFunction = widthFunction; + ColorFunction = colorFunction; - // Default to bezier smoothening if nothing else is inputted. - if (pointFunction is null) - pointFunction = SmoothBezierPointRetreivalFunction; + // Default to bezier smoothening if nothing else is inputted. + if (pointFunction is null) + pointFunction = SmoothBezierPointRetreivalFunction; - TrailPointFunction = pointFunction; + TrailPointFunction = pointFunction; - if (specialShader != null) - SpecialShader = specialShader; + if (specialShader != null) + SpecialShader = specialShader; - BaseEffect = new BasicEffect(Main.instance.GraphicsDevice) - { - VertexColorEnabled = true, - TextureEnabled = false - }; - UpdateBaseEffect(out _, out _); - } + BaseEffect = new BasicEffect(Main.instance.GraphicsDevice) + { + VertexColorEnabled = true, + TextureEnabled = false + }; + UpdateBaseEffect(out _, out _); + } - public void UpdateBaseEffect(out Matrix effectProjection, out Matrix effectView) - { - CalamityUtils.CalculatePerspectiveMatricies(out effectView, out effectProjection); + public void UpdateBaseEffect(out Matrix effectProjection, out Matrix effectView) + { + CalamityUtils.CalculatePerspectiveMatricies(out effectView, out effectProjection); - BaseEffect.View = effectView; - BaseEffect.Projection = effectProjection; - } + BaseEffect.View = effectView; + BaseEffect.Projection = effectProjection; + } - public static List RigidPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable _ = null) - { - List basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList(); - List endPoints = new List(); + public static List RigidPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable _ = null) + { + List basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList(); + List endPoints = new List(); - if (basePoints.Count < 2) - { - for (int i = 0; i < basePoints.Count; i++) - basePoints[i] += generalOffset; - return basePoints; - } + if (basePoints.Count < 2) + { + for (int i = 0; i < basePoints.Count; i++) + basePoints[i] += generalOffset; + return basePoints; + } - // Remap the original positions across a certain length. - for (int i = 0; i < totalTrailPoints; i++) - { - float completionRatio = i / (float)(totalTrailPoints - 1f); - int currentIndex = (int)(completionRatio * (basePoints.Count - 1)); - Vector2 currentPoint = basePoints[currentIndex]; - Vector2 nextPoint = basePoints[(currentIndex + 1) % basePoints.Count]; - endPoints.Add(Vector2.Lerp(currentPoint, nextPoint, completionRatio * (basePoints.Count - 1) % 0.99999f) + generalOffset); - } - endPoints.Add(basePoints.Last() + generalOffset); - return endPoints; - } + // Remap the original positions across a certain length. + for (int i = 0; i < totalTrailPoints; i++) + { + float completionRatio = i / (float)(totalTrailPoints - 1f); + int currentIndex = (int)(completionRatio * (basePoints.Count - 1)); + Vector2 currentPoint = basePoints[currentIndex]; + Vector2 nextPoint = basePoints[(currentIndex + 1) % basePoints.Count]; + endPoints.Add(Vector2.Lerp(currentPoint, nextPoint, completionRatio * (basePoints.Count - 1) % 0.99999f) + generalOffset); + } + endPoints.Add(basePoints.Last() + generalOffset); + return endPoints; + } - // NOTE: Beziers can be laggy when a lot of control points are used, since our implementation - // uses a recursive Lerp that gets more computationally expensive the more original indices. - // n(n + 1)/2 linear interpolations to be precise, where n is the amount of original indices. - public static List SmoothBezierPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) - { - List controlPoints = new List(); - for (int i = 0; i < originalPositions.Count(); i++) - { - // Don't incorporate points that are zeroed out. - // They are almost certainly a result of incomplete oldPos arrays. - if (originalPositions.ElementAt(i) == Vector2.Zero) - continue; - controlPoints.Add(originalPositions.ElementAt(i) + generalOffset); - } - BezierCurve bezierCurve = new BezierCurve(controlPoints.ToArray()); - return controlPoints.Count <= 1 ? controlPoints : bezierCurve.GetPoints(totalTrailPoints); - } + // NOTE: Beziers can be laggy when a lot of control points are used, since our implementation + // uses a recursive Lerp that gets more computationally expensive the more original indices. + // n(n + 1)/2 linear interpolations to be precise, where n is the amount of original indices. + public List SmoothBezierPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) + { + List controlPoints = new List(); + for (int i = 0; i < originalPositions.Count(); i++) + { + // Don't incorporate points that are zeroed out. + // They are almost certainly a result of incomplete oldPos arrays. + if (originalPositions.ElementAt(i) == Vector2.Zero) + continue; + controlPoints.Add(originalPositions.ElementAt(i) + generalOffset); + } - // Using this method requires oldRot be supplied to the Draw method for the sake of determining how many points need to be made at a given time step. - // Furthermore, since the point count is dynamic, the point count int parameter has no purpose. It can be supplied simply with zero. - public static List SmoothCatmullRomPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int _, IEnumerable originalRotations) - { - List smoothenedPoints = new List(); - for (int i = 0; i < originalPositions.Count() - 1; i++) - { - Vector2 currentPosition = originalPositions.ElementAt(i); - Vector2 aheadPosition = originalPositions.ElementAt(i + 1); + bool pointCountCondition = DegreeOfBezierCurveCornerSmoothening <= 0 || controlPoints.Count < DegreeOfBezierCurveCornerSmoothening * 3; + int effectivePointCount = DegreeOfBezierCurveCornerSmoothening > 0 ? totalTrailPoints * DegreeOfBezierCurveCornerSmoothening : totalTrailPoints; + BezierCurve bezierCurve = new BezierCurve(controlPoints.Where((_, i) => + { + return DegreeOfBezierCurveCornerSmoothening <= 0 || + i % DegreeOfBezierCurveCornerSmoothening == 0 || + i == 0 || + i == controlPoints.Count - 1 || + pointCountCondition; + }).ToArray()); + return controlPoints.Count <= 1 ? controlPoints : bezierCurve.GetPoints(effectivePointCount); + } - // Don't incorporate points that are zeroed out. - // They are almost certainly a result of incomplete oldPos arrays. - if (currentPosition == Vector2.Zero || aheadPosition == Vector2.Zero) - continue; + // Using this method requires oldRot be supplied to the Draw method for the sake of determining how many points need to be made at a given time step. + // Furthermore, since the point count is dynamic, the point count int parameter has no purpose. It can be supplied simply with zero. + public static List SmoothCatmullRomPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int _, IEnumerable originalRotations) + { + List smoothenedPoints = new List(); + for (int i = 0; i < originalPositions.Count() - 1; i++) + { + Vector2 currentPosition = originalPositions.ElementAt(i); + Vector2 aheadPosition = originalPositions.ElementAt(i + 1); - float currentRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i)); - float aheadRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i + 1)); + // Don't incorporate points that are zeroed out. + // They are almost certainly a result of incomplete oldPos arrays. + if (currentPosition == Vector2.Zero || aheadPosition == Vector2.Zero) + continue; - // Determine the amount of extra points to draw based on the rotational offset between the two time steps. - int pointsToAdd = (int)Math.Round(Math.Abs(MathHelper.WrapAngle(aheadRotation - currentRotation)) * 8f / MathHelper.Pi); + float currentRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i)); + float aheadRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i + 1)); - // Add a base point. - smoothenedPoints.Add(currentPosition + generalOffset); + // Determine the amount of extra points to draw based on the rotational offset between the two time steps. + int pointsToAdd = (int)Math.Round(Math.Abs(MathHelper.WrapAngle(aheadRotation - currentRotation)) * 8f / MathHelper.Pi); - // If no new points are needed, skip this. - if (pointsToAdd == 0) - continue; + // Add a base point. + smoothenedPoints.Add(currentPosition + generalOffset); - float segmentLength = Vector2.Distance(currentPosition, aheadPosition); - float increment = 1f / (pointsToAdd + 2); - Vector2 backEnd = currentPosition + currentRotation.ToRotationVector2() * segmentLength; - Vector2 frontEnd = aheadPosition + aheadRotation.ToRotationVector2() * -segmentLength; + // If no new points are needed, skip this. + if (pointsToAdd == 0) + continue; - // Create smoothened points based on a Catmull-Rom spline. - for (float j = increment; j < 1f; j += increment) - smoothenedPoints.Add(Vector2.CatmullRom(backEnd, currentPosition, aheadPosition, frontEnd, j) + generalOffset); - } - return smoothenedPoints; - } + float segmentLength = Vector2.Distance(currentPosition, aheadPosition); + float increment = 1f / (pointsToAdd + 2); + Vector2 backEnd = currentPosition + currentRotation.ToRotationVector2() * segmentLength; + Vector2 frontEnd = aheadPosition + aheadRotation.ToRotationVector2() * -segmentLength; - public VertexPosition2DColor[] GetVerticesFromTrailPoints(List trailPoints) - { - VertexPosition2DColor[] vertices = new VertexPosition2DColor[trailPoints.Count * 2 - 2]; - for (int i = 0; i < trailPoints.Count - 1; i++) - { - float completionRatio = i / (float)trailPoints.Count; - float widthAtVertex = WidthFunction(completionRatio); - Color vertexColor = ColorFunction(completionRatio); + // Create smoothened points based on a Catmull-Rom spline. + for (float j = increment; j < 1f; j += increment) + smoothenedPoints.Add(Vector2.CatmullRom(backEnd, currentPosition, aheadPosition, frontEnd, j) + generalOffset); + } + return smoothenedPoints; + } - Vector2 currentPosition = trailPoints[i]; - Vector2 positionAhead = trailPoints[i + 1]; - Vector2 directionToAhead = (positionAhead - trailPoints[i]).SafeNormalize(Vector2.Zero); + public VertexPosition2DColor[] GetVerticesFromTrailPoints(List trailPoints) + { + VertexPosition2DColor[] vertices = new VertexPosition2DColor[trailPoints.Count * 2 - 2]; + for (int i = 0; i < trailPoints.Count - 1; i++) + { + float completionRatio = i / (float)trailPoints.Count; + float widthAtVertex = WidthFunction(completionRatio); + Color vertexColor = ColorFunction(completionRatio); - Vector2 leftCurrentTextureCoord = new Vector2(completionRatio, 0f); - Vector2 rightCurrentTextureCoord = new Vector2(completionRatio, 1f); + Vector2 currentPosition = trailPoints[i]; + Vector2 positionAhead = trailPoints[i + 1]; + Vector2 directionToAhead = (positionAhead - trailPoints[i]).SafeNormalize(Vector2.Zero); - // Point 90 degrees away from the direction towards the next point, and use it to mark the edges of the rectangle. - // This doesn't use RotatedBy for the sake of performance (there can potentially be a lot of trail points). - Vector2 sideDirection = new Vector2(-directionToAhead.Y, directionToAhead.X); + Vector2 leftCurrentTextureCoord = new Vector2(completionRatio, 0f); + Vector2 rightCurrentTextureCoord = new Vector2(completionRatio, 1f); - Vector2 left = currentPosition - sideDirection * widthAtVertex; - Vector2 right = currentPosition + sideDirection * widthAtVertex; - if (i == 0 && OverridingStickPointStart != Vector2.Zero) + // Point 90 degrees away from the direction towards the next point, and use it to mark the edges of the rectangle. + // This doesn't use RotatedBy for the sake of performance (there can potentially be a lot of trail points). + Vector2 sideDirection = new Vector2(-directionToAhead.Y, directionToAhead.X); + + Vector2 left = currentPosition - sideDirection * widthAtVertex; + Vector2 right = currentPosition + sideDirection * widthAtVertex; + if (i == 0 && OverridingStickPointStart != Vector2.Zero) { - left = OverridingStickPointStart; - right = OverridingStickPointEnd; - } + left = OverridingStickPointStart; + right = OverridingStickPointEnd; + } - // What this is doing, at its core, is defining a rectangle based on two triangles. - // These triangles are defined based on the width of the strip at that point. - // The resulting rectangles combined are what make the trail itself. - vertices[i * 2] = new VertexPosition2DColor(left, vertexColor, leftCurrentTextureCoord); - vertices[i * 2 + 1] = new VertexPosition2DColor(right, vertexColor, rightCurrentTextureCoord); - } + // What this is doing, at its core, is defining a rectangle based on two triangles. + // These triangles are defined based on the width of the strip at that point. + // The resulting rectangles combined are what make the trail itself. + vertices[i * 2] = new VertexPosition2DColor(left, vertexColor, leftCurrentTextureCoord); + vertices[i * 2 + 1] = new VertexPosition2DColor(right, vertexColor, rightCurrentTextureCoord); + } - return vertices.ToArray(); - } + return vertices.ToArray(); + } - public short[] GetIndicesFromTrailPoints(int pointCount) - { - // What this is doing is basically representing each point on the vertices list as - // indices. These indices should come together to create a tiny rectangle that acts - // as a segment on the trail. This is achieved here by splitting the indices (or rather, points) - // into 2 triangles, which requires 6 points. - // The logic here basically determines which indices are connected together. - int totalIndices = (pointCount - 1) * 6; - short[] indices = new short[totalIndices]; + public short[] GetIndicesFromTrailPoints(int pointCount) + { + // What this is doing is basically representing each point on the vertices list as + // indices. These indices should come together to create a tiny rectangle that acts + // as a segment on the trail. This is achieved here by splitting the indices (or rather, points) + // into 2 triangles, which requires 6 points. + // The logic here basically determines which indices are connected together. + int totalIndices = (pointCount - 1) * 6; + short[] indices = new short[totalIndices]; - for (int i = 0; i < pointCount - 2; i++) - { - int startingTriangleIndex = i * 6; - int connectToIndex = i * 2; - indices[startingTriangleIndex] = (short)connectToIndex; - indices[startingTriangleIndex + 1] = (short)(connectToIndex + 1); - indices[startingTriangleIndex + 2] = (short)(connectToIndex + 2); - indices[startingTriangleIndex + 3] = (short)(connectToIndex + 2); - indices[startingTriangleIndex + 4] = (short)(connectToIndex + 1); - indices[startingTriangleIndex + 5] = (short)(connectToIndex + 3); - } + for (int i = 0; i < pointCount - 2; i++) + { + int startingTriangleIndex = i * 6; + int connectToIndex = i * 2; + indices[startingTriangleIndex] = (short)connectToIndex; + indices[startingTriangleIndex + 1] = (short)(connectToIndex + 1); + indices[startingTriangleIndex + 2] = (short)(connectToIndex + 2); + indices[startingTriangleIndex + 3] = (short)(connectToIndex + 2); + indices[startingTriangleIndex + 4] = (short)(connectToIndex + 1); + indices[startingTriangleIndex + 5] = (short)(connectToIndex + 3); + } - return indices; - } + return indices; + } - public void Draw(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) - { - Main.instance.GraphicsDevice.RasterizerState = RasterizerState.CullNone; - List trailPoints = TrailPointFunction(originalPositions, generalOffset, totalTrailPoints, originalRotations); + public void Draw(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) + { + Main.instance.GraphicsDevice.RasterizerState = RasterizerState.CullNone; + List trailPoints = TrailPointFunction(originalPositions, generalOffset, totalTrailPoints, originalRotations); - // A trail with only one point or less has nothing to connect to, and therefore, can't make a trail. - if (trailPoints.Count < 2) - return; + // A trail with only one point or less has nothing to connect to, and therefore, can't make a trail. + if (trailPoints.Count < 2) + return; - // If the trail points have any NaN positions, don't draw anything. - if (trailPoints.Any(point => point.HasNaNs())) - return; + // If the trail points have any NaN positions, don't draw anything. + if (trailPoints.Any(point => point.HasNaNs())) + return; - // If the trail points are all equal, don't draw anything. - if (trailPoints.All(point => point == trailPoints[0])) - return; + // If the trail points are all equal, don't draw anything. + if (trailPoints.All(point => point == trailPoints[0])) + return; - UpdateBaseEffect(out Matrix projection, out Matrix view); - VertexPosition2DColor[] vertices = GetVerticesFromTrailPoints(trailPoints); + UpdateBaseEffect(out Matrix projection, out Matrix view); + VertexPosition2DColor[] vertices = GetVerticesFromTrailPoints(trailPoints); - short[] triangleIndices = GetIndicesFromTrailPoints(trailPoints.Count); + short[] triangleIndices = GetIndicesFromTrailPoints(trailPoints.Count); - // Don't draw anything if the indicies/vertices are in any way invalid. - // If they are, the graphics engine, along with the entire game, will crash. - if (triangleIndices.Length % 6 != 0 || vertices.Length % 2 != 0) - return; + // Don't draw anything if the indicies/vertices are in any way invalid. + // If they are, the graphics engine, along with the entire game, will crash. + if (triangleIndices.Length % 6 != 0 || vertices.Length % 2 != 0) + return; - if (SpecialShader != null) - { - SpecialShader.Shader.Parameters["uWorldViewProjection"].SetValue(view * projection); - SpecialShader.Apply(); - } - else - BaseEffect.CurrentTechnique.Passes[0].Apply(); + if (SpecialShader != null) + { + SpecialShader.Shader.Parameters["uWorldViewProjection"].SetValue(view * projection); + SpecialShader.Apply(); + } + else + BaseEffect.CurrentTechnique.Passes[0].Apply(); - Main.instance.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, triangleIndices, 0, triangleIndices.Length / 3); - Main.pixelShader.CurrentTechnique.Passes[0].Apply(); - } - } -} \ No newline at end of file + Main.instance.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, triangleIndices, 0, triangleIndices.Length / 3); + Main.pixelShader.CurrentTechnique.Passes[0].Apply(); + } + } +} From 4d3b6fc95ad20e388b59d4bc002bcab735efefb7 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sun, 13 Feb 2022 11:22:16 -0600 Subject: [PATCH 4/4] Smoothening reversion as requested --- Projectiles/Magic/FabRay.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs index b8210ea4fc..7ce0648c04 100644 --- a/Projectiles/Magic/FabRay.cs +++ b/Projectiles/Magic/FabRay.cs @@ -82,12 +82,7 @@ namespace CalamityMod.Projectiles.Magic public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { if (TrailDrawer is null) - { - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]) - { - DegreeOfBezierCurveCornerSmoothening = 4 - }; - } + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 32);