diff --git a/Effects/Compiler/WulfrumTilePing.fx b/Effects/Compiler/WulfrumTilePing.fx index 35fbc9eb28..fc44e3ecc8 100644 --- a/Effects/Compiler/WulfrumTilePing.fx +++ b/Effects/Compiler/WulfrumTilePing.fx @@ -14,9 +14,12 @@ float tileEdgeBlendStrenght; //How hard the border of a tile should get blended float4 baseTintColor; //Color of the tile's overlay float3 tileEdgeColor; //Color of the tile's edge effects float4 scanlineColor; //Color of the scanline effects - float4 waveColor; //Color of the ping wave +float4 ScanLines[10]; +int ScanLinesCount; +int verticalScanLinesIndex; + //Per tile stuff float2 tilePosition; //The position of the top left of the tile bool4 cardinalConnections; //Up, Left, Right, Down connections. @@ -46,6 +49,11 @@ int COUNT(bool4 value) return count; } +float MOD(float a, float n) +{ + return a - floor(a / n) * n; +} + float inverselerp(float x, float start, float end) { return clamp((x - start) / (end - start), 0, 1); @@ -79,6 +87,7 @@ bool cornerDrawCheck(float2 position) return COUNT(edgeChecks) < 2; } +//Gets the gradient from the tile outline effects float getOpacityFromEdge(float2 position) { //If fully surrounded, don't draw anything @@ -111,6 +120,38 @@ float getOpacityFromEdge(float2 position) return baseOpacity; } +//Gets the opacity of the scanline on the specific pixel +float getOpacityFromScanLine(float2 position) +{ + float opacity = 0; + float4 scanline; + + //x = offset from origin, y = period, z = speed, w = opacity. + for (int i = 0; i < ScanLinesCount; i++) + { + scanline = ScanLines[i]; + + float pixelPos; + if (i >= verticalScanLinesIndex) + pixelPos = (position.x + tilePosition.x / 16) % scanline.y; + + else + pixelPos = (position.y + tilePosition.y / 16) % scanline.y; + + //Custom mod in case scanline.z is negative, aka the scanline moves in the opposite direction. + float scanlinePos = MOD((scanline.x + time * scanline.z), scanline.y); + + scanlinePos -= scanlinePos % (1 / Resolution); + + pixelPos -= pixelPos % (1 / Resolution); + + if (pixelPos == scanlinePos) + opacity += scanline.w; + } + + + return opacity * (scanlineColor.a - baseTintColor.a); +} float4 main(float2 uv : TEXCOORD) : COLOR { @@ -144,6 +185,12 @@ float4 main(float2 uv : TEXCOORD) : COLOR OpacityTotal = lerp(OpacityTotal, 1, tileEdgeBlend); ColorTotal = lerp(ColorTotal, tileEdgeColor, tileEdgeBlend); + float scanlineOpacity = getOpacityFromScanLine(uv); + if (scanlineOpacity > 0) + { + OpacityTotal += scanlineOpacity; + ColorTotal = lerp(ColorTotal, scanlineColor.rgb, scanlineOpacity); + } //Fade away the border if (realPingRadius - distanceFromPingOrigin < edgeBlendOutLenght) diff --git a/Effects/Compiler/WulfrumTilePing.xnb b/Effects/Compiler/WulfrumTilePing.xnb index 909a8412f6..b744f5b7c8 100644 Binary files a/Effects/Compiler/WulfrumTilePing.xnb and b/Effects/Compiler/WulfrumTilePing.xnb differ diff --git a/Systems/TilePingerSystem.cs b/Systems/TilePingerSystem.cs index 23f4d067cc..176c47cd82 100644 --- a/Systems/TilePingerSystem.cs +++ b/Systems/TilePingerSystem.cs @@ -209,28 +209,29 @@ namespace CalamityMod.Systems tileEffect.Parameters["pingFadePoint"].SetValue(0.9f); tileEffect.Parameters["edgeBlendStrength"].SetValue(1f); tileEffect.Parameters["edgeBlendOutLenght"].SetValue(6f); - tileEffect.Parameters["tileEdgeBlendStrenght"].SetValue(1f); + tileEffect.Parameters["tileEdgeBlendStrenght"].SetValue(2f); tileEffect.Parameters["waveColor"].SetValue(Color.GreenYellow.ToVector4()); - tileEffect.Parameters["baseTintColor"].SetValue(Color.DeepSkyBlue.ToVector4() * 0.6f); - tileEffect.Parameters["scanlineColor"].SetValue(Color.YellowGreen.ToVector4() * 0.8f); + tileEffect.Parameters["baseTintColor"].SetValue(Color.DeepSkyBlue.ToVector4() * 0.5f); + tileEffect.Parameters["scanlineColor"].SetValue(Color.YellowGreen.ToVector4() * 1f); tileEffect.Parameters["tileEdgeColor"].SetValue(Color.GreenYellow.ToVector3()); tileEffect.Parameters["Resolution"].SetValue(8f); tileEffect.Parameters["time"].SetValue(Main.GameUpdateCount); Vector4[] scanLines = new Vector4[] { - new Vector4(0f, 83f, 1f, 1f), - new Vector4(39f, 40f, 0.4f, 0.5f), - new Vector4(137f, 340f, 4f, 1f), - new Vector4(39f, 40f, 0.4f, 0.5f), - new Vector4(19f, 40f, 0.4f, 0.5f) + new Vector4(0f, 4f, 0.1f, 0.5f), + new Vector4(1f, 4f, 0.1f, 0.5f), + new Vector4(37f, 60f, 0.4f, 1f), + new Vector4(2f, 6f, -0.2f, 0.3f), + new Vector4(0f, 4f, 0.1f, 0.5f), //vertical start + new Vector4(1f, 4f, 0.1f, 0.5f), + new Vector4(2f, 6f, -0.2f, 0.3f) }; - //tileEffect.Parameters["ScanLines"].SetValue(scanLines); - //tileEffect.Parameters["ScanLinesCount"].SetValue(scanLines.Length); - //tileEffect.Parameters["ScanLinesCount"].SetValue(0); - //tileEffect.Parameters["verticalScanLinesIndex"].SetValue(2); + tileEffect.Parameters["ScanLines"].SetValue(scanLines); + tileEffect.Parameters["ScanLinesCount"].SetValue(scanLines.Length); + tileEffect.Parameters["verticalScanLinesIndex"].SetValue(4); return tileEffect; }