diff --git a/FluidSimulation/FluidField.cs b/FluidSimulation/FluidField.cs index cfc1b8c1f6..a4b01c9237 100644 --- a/FluidSimulation/FluidField.cs +++ b/FluidSimulation/FluidField.cs @@ -169,7 +169,7 @@ namespace CalamityMod.FluidSimulation diffusionFactor *= DeltaTime * Size; ApplyThingToTarget(field.NextState, () => { - Main.instance.GraphicsDevice.Textures[1] = field.PreviousState; + Main.instance.GraphicsDevice.Textures[1] = field.PreviousState.Target; CalamityShaders.FluidShaders.Value.Parameters["size"].SetValue(Size); CalamityShaders.FluidShaders.Value.Parameters["diffusionFactor"].SetValue(diffusionFactor); CalamityShaders.FluidShaders.Value.Parameters["handlingColors"].SetValue(colors); @@ -209,9 +209,9 @@ namespace CalamityMod.FluidSimulation { ApplyThingToTarget(DivergencePoissonField, () => { - Main.instance.GraphicsDevice.Textures[1] = DivergencePoissonField; + Main.instance.GraphicsDevice.Textures[1] = DivergencePoissonField.Target; Main.instance.GraphicsDevice.Textures[2] = velocities; - Main.instance.GraphicsDevice.Textures[4] = DivergenceField; + Main.instance.GraphicsDevice.Textures[4] = DivergenceField.Target; CalamityShaders.FluidShaders.Value.Parameters["size"].SetValue(Size); CalamityShaders.FluidShaders.Value.CurrentTechnique.Passes["PerformPoissonIterationPass"].Apply(); }); @@ -220,7 +220,7 @@ namespace CalamityMod.FluidSimulation ApplyThingToTarget(velocities, () => { Main.instance.GraphicsDevice.Textures[1] = velocities; - Main.instance.GraphicsDevice.Textures[3] = DivergencePoissonField; + Main.instance.GraphicsDevice.Textures[3] = DivergencePoissonField.Target; CalamityShaders.FluidShaders.Value.CurrentTechnique.Passes["ClearDivergencePass"].Apply(); }); } @@ -279,9 +279,9 @@ namespace CalamityMod.FluidSimulation Main.instance.GraphicsDevice.Clear(Color.Transparent); Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); - Main.instance.GraphicsDevice.Textures[5] = ColorField.NextState; + Main.instance.GraphicsDevice.Textures[5] = ColorField.NextState.Target; CalamityShaders.FluidShaders.Value.CurrentTechnique.Passes["DrawFluidPass"].Apply(); - Main.spriteBatch.Draw(DensityField.NextState, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1f, 0, 0f); + Main.spriteBatch.Draw(DensityField.NextState.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1f, 0, 0f); Main.spriteBatch.End(); Main.instance.GraphicsDevice.SetRenderTarget(null); @@ -323,7 +323,7 @@ namespace CalamityMod.FluidSimulation shaderPreparations?.Invoke(OutputTarget); - Main.spriteBatch.Draw(OutputTarget, drawPosition, null, Color.White, 0f, OutputTarget.Size * 0.5f, Scale, 0, 0f); + Main.spriteBatch.Draw(OutputTarget.Target, drawPosition, null, Color.White, 0f, OutputTarget.Target.Size() * 0.5f, Scale, 0, 0f); Main.spriteBatch.End(); if (needsToCallEnd) diff --git a/FluidSimulation/FluidFieldState.cs b/FluidSimulation/FluidFieldState.cs index 9a807d250e..0e9da15fbb 100644 --- a/FluidSimulation/FluidFieldState.cs +++ b/FluidSimulation/FluidFieldState.cs @@ -21,9 +21,6 @@ namespace CalamityMod.FluidSimulation public void SwapState() => Utils.Swap(ref PreviousState, ref NextState); - public RenderTarget2D FieldColorCreateCondition(int screen, int height) => - new(Main.instance.GraphicsDevice, Size, Size, true, FieldContents, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents); - public FluidFieldState(int size, SurfaceFormat fieldContents = SurfaceFormat.Color) { if (Main.dedServ) @@ -32,8 +29,9 @@ namespace CalamityMod.FluidSimulation Size = size; FieldContents = fieldContents; - PreviousState = new(false, FieldColorCreateCondition, false); - NextState = new(false, FieldColorCreateCondition, false); + var descriptor = new RenderTargetDescriptor(FieldContents, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents, true); + PreviousState = RenderTargetPool.Shared.Rent(Main.instance.GraphicsDevice, Size, Size, descriptor); + NextState = RenderTargetPool.Shared.Rent(Main.instance.GraphicsDevice, Size, Size, descriptor); } } } diff --git a/Graphics/Metaballs/DoGDistortionMetaball.cs b/Graphics/Metaballs/DoGDistortionMetaball.cs index 260f13a4a1..0c23deb9ae 100644 --- a/Graphics/Metaballs/DoGDistortionMetaball.cs +++ b/Graphics/Metaballs/DoGDistortionMetaball.cs @@ -74,7 +74,7 @@ namespace CalamityMod.Graphics.Metaballs metaballShader.Value.Parameters["edgeColor"]?.SetValue(EdgeColor.ToVector4()); metaballShader.Value.Parameters["singleFrameScreenOffset"]?.SetValue((Main.screenLastPosition - Main.screenPosition) / screenSize); - gd.Textures[1] = DoGVisualsManager.DistortionForegroundContentsTarget; + gd.Textures[1] = DoGVisualsManager.DistortionForegroundContentsTarget.Target; gd.SamplerStates[1] = SamplerState.LinearWrap; metaballShader.Value.CurrentTechnique.Passes[0].Apply(); diff --git a/Graphics/Metaballs/MetaballManager.cs b/Graphics/Metaballs/MetaballManager.cs index 868291d0cf..107f2dbeba 100644 --- a/Graphics/Metaballs/MetaballManager.cs +++ b/Graphics/Metaballs/MetaballManager.cs @@ -110,7 +110,7 @@ namespace CalamityMod.Graphics.Metaballs metaball.PrepareShaderForTarget(i); // Draw the metaball's raw contents with the shader. - Main.spriteBatch.Draw(metaball.LayerTargets[i], Vector2.Zero, Color.White); + Main.spriteBatch.Draw(metaball.LayerTargets[i].Target, Vector2.Zero, Color.White); } } diff --git a/Graphics/Renderers/BaseRenderer.cs b/Graphics/Renderers/BaseRenderer.cs index 63c838e624..cfbe060ec6 100644 --- a/Graphics/Renderers/BaseRenderer.cs +++ b/Graphics/Renderers/BaseRenderer.cs @@ -82,7 +82,7 @@ namespace CalamityMod.Graphics.Renderers /// Draw the target here. By default, just draws the target. /// /// - public virtual void DrawTarget(SpriteBatch spriteBatch) => spriteBatch.Draw(MainTarget, Vector2.Zero, Color.White); + public virtual void DrawTarget(SpriteBatch spriteBatch) => spriteBatch.Draw(MainTarget.Target, Vector2.Zero, Color.White); #endregion } } diff --git a/Graphics/Renderers/CalamityRenderers/DyeableShadersRenderer.cs b/Graphics/Renderers/CalamityRenderers/DyeableShadersRenderer.cs index 4bd0f8cc9c..f24116799b 100644 --- a/Graphics/Renderers/CalamityRenderers/DyeableShadersRenderer.cs +++ b/Graphics/Renderers/CalamityRenderers/DyeableShadersRenderer.cs @@ -189,10 +189,10 @@ namespace CalamityMod.Graphics.Renderers.CalamityRenderers // If it is dyeable, and a dye exists, apply it. This has null safety, as dyeShader can be null here. if (renderer.ShaderIsDyeable && Dyes.TryGetValue(renderer, out var dyeID) && dyeID > 0) - GameShaders.Armor.Apply(dyeID, null, new(target, Vector2.Zero, new Rectangle(0, 0, target.Width, target.Height), Color.White)); + GameShaders.Armor.Apply(dyeID, null, new(target.Target, Vector2.Zero, new Rectangle(0, 0, target.Target.Width, target.Target.Height), Color.White)); // Draw the assosiated target that has been drawn to. - spriteBatch.Draw(target, Vector2.Zero, Color.White with { A = 0 }); + spriteBatch.Draw(target.Target, Vector2.Zero, Color.White with { A = 0 }); } spriteBatch.End(); diff --git a/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs b/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs index 330a07e939..2c0fb4dcfa 100644 --- a/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs +++ b/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs @@ -95,7 +95,7 @@ namespace CalamityMod.Graphics.Renderers.CalamityRenderers blightShader.UseOpacity(0.7f); blightShader.Apply(); - spriteBatch.Draw(MainTarget, Vector2.Zero, Color.White); + spriteBatch.Draw(MainTarget.Target, Vector2.Zero, Color.White); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise); diff --git a/Skies/DoGSky.cs b/Skies/DoGSky.cs index f6d728e352..34f3f33673 100644 --- a/Skies/DoGSky.cs +++ b/Skies/DoGSky.cs @@ -415,8 +415,8 @@ namespace CalamityMod.Skies { // Impose the distortion rift contents onto the primitives via shader. var metaballShader = CalamityShaders.MetaballEdgeShader; - Texture2D distortionRiftContents = DoGVisualsManager.DistortionRiftBackgroundContentsTarget; - Texture2D distortionRift = DoGVisualsManager.DistortionRiftPrimitivesTarget; + Texture2D distortionRiftContents = DoGVisualsManager.DistortionRiftBackgroundContentsTarget.Target; + Texture2D distortionRift = DoGVisualsManager.DistortionRiftPrimitivesTarget.Target; Vector2 screenSize = new(Main.screenWidth, Main.screenHeight); diff --git a/Systems/Graphic/PixelationSystem/PixelationManager.cs b/Systems/Graphic/PixelationSystem/PixelationManager.cs index 3860255897..2a63f1ff3e 100644 --- a/Systems/Graphic/PixelationSystem/PixelationManager.cs +++ b/Systems/Graphic/PixelationSystem/PixelationManager.cs @@ -194,7 +194,7 @@ namespace CalamityMod.Systems.Graphic.PixelationSystem Main.spriteBatch.Begin(default, keyValuePair.Key, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); float targetScale = 1f / PixelationResolution; - Main.spriteBatch.Draw(keyValuePair.Value, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, targetScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(keyValuePair.Value.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, targetScale, SpriteEffects.None, 0f); Main.spriteBatch.End(); } } @@ -241,42 +241,42 @@ namespace CalamityMod.Systems.Graphic.PixelationSystem { case GeneralDrawLayer.BeforeAllTiles: if (!PixelTargets_BeforeAllTiles.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_BeforeAllTiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_BeforeAllTiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.BeforeSolidTiles: if (!PixelTargets_BeforeSolidTiles.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_BeforeSolidTiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_BeforeSolidTiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.BeforeNPCs: if (!PixelTargets_BeforeNPCs.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_BeforeNPCs[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_BeforeNPCs[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.AfterNPCs: if (!PixelTargets_AfterNPCs.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_AfterNPCs[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_AfterNPCs[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.BeforeProjectiles: if (!PixelTargets_BeforeProjectiles.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_BeforeProjectiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_BeforeProjectiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.AfterProjectiles: if (!PixelTargets_AfterProjectiles.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_AfterProjectiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_AfterProjectiles[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.AfterPlayers: if (!PixelTargets_AfterPlayers.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_AfterPlayers[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_AfterPlayers[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.AfterDusts: if (!PixelTargets_AfterDusts.ContainsKey(blendState)) - Main.QueueMainThreadAction(() => PixelTargets_AfterDusts[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))) + Main.QueueMainThreadAction(() => PixelTargets_AfterDusts[blendState] = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => ((int)(w * PixelationResolution), (int)(h * PixelationResolution)))); break; case GeneralDrawLayer.AfterEverything: