From d576ea382f22f8ed3d2710b5e4e8ff1707411940 Mon Sep 17 00:00:00 2001 From: TripleFate Date: Mon, 15 Jul 2024 18:44:46 -0700 Subject: [PATCH] fixes for cutaway and reflection target inverted gravity rendering --- .../CustomHooks/Visuals.ReflectionTarget.cs | 23 +++++++++++++++---- .../ScreenTargetSystem/ScreenTargetHandler.cs | 2 +- PATCH_NOTES.txt | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Content/CustomHooks/Visuals.ReflectionTarget.cs b/Content/CustomHooks/Visuals.ReflectionTarget.cs index 905523abf..3a89080bb 100644 --- a/Content/CustomHooks/Visuals.ReflectionTarget.cs +++ b/Content/CustomHooks/Visuals.ReflectionTarget.cs @@ -1,4 +1,5 @@ -using StarlightRiver.Content.Configs; +using Microsoft.Xna.Framework.Graphics; +using StarlightRiver.Content.Configs; using StarlightRiver.Core.Systems.ScreenTargetSystem; using System; using System.Reflection; @@ -129,6 +130,11 @@ private void DrawReflectableEntities(SpriteBatch sb) { canUseTarget = false; + Vector2 storedZoom = Main.GameViewMatrix.Zoom; + Main.GameViewMatrix.Zoom = new Vector2(1, 1); + SpriteEffects storedSpriteEffects = Main.GameViewMatrix.Effects; + Main.GameViewMatrix.Effects = SpriteEffects.None; + ReflectionSubConfig reflectionConfig = ModContent.GetInstance().ReflectionConfig; Main.graphics.GraphicsDevice.Clear(Color.Transparent); @@ -186,6 +192,9 @@ private void DrawReflectableEntities(SpriteBatch sb) Overlays.Scene.Draw(sb, RenderLayers.Entities, true); + Main.GameViewMatrix.Zoom = storedZoom; + Main.GameViewMatrix.Effects = storedSpriteEffects; + canUseTarget = true; } @@ -200,8 +209,14 @@ public void DrawWallReflectionLayer(On_Main.orig_DoDraw_WallsAndBlacks orig, Mai if (ReflectionTarget.applyWallReflectionsThisFrame) { - DrawReflection(Main.spriteBatch, screenPos: Vector2.Zero, normalMap: reflectionNormalMapTarget.RenderTarget, flatOffset: new Vector2(-0.0075f, 0.016f), offsetScale: 0.05f, tintColor: Color.White, restartSpriteBatch: true); + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearClamp, default, RasterizerState.CullNone, null, Main.GameViewMatrix.TransformationMatrix); + + DrawReflection(Main.spriteBatch, screenPos: Vector2.Zero, normalMap: reflectionNormalMapTarget.RenderTarget, flatOffset: new Vector2(-0.0075f, 0.016f), offsetScale: 0.05f, tintColor: Color.White, restartSpriteBatch: false); ReflectionTarget.applyWallReflectionsThisFrame = false; + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); } } @@ -218,7 +233,7 @@ public static void DrawReflection(SpriteBatch spriteBatch, Vector2 screenPos, Te if (restartSpriteBatch) { spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearClamp, default, RasterizerState.CullNone, default, Main.GameViewMatrix.TransformationMatrix); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearClamp, default, RasterizerState.CullNone, default); } var data = new DrawData(normalMap, screenPos, sourceRect, new Color(255, 255, 255, 0)); @@ -258,7 +273,7 @@ public void drawGlassWallReflectionNormalMap(SpriteBatch spriteBatch) return; spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend, SamplerState.PointClamp, default, RasterizerState.CullNone, Filters.Scene["ReflectionMapper"].GetShader().Shader, Main.GameViewMatrix.TransformationMatrix); + spriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend, SamplerState.PointClamp, default, RasterizerState.CullNone, Filters.Scene["ReflectionMapper"].GetShader().Shader); shader.Parameters["uColor"].SetValue(new Vector3(0.5f, 0.5f, 1f)); shader.Parameters["uIntensity"].SetValue(0.5f); diff --git a/Core/Systems/ScreenTargetSystem/ScreenTargetHandler.cs b/Core/Systems/ScreenTargetSystem/ScreenTargetHandler.cs index bf743332f..6693a27f8 100644 --- a/Core/Systems/ScreenTargetSystem/ScreenTargetHandler.cs +++ b/Core/Systems/ScreenTargetSystem/ScreenTargetHandler.cs @@ -112,7 +112,7 @@ private void RenderScreens(On_Main.orig_CheckMonoliths orig) if (target.drawFunct is null) //allows for RTs which dont draw in the default loop, like the lighting tile buffers continue; - Main.spriteBatch.Begin(); + Main.spriteBatch.Begin(default, default, Main.DefaultSamplerState, default, RasterizerState.CullNone, default); Main.graphics.GraphicsDevice.SetRenderTarget(target.RenderTarget); Main.graphics.GraphicsDevice.Clear(Color.Transparent); diff --git a/PATCH_NOTES.txt b/PATCH_NOTES.txt index 6c1e929ee..82da291e6 100644 --- a/PATCH_NOTES.txt +++ b/PATCH_NOTES.txt @@ -2,3 +2,4 @@ ## Fixes - Fixed random invalid memory access crashes +- Fixes for inverted gravity rendering