diff --git a/Backgrounds/SunkenSeaBurrowsBG.cs b/Backgrounds/SunkenSeaBurrowsBG.cs index 15286d2293..838eda9488 100644 --- a/Backgrounds/SunkenSeaBurrowsBG.cs +++ b/Backgrounds/SunkenSeaBurrowsBG.cs @@ -108,12 +108,15 @@ namespace CalamityMod.Backgrounds Main.spriteBatch.End(); Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, Main.Rasterizer, distortionShader.Shader, CalamityUtils.BackgroundMatrix); - distortionShader.Shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); - distortionShader.Shader.Parameters["distortionXSpeed"].SetValue(-0.012f); - distortionShader.Shader.Parameters["distortionYSpeed"].SetValue(0.02f); - distortionShader.Shader.Parameters["distortionStrength"].SetValue(0.035f); - distortionShader.Shader.Parameters["noiseScale"].SetValue(0.075f); - distortionShader.SetShaderTexture(distortionTexture, index: 0); + const float distortionXSpeed = -0.012f; + const float distortionYSpeed = 0.02f; + const float noiseScale = 0.075f; + const float noiseStrength = 0.035f; + Vector2 timeOffset = new Vector2(distortionXSpeed, distortionYSpeed) * Main.GlobalTimeWrappedHourly * noiseScale; + Vector2 noiseScaleStrength = new Vector2(noiseScale, noiseStrength); + distortionShader.Shader.Parameters["timeOffset"].SetValue(timeOffset); + distortionShader.Shader.Parameters["noiseScaleStrength"].SetValue(noiseScaleStrength); + distortionShader.SetShaderTexture(distortionTexture); Main.spriteBatch.Draw(WaterDistortionTarget.Target, new Rectangle(16, 16, Main.screenWidth, Main.screenHeight), Color.White); } diff --git a/Effects/BasicTextureDistortionShader.fx b/Effects/BasicTextureDistortionShader.fx index ec5cc7c77a..a9e45abb3a 100644 --- a/Effects/BasicTextureDistortionShader.fx +++ b/Effects/BasicTextureDistortionShader.fx @@ -1,30 +1,20 @@ -cbuffer DistortionParams : register(b0) -{ - float time; - float distortionXSpeed; - float distortionYSpeed; - float distortionStrength; - float noiseScale; -}; +sampler baseTexture : register(s0); +sampler distortionTexture : register(s1); -Texture2D baseTexture : register(t0); -Texture2D distortionTexture : register(t1); -SamplerState linearSampler : register(s0); +float2 timeOffset; +float2 noiseScaleStrength; -float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : SV_Target +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR { - float2 distortedCoords = coords + float2(time * distortionXSpeed, time * distortionYSpeed); - distortedCoords *= noiseScale; - float distortion = distortionTexture.Sample(linearSampler, distortedCoords).r; - - float4 returnColor = baseTexture.Sample(linearSampler, coords + distortion * distortionStrength); - return returnColor * sampleColor.a; + float2 distortedCoords = coords * noiseScaleStrength.x + timeOffset; + float distortion = tex2D(distortionTexture, distortedCoords).r * noiseScaleStrength.y; + return tex2D(baseTexture, coords + distortion) * sampleColor.a; } technique Technique1 { pass DistortionPass { - PixelShader = compile ps_4_0 PixelShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); } } diff --git a/Effects/BasicTextureDistortionShader.xnb b/Effects/BasicTextureDistortionShader.xnb index 7d0177e650..b556cca62c 100644 Binary files a/Effects/BasicTextureDistortionShader.xnb and b/Effects/BasicTextureDistortionShader.xnb differ