Skip to content

Commit

Permalink
Merge pull request #741 from ProjectStarlight/cutaway-fix
Browse files Browse the repository at this point in the history
fixes for cutaway and reflection target inverted gravity rendering
  • Loading branch information
ScalarVector1 authored Jul 17, 2024
2 parents bf268d3 + d576ea3 commit 78dd25d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
23 changes: 19 additions & 4 deletions Content/CustomHooks/Visuals.ReflectionTarget.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<GraphicsConfig>().ReflectionConfig;

Main.graphics.GraphicsDevice.Clear(Color.Transparent);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}

Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Core/Systems/ScreenTargetSystem/ScreenTargetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions PATCH_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

## Fixes
- Fixed random invalid memory access crashes
- Fixes for inverted gravity rendering

0 comments on commit 78dd25d

Please sign in to comment.