From 9936ff7852f969ebca99fed08910685dc7493a34 Mon Sep 17 00:00:00 2001 From: Dominic Date: Fri, 27 May 2022 17:23:48 -0500 Subject: [PATCH] Added gfx quality integration to the fluid sim --- CalPlayer/CalamityPlayer.cs | 10 ++++++---- Effects/FluidShaders.fx | 8 +++----- Effects/FluidShaders.xnb | Bin 8456 -> 8440 bytes FluidSimulation/FluidFieldManager.cs | 14 ++++++++++++++ ILEditing/MechanicILChanges.cs | 9 +++++---- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 092794a69b..534e9aa71a 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -5861,16 +5861,18 @@ namespace CalamityMod.CalPlayer if (totalMoonlightDyes > 0) { // Initialize the aurora drawer. - int size = 520; - int sourceArea = 3; + int size = 455; + FluidFieldManager.AdjustSizeRelativeToGraphicsQuality(ref size); + float scale = MathHelper.Max(Main.screenWidth, Main.screenHeight) / size; if (ProfanedMoonlightAuroraDrawer is null || ProfanedMoonlightAuroraDrawer.Size != size) ProfanedMoonlightAuroraDrawer = FluidFieldManager.CreateField(size, scale, 0.1f, 50f, 0.992f); + int sourceArea = (int)Math.Ceiling(6f / ProfanedMoonlightAuroraDrawer.Scale) + 1; ProfanedMoonlightAuroraDrawer.ShouldUpdate = true; ProfanedMoonlightAuroraDrawer.UpdateAction = () => { - int auroraCount = totalMoonlightDyes / 2 + 3; + int auroraCount = totalMoonlightDyes / 2 + 4; for (int i = 0; i < auroraCount; i++) { float auroraPower = MathHelper.Clamp(totalMoonlightDyes / 3f, 0f, 1f); @@ -5880,7 +5882,7 @@ namespace CalamityMod.CalPlayer Vector2 auroraVelocity = (offsetAngle / 3f + Main.GlobalTimeWrappedHourly * 0.32f).ToRotationVector2(); auroraVelocity.Y = -Math.Abs(auroraVelocity.Y); - auroraVelocity = (auroraVelocity * new Vector2(0.15f, 1f) - Vector2.UnitX * Player.velocity.X / 9f).SafeNormalize(Vector2.UnitY) * 0.04f; + auroraVelocity = (auroraVelocity * new Vector2(0.15f, 1f) - Vector2.UnitX * Player.velocity.X / 9f).SafeNormalize(Vector2.UnitY) * 0.03f; Vector2 drawPosition = Main.LocalPlayer.Center - Main.screenPosition; Vector2 auroraSpawnPosition = drawPosition - Vector2.UnitY * 15f; diff --git a/Effects/FluidShaders.fx b/Effects/FluidShaders.fx index 53fdef1325..9de856851a 100644 --- a/Effects/FluidShaders.fx +++ b/Effects/FluidShaders.fx @@ -144,11 +144,9 @@ float4 InitializeDivergence(float4 sampleColor : TEXCOORD, float2 coords : TEXCO float4 DrawField(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 { - float density = tex2D(nextStates, coords).r; - if (density < 0.05) - return 0; - - return float4(tex2D(colorField, coords).rgb, 1) * density; + float density = pow(tex2D(nextStates, coords).r, 1.84); + float3 color = tex2D(colorField, coords).rgb; + return float4(color, 1) * density; } technique Technique1 diff --git a/Effects/FluidShaders.xnb b/Effects/FluidShaders.xnb index aebb4a2c3ffa796e2716192783102c31028d639b..d0cd18cd82b4a252ed8d30e4c03ad14971e63f82 100644 GIT binary patch delta 187 zcmeBh`r*hC;pbG&%J@TJBF7xg00jny^V}cySWIpdH=g()o{?d)1EUrb1H#8VeA YFk~%Y1*zfSZ(s!LdD5^sg?))606*$4+5i9m delta 203 zcmez2*x|$x;pbG&%E+NOkz)>Lf&v4>dF~H;EG8F<8&7-?&&W2}fl-TTHrwPJ#zRc) zVv`M+jDcb)Oq$G3nRqr&V4BFt!o|f*n?r~u14unX0}wA@WME)o;NSZ2$lO diff --git a/FluidSimulation/FluidFieldManager.cs b/FluidSimulation/FluidFieldManager.cs index dce3214134..dc82c819be 100644 --- a/FluidSimulation/FluidFieldManager.cs +++ b/FluidSimulation/FluidFieldManager.cs @@ -15,6 +15,20 @@ namespace CalamityMod.FluidSimulation return field; } + public static void AdjustSizeRelativeToGraphicsQuality(ref int size, int min = 325, int max = 725) + { + float graphicsQuality = MathHelper.Clamp(Main.gfxQuality, 0f, 1f); + + // Use a quality of 0.5 for quality if it automatically updates. This is done to prevent having small changes reset the size and + // require the creation of a new field altogether. + if (Main.qaStyle == 0) + graphicsQuality = 0.5f; + + int lowerBound = (int)MathHelper.Lerp(size, min, 1f - graphicsQuality); + int upperBound = (int)MathHelper.Lerp(size, max, graphicsQuality); + size = (upperBound + lowerBound) / 2; + } + // Update logic SHOULD NOT be called manually in external parts. // A should update and update action field exist to allow for modularity with that. // The reason you should not update manually in arbitrary parts of code is because the update loop diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 0ca0b7dbca..1a94876180 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -462,7 +462,9 @@ namespace CalamityMod.ILEditing // If the blazing mouse is actually going to do damage, draw an indicator aura. if (Main.LocalPlayer.Calamity().blazingCursorDamage && !Main.mapFullscreen) { - int size = 375; + int size = 450; + FluidFieldManager.AdjustSizeRelativeToGraphicsQuality(ref size); + float scale = MathHelper.Max(Main.screenWidth, Main.screenHeight) / size; ref FluidField calamityFireDrawer = ref Main.LocalPlayer.Calamity().CalamityFireDrawer; ref Vector2 firePosition = ref Main.LocalPlayer.Calamity().FireDrawerPosition; @@ -474,6 +476,8 @@ namespace CalamityMod.ILEditing int x = (int)((drawPosition.X - firePosition.X) / calamityFireDrawer.Scale); int y = (int)((drawPosition.Y - firePosition.Y) / calamityFireDrawer.Scale); + int horizontalArea = (int)Math.Ceiling(5f / calamityFireDrawer.Scale); + int verticalArea = (int)Math.Ceiling(5f / calamityFireDrawer.Scale); calamityFireDrawer.ShouldUpdate = true; calamityFireDrawer.UpdateAction = () => @@ -484,9 +488,6 @@ namespace CalamityMod.ILEditing if (Main.LocalPlayer.hasRainbowCursor) color = Color.Lerp(color, Main.hslToRgb(Main.GlobalTimeWrappedHourly * 0.97f % 1f, 1f, 0.6f), 0.75f); - int horizontalArea = 2; - int verticalArea = 2; - for (int i = -horizontalArea; i <= horizontalArea; i++) { float offsetAngle = (float)Math.Sin(Main.GlobalTimeWrappedHourly * 6.7f) * 0.99f;