diff --git a/Utilities/TileUtils.cs b/Utilities/TileUtils.cs index 09a581aac2..50442427ef 100644 --- a/Utilities/TileUtils.cs +++ b/Utilities/TileUtils.cs @@ -21,6 +21,7 @@ using CalamityMod.Tiles.SunkenSea; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; using Terraria.ObjectData; @@ -264,6 +265,45 @@ namespace CalamityMod return PaintID.DeepRedPaint >= paintType && paintType <= PaintID.DeepPinkPaint; } + /// + /// Draws placed wall with multiple variants, properly painted. + /// + /// The sprite batch. + /// The type of wall. + /// The x co-ordinate of the wall. + /// The y co-ordinate of the wall. + /// The offset within the spritesheet, similar to TileFrame. + /// Whether or not PreDraw is drawn + public static bool DrawMultiVariantWall(this SpriteBatch spriteBatch, int type, int i, int j, int[] sheetOffset) + { + if (spriteBatch is null) + return true; + + spriteBatch.SafeBegin(SpriteSortMode.Immediate, BatchSetting.AlphaBlend, null, Main.GameViewMatrix.TransformationMatrix, () => + { + Tile tile = Main.tile[i, j]; + Effect tileShader = Main.tileShader; + TreePaintingSettings settings = TreePaintSystemData.GetWallSettings(type); + int paintColor = tile.WallColor; + tileShader.Parameters["leafHueTestOffset"]?.SetValue(settings.HueTestOffset); + tileShader.Parameters["leafMinHue"]?.SetValue(settings.SpecialGroupMinimalHueValue); + tileShader.Parameters["leafMaxHue"]?.SetValue(settings.SpecialGroupMaximumHueValue); + tileShader.Parameters["leafMinSat"]?.SetValue(settings.SpecialGroupMinimumSaturationValue); + tileShader.Parameters["leafMaxSat"]?.SetValue(settings.SpecialGroupMaximumSaturationValue); + tileShader.Parameters["invertSpecialGroupResult"]?.SetValue(settings.InvertSpecialGroupResult); + int index = Main.ConvertPaintIdToTileShaderIndex(paintColor, settings.UseSpecialGroups, settings.UseWallShaderHacks); + tileShader.CurrentTechnique.Passes[index].Apply(); + + Texture2D sprite = TextureAssets.Wall[type].Value; + Vector2 offset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + (Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange)) - Vector2.One * 8f; + Rectangle frame = new Rectangle(sheetOffset[0] + tile.WallFrameX, sheetOffset[1] + tile.WallFrameY, 32, 32); + Color lightColor = Lighting.GetColor(i, j); + + spriteBatch.Draw(sprite, offset, frame, lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + }); + return false; + } + public static Tile ParanoidTileRetrieval(int x, int y) { if (!WorldGen.InWorld(x, y)) diff --git a/Walls/AshenSlabWall.cs b/Walls/AshenSlabWall.cs index a2d65f6c17..ba96f5121b 100644 --- a/Walls/AshenSlabWall.cs +++ b/Walls/AshenSlabWall.cs @@ -1,7 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; -using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; @@ -24,28 +23,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/AstralMonolithWall.cs b/Walls/AstralMonolithWall.cs index ab826e6ae2..4fb6c06ea1 100644 --- a/Walls/AstralMonolithWall.cs +++ b/Walls/AstralMonolithWall.cs @@ -2,7 +2,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; -using Terraria.GameContent; using Terraria.ModLoader; namespace CalamityMod.Walls @@ -23,28 +22,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/BrimstoneSlabWall.cs b/Walls/BrimstoneSlabWall.cs index 8aec81812a..3c0e87b7a2 100644 --- a/Walls/BrimstoneSlabWall.cs +++ b/Walls/BrimstoneSlabWall.cs @@ -1,7 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; -using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; @@ -29,28 +28,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/BrimstoneSlagWall.cs b/Walls/BrimstoneSlagWall.cs index 002fb585bb..8addfebb53 100644 --- a/Walls/BrimstoneSlagWall.cs +++ b/Walls/BrimstoneSlagWall.cs @@ -1,7 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; -using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; @@ -24,28 +23,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/BrimstoneSlagWallUnsafe.cs b/Walls/BrimstoneSlagWallUnsafe.cs index 5663da37f0..c861ce2802 100644 --- a/Walls/BrimstoneSlagWallUnsafe.cs +++ b/Walls/BrimstoneSlagWallUnsafe.cs @@ -1,7 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; -using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; @@ -24,28 +23,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/CryonicBrickWall.cs b/Walls/CryonicBrickWall.cs index 3d2baab04c..5f2c0ce425 100644 --- a/Walls/CryonicBrickWall.cs +++ b/Walls/CryonicBrickWall.cs @@ -24,28 +24,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/ExoPrismPanelWall.cs b/Walls/ExoPrismPanelWall.cs index ff117d1ffd..e12e5d695c 100644 --- a/Walls/ExoPrismPanelWall.cs +++ b/Walls/ExoPrismPanelWall.cs @@ -24,28 +24,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/FloralWall.cs b/Walls/FloralWall.cs index 0773f69e1d..fcd4af4b31 100644 --- a/Walls/FloralWall.cs +++ b/Walls/FloralWall.cs @@ -25,28 +25,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/PerennialBrickWall.cs b/Walls/PerennialBrickWall.cs index 292f5b34d7..8ad57d43b3 100644 --- a/Walls/PerennialBrickWall.cs +++ b/Walls/PerennialBrickWall.cs @@ -25,28 +25,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/ProfanedSlabWall.cs b/Walls/ProfanedSlabWall.cs index 4cc1a0982f..a8ca231d45 100644 --- a/Walls/ProfanedSlabWall.cs +++ b/Walls/ProfanedSlabWall.cs @@ -24,28 +24,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/RunicProfanedBrickWall.cs b/Walls/RunicProfanedBrickWall.cs index d69f38209a..abd86eace7 100644 --- a/Walls/RunicProfanedBrickWall.cs +++ b/Walls/RunicProfanedBrickWall.cs @@ -26,28 +26,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/ScorchedBoneWall.cs b/Walls/ScorchedBoneWall.cs index a8f7afb80d..65d8c1305b 100644 --- a/Walls/ScorchedBoneWall.cs +++ b/Walls/ScorchedBoneWall.cs @@ -18,28 +18,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { diff --git a/Walls/VoidstoneSlabWall.cs b/Walls/VoidstoneSlabWall.cs index 2a7e70cb03..4e8d696829 100644 --- a/Walls/VoidstoneSlabWall.cs +++ b/Walls/VoidstoneSlabWall.cs @@ -24,80 +24,13 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) { - int[] sheetOffset = new int[2] { i % 3, j % 3 }; int xPos = i % 3; int yPos = j % 3; - switch (yPos) - { - case 0: - switch (xPos) - { - case 0: - sheetOffset = new int[2] { 0, 0 }; - break; - case 1: - sheetOffset = new int[2] { 0, 1 }; - break; - case 2: - sheetOffset = new int[2] { 0, 2 }; - break; - } - break; - case 1: - switch (xPos) - { - case 0: - sheetOffset = new int[2] { 0, 3 }; - break; - case 1: - sheetOffset = new int[2] { 0, 4 }; - break; - case 2: - sheetOffset = new int[2] { 0, 0 }; - break; - } - break; - case 2: - switch (xPos) - { - case 0: - sheetOffset = new int[2] { 0, 1 }; - break; - case 1: - sheetOffset = new int[2] { 0, 2 }; - break; - case 2: - sheetOffset = new int[2] { 0, 3 }; - break; - } - break; - } - sheetOffset[0] = sheetOffset[0] * 468; + int[] sheetOffset = new int[2] { 0, (xPos + yPos * 3) % 5 }; sheetOffset[1] = sheetOffset[1] * 180; return sheetOffset; } diff --git a/Walls/VoidstoneWall.cs b/Walls/VoidstoneWall.cs index ebacecb708..3f9290c465 100644 --- a/Walls/VoidstoneWall.cs +++ b/Walls/VoidstoneWall.cs @@ -33,59 +33,46 @@ namespace CalamityMod.Walls return false; } - public static void DrawWallGlow(int wallType, int i, int j, SpriteBatch spriteBatch) + public static bool DrawWallGlow(int type, int i, int j, SpriteBatch spriteBatch) { if (GlowMask.Texture is null) - return; + return true; - Tile tile = Main.tile[i, j]; - int xLength = 32; - int xOff = 0; - - int xPos = tile.WallFrameX + xOff; - int yPos = tile.WallFrameY; - - Rectangle frame = new Rectangle(xPos, yPos, xLength, 32); - Color drawcolor; - drawcolor = WorldGen.paintColor(tile.WallColor); - drawcolor.A = 255; - Vector2 zero = new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (Main.drawToScreen) - zero = Vector2.Zero; - - Vector2 pos = new Vector2(i * 16 - (int)Main.screenPosition.X, j * 16 - (int)Main.screenPosition.Y) + zero; - Color lightColor = Lighting.GetColor(i, j, Color.White); - - spriteBatch.Draw(TextureAssets.Wall[wallType].Value, pos + new Vector2(-8 + xOff, -8), frame, lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); - - if (GlowMask.HasContentInFramePos(xPos, yPos)) + spriteBatch.SafeBegin(SpriteSortMode.Immediate, BatchSetting.AlphaBlend, null, Main.GameViewMatrix.TransformationMatrix, () => { - float brightness = 1f; - float declareThisHereToPreventRunningTheSameCalculationMultipleTimes = Main.GameUpdateCount * 0.007f; - brightness *= MathF.Sin(i / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= MathF.Sin(j / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= MathF.Sin(i * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= MathF.Sin(j * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - drawcolor *= brightness; - Color glowColor = drawcolor * 0.4f; + Tile tile = Main.tile[i, j]; + Effect tileShader = Main.tileShader; + TreePaintingSettings settings = TreePaintSystemData.GetWallSettings(type); + int paintColor = tile.WallColor; + tileShader.Parameters["leafHueTestOffset"]?.SetValue(settings.HueTestOffset); + tileShader.Parameters["leafMinHue"]?.SetValue(settings.SpecialGroupMinimalHueValue); + tileShader.Parameters["leafMaxHue"]?.SetValue(settings.SpecialGroupMaximumHueValue); + tileShader.Parameters["leafMinSat"]?.SetValue(settings.SpecialGroupMinimumSaturationValue); + tileShader.Parameters["leafMaxSat"]?.SetValue(settings.SpecialGroupMaximumSaturationValue); + tileShader.Parameters["invertSpecialGroupResult"]?.SetValue(settings.InvertSpecialGroupResult); + int index = Main.ConvertPaintIdToTileShaderIndex(paintColor, settings.UseSpecialGroups, settings.UseWallShaderHacks); + tileShader.CurrentTechnique.Passes[index].Apply(); - // For now checking for glowing frames greatly reducing the bottleneck - // But maybe we could squeeze bit more by removing the loop - for (int k = 0; k < 3; k++) + Texture2D sprite = TextureAssets.Wall[type].Value; + Vector2 offset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + (Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange)) - Vector2.One * 8f; + int yPos = tile.WallFrameY; + int xPos = tile.WallFrameX; + Rectangle frame = new Rectangle(xPos, yPos, 32, 32); + Color lightColor = Lighting.GetColor(i, j); + + spriteBatch.Draw(sprite, offset, frame, lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + + if (GlowMask.HasContentInFramePos(xPos, yPos)) { - Vector2 offset = new Vector2(Main.rand.NextFloat(-1, 1f), Main.rand.NextFloat(-1, 1f)) * 0.2f * k; - spriteBatch.Draw(GlowMask.Texture, pos + offset + new Vector2(-8 + xOff, -8), frame, glowColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + Color glowColor = Color.Lerp(lightColor, Color.White, 0.2f + MathF.Sin(Main.GameUpdateCount * 0.007f) * 0.1f); + spriteBatch.Draw(GlowMask.Texture, offset, frame, glowColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } - } - } - - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - DrawWallGlow(Type, i, j, spriteBatch); + }); return false; } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => DrawWallGlow(Type, i, j, spriteBatch); + public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; } } diff --git a/Walls/VoidstoneWallUnsafe.cs b/Walls/VoidstoneWallUnsafe.cs index ecb6dc0a0b..deee028dc4 100644 --- a/Walls/VoidstoneWallUnsafe.cs +++ b/Walls/VoidstoneWallUnsafe.cs @@ -42,59 +42,46 @@ namespace CalamityMod.Walls } } - public static void DrawWallGlow(int wallType, int i, int j, SpriteBatch spriteBatch) + public static bool DrawWallGlow(int type, int i, int j, SpriteBatch spriteBatch) { if (GlowMask.Texture is null) - return; + return true; - Tile tile = Main.tile[i, j]; - int xLength = 32; - int xOff = 0; - - int xPos = tile.WallFrameX + xOff; - int yPos = tile.WallFrameY; - - Rectangle frame = new Rectangle(xPos, yPos, xLength, 32); - Color drawcolor; - drawcolor = WorldGen.paintColor(tile.WallColor); - drawcolor.A = 255; - Vector2 zero = new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (Main.drawToScreen) - zero = Vector2.Zero; - - Vector2 pos = new Vector2((i * 16 - (int)Main.screenPosition.X), (j * 16 - (int)Main.screenPosition.Y)) + zero; - Color lightColor = Lighting.GetColor(i, j, Color.White); - - spriteBatch.Draw(TextureAssets.Wall[wallType].Value, pos + new Vector2(-8 + xOff, -8), frame, lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); - - if (GlowMask.HasContentInFramePos(xPos, yPos)) + spriteBatch.SafeBegin(SpriteSortMode.Immediate, BatchSetting.AlphaBlend, null, Main.GameViewMatrix.TransformationMatrix, () => { - float brightness = 1f; - float declareThisHereToPreventRunningTheSameCalculationMultipleTimes = Main.GameUpdateCount * 0.007f; - brightness *= MathF.Sin(i / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= MathF.Sin(j / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= MathF.Sin(i * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= MathF.Sin(j * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - drawcolor *= brightness; - Color glowColor = drawcolor * 0.4f; + Tile tile = Main.tile[i, j]; + Effect tileShader = Main.tileShader; + TreePaintingSettings settings = TreePaintSystemData.GetWallSettings(type); + int paintColor = tile.WallColor; + tileShader.Parameters["leafHueTestOffset"]?.SetValue(settings.HueTestOffset); + tileShader.Parameters["leafMinHue"]?.SetValue(settings.SpecialGroupMinimalHueValue); + tileShader.Parameters["leafMaxHue"]?.SetValue(settings.SpecialGroupMaximumHueValue); + tileShader.Parameters["leafMinSat"]?.SetValue(settings.SpecialGroupMinimumSaturationValue); + tileShader.Parameters["leafMaxSat"]?.SetValue(settings.SpecialGroupMaximumSaturationValue); + tileShader.Parameters["invertSpecialGroupResult"]?.SetValue(settings.InvertSpecialGroupResult); + int index = Main.ConvertPaintIdToTileShaderIndex(paintColor, settings.UseSpecialGroups, settings.UseWallShaderHacks); + tileShader.CurrentTechnique.Passes[index].Apply(); - // For now checking for glowing frames greatly reducing the bottleneck - // But maybe we could squeeze bit more by removing the loop - for (int k = 0; k < 3; k++) + Texture2D sprite = TextureAssets.Wall[type].Value; + Vector2 offset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + (Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange)) - Vector2.One * 8f; + int yPos = tile.WallFrameY; + int xPos = tile.WallFrameX; + Rectangle frame = new Rectangle(xPos, yPos, 32, 32); + Color lightColor = Lighting.GetColor(i, j); + + spriteBatch.Draw(sprite, offset, frame, lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + + if (GlowMask.HasContentInFramePos(xPos, yPos)) { - Vector2 offset = new Vector2(Main.rand.NextFloat(-1f, 1f), Main.rand.NextFloat(-1f, 1f)) * 0.2f * k; - spriteBatch.Draw(GlowMask.Texture, pos + offset + new Vector2(-8 + xOff, -8), frame, glowColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + Color glowColor = Color.Lerp(lightColor, Color.White, 0.2f + MathF.Sin(Main.GameUpdateCount * 0.007f) * 0.1f); + spriteBatch.Draw(GlowMask.Texture, offset, frame, glowColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } - } - } - - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - DrawWallGlow(Type, i, j, spriteBatch); + }); return false; } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => DrawWallGlow(Type, i, j, spriteBatch); + public override void KillWall(int i, int j, ref bool fail) => fail = true; public override bool CanExplode(int i, int j) => false; diff --git a/Walls/WulfrumPlatingWall.cs b/Walls/WulfrumPlatingWall.cs index 131ba934ea..32ed421549 100644 --- a/Walls/WulfrumPlatingWall.cs +++ b/Walls/WulfrumPlatingWall.cs @@ -23,28 +23,7 @@ namespace CalamityMod.Walls public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Texture2D sprite = TextureAssets.Wall[Type].Value; - Color lightColor = CalamityUtils.ApplyPaint(Main.tile[i, j].WallColor, Lighting.GetColor(i, j), false); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - zero -= new Vector2(8, 8); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - int[] sheetOffset = CreatePattern(i, j); - spriteBatch.Draw - ( - sprite, - drawOffset, - new Rectangle(sheetOffset[0] + Main.tile[i, j].WallFrameX, sheetOffset[1] + Main.tile[i, j].WallFrameY, 32, 32), - lightColor, - 0, - new Vector2(0f, 0f), - 1, - SpriteEffects.None, - 0f - ); - return false; - } + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) => spriteBatch.DrawMultiVariantWall(Type, i, j, CreatePattern(i, j)); private int[] CreatePattern(int i, int j) {