nanoblack visual pass pt. 1?

This commit is contained in:
Dreitone authored and Cameron Ewell committed 2026-02-15 11:12:31 -05:00
1 parent 2b900bdd90
commit ddf2c4a771
18 files changed
+686 -85

No files matched your search

+7
View File
@@ -270,6 +270,9 @@ namespace CalamityMod.Effects
// nanoblack reaper slash effect !!!!
internal static Asset<Effect> NanoblackSlashShader;
// static gaussian bloom, cannot change parameters. do not reuse this if that binds you.
internal static Asset<Effect> GaussianBloomShader;
#endregion
@@ -533,6 +536,10 @@ namespace CalamityMod.Effects
NanoblackSlashShader = LoadShader("SlashEffects/NanoblackSlash");
RegisterMiscShader(NanoblackSlashShader, "SlashPass", "NanoblackSlash");
// also my shader!!!!!!!! also by jasper!!!!! i am the apostle of gauss himself!!!!!!!!
GaussianBloomShader = LoadShader("SlashEffects/GaussianBloom");
RegisterMiscShader(GaussianBloomShader, "BloomShader", "GaussianBloom");
SunkenSeaMenuLogoWater = LoadShader("UI/SunkenSeaMenuLogoWater");
}
+75
View File
@@ -0,0 +1,75 @@
sampler uImage0 : register(s0);
float uTime;
float uHoverIntensity;
float uPixel;
float uColorResolution;
float uGrayness;
float uSpeed;
float4 uSource;
float3 uInColor;
// variations of this need to be purpose built because of hlsl limitations
// this one only does a basic gaussian bloom at fixed parameters
float gaussian(float2 i, float sigma2, float pisigma2) {
float top = exp(-((i.x * i.x) + (i.y * i.y)) / sigma2);
float bot = pisigma2;
return top / bot;
}
float2 AspectCorrectedGBlurScale(float2 resolution, float blurIntensity) {
return (1.0f.xx / resolution) * blurIntensity;
}
float4 gauss_blur(sampler sp, float2 uv, float2 scale, int samples) {
const float pi = radians(180.);
const float sigma = float(samples) * 0.25;
const float sigma2 = 2. * sigma * sigma;
const float pisigma2 = pi * sigma2;
float2 offset = float2(0, 0);
float weight = gaussian(offset, sigma2, pisigma2);
float4 color_av = tex2D(sp, uv) * weight;
float accum = weight;
for (int x = 0; x <= samples / 2; ++x) {
for (int y = 1; y <= samples / 2; ++y) {
offset = float2(x, y);
weight = gaussian(offset, sigma2, pisigma2);
color_av += tex2D(sp, uv + scale * offset) * weight;
accum += weight;
color_av += tex2D(sp, uv - scale * offset) * weight;
accum += weight;
offset = float2(-y, x);
color_av += tex2D(sp, uv + scale * offset) * weight;
accum += weight;
color_av += tex2D(sp, uv - scale * offset) * weight;
accum += weight;
}
}
float4 final = color_av / accum;
// gamma correction
final = pow(final, (1.0 / 2.2).xxxx);
return final;
}
float4 gauss_bloom(sampler sp, float2 uv, float2 scale, int samples, float4 exposure, float thresh) {
float4 bright = clamp(gauss_blur(sp, uv, scale, samples) - thresh.xxxx, 0.0f.xxxx, 1.0f.xxxx) * (1.0f / (1.0f - thresh));
return bright * exposure;
}
float4 main(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
return gauss_bloom(uImage0, coords, AspectCorrectedGBlurScale(uSource, 4.0f), 8, 1., 0.3f);
}
technique Technique1
{
pass BloomShader
{
PixelShader = compile ps_3_0 main();
}
}
Binary file not shown.
+52 -21
View File
@@ -1,11 +1,14 @@
// Judgement Cut–style horizontal slash
// HLSL for use with SanePrimitiveRenderer's custom Effect path
// Specifically SanePrimitiveRenderer. This won't work with the regular one.
// Sorry!
// HLSL for use with SanePrimitiveRenderer's custom Effect path. This shader needs to be compensated for before use.
// Specifically SanePrimitiveRenderer. This won't work with the regular PrimitiveRenderer.
// You have been warned.
matrix uTransformMatrix;
float uTime;
float3 uColor;
float uBrightness;
struct VertexShaderInput
{
float4 Position : POSITION0;
@@ -60,21 +63,33 @@ float3 chromaSlash(float2 uv, float time)
float thickness = 0.02;
float feather = 0.08;
float distort = noise(float2(uv.x * 8.0, time * 6.0)) * 0.05;
uv.y += distort * slashMask(uv, thickness * 2.0, feather);
float widthPulse = 1.0 + 0.35 * sin(uv.x * 18.0 - time * 14.0);
float localThickness = thickness * widthPulse;
float distortA = noise(float2(uv.x * 8.0 - time * 1.3, time * 6.0));
float distortB = noise(float2(uv.x * 16.0 + time * 0.9, time * 11.0));
float distort = (distortA - 0.5) * 0.06 + (distortB - 0.5) * 0.035;
uv.y += distort * slashMask(uv, localThickness * 2.0, feather);
float aberr = 0.015;
float r = slashMask(uv + float2( aberr, 0.0), thickness, feather);
float g = slashMask(uv, thickness, feather);
float b = slashMask(uv + float2(-aberr, 0.0), thickness, feather);
float r = slashMask(uv + float2( aberr, 0.0), localThickness, feather);
float g = slashMask(uv, localThickness, feather);
float b = slashMask(uv + float2(-aberr, 0.0), localThickness, feather);
float3 col = float3(r, g, b);
float core = slashMask(uv, thickness * 0.4, feather * 0.2);
col += core * float3(1.2, 1.3, 1.5);
float core = slashMask(uv, localThickness * 0.38, feather * 0.22);
col += core * float3(1.4, 1.4, 1.5);
float glow = slashMask(uv, thickness * 3.5, feather * 2.0);
col += glow * float3(0.3, 0.6, 1.0);
float glow = slashMask(uv, localThickness * 3.8, feather * 2.4);
col += glow * uColor * 0.7;
float veinNoise = noise(float2(uv.x * 22.0 - time * 3.0, uv.y * 48.0 + time * 10.0));
float veins = smoothstep(0.7, 0.98, veinNoise) * glow;
col += veins * uColor * 0.9;
float shock = exp(-abs(uv.y * 13.0 + sin(uv.x * 11.0 + time * 9.0) * 1.7));
col += shock * glow * uColor * 0.25;
return col;
}
@@ -86,13 +101,25 @@ float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
float time = uTime;
float3 col = chromaSlash(uv, time);
// temp
float fillMask = smoothstep(1.0, 0.6, abs(uv.y));
float fillNoise = noise(float2(uv.x * 6.0 + time * 0.8, uv.y * 3.0));
fillMask *= lerp(0.7, 1.1, fillNoise);
fillMask = pow(saturate(fillMask), 1.8);
float fillEdgeFade = smoothstep(1.0, 0.25, abs(uv.y);
col += fillMask * fillEdgeFade * float3(0.12, 0.25, 0.55);
float2 bloomUV = float2(uv.x * 0.85, uv.y * 2.4);
float centerBloom = exp(-dot(bloomUV, bloomUV) * 3.8);
float bloomNoise = noise(float2(uv.x * 10.0 + time * 0.6, uv.y * 5.0));
centerBloom *= lerp(0.92, 1.08, bloomNoise);
centerBloom = saturate(centerBloom);
col += centerBloom * float3(0.18, 0.2, 0.25);
float sweepPos = frac(time * 1.25) * 2.0 - 1.0;
float sweep = exp(-abs(uv.x - sweepPos) * 18.0) * slashMask(uv, 0.12, 0.18);
col += sweep * lerp(float3(1.0, 1.0, 1.0), uColor, 0.2) * 0.55;
float sparkNoise = noise(float2(uv.x * 30.0 + time * 7.0, uv.y * 7.0 - time * 2.0));
float sparkMask = smoothstep(0.92, 0.995, sparkNoise) * slashMask(uv, 0.20, 0.24);
col += sparkMask * lerp(float3(1.0, 1.0, 1.0), uColor, 0.25) * 0.45;
float chromaPulse = 0.5 + 0.5 * sin(time * 6.0 + uv.x * 8.0);
float3 pulseTint = lerp(float3(0.9, 0.9, 0.9), float3(1.1, 1.1, 1.1), chromaPulse);
col *= pulseTint;
float flicker = 0.85 + 0.15 * sin(time * 40.0);
col *= flicker;
@@ -100,9 +127,13 @@ float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
float edgeFade = smoothstep(1.0, 0.3, abs(uv.x));
col *= edgeFade;
col *= input.Color.rgb;
float3 rawCol = col;
float alpha = max(col.r, max(col.g, col.b)) * input.Color.a;
col *= input.Color.rgb;
col *= uBrightness;
float structureAlpha = max(rawCol.r, max(rawCol.g, rawCol.b));
float alpha = structureAlpha * input.Color.a;
return float4(col, alpha);
}
Binary file not shown.
@@ -260,6 +260,9 @@ namespace CalamityMod.Projectiles.Melee
Effect shader = CalamityShaders.NanoblackSlashShader.Value;
shader.Parameters["uTime"]?.SetValue((float)Main.gameTimeCache.TotalGameTime.TotalSeconds);
Color tc = Terratomere.TerraColor1;
shader.Parameters["uColor"]?.SetValue(new Vector3(tc.R / 255f, tc.G / 255f, tc.B / 255f));
shader.Parameters["uBrightness"]?.SetValue(1f);
Matrix view = Main.GameViewMatrix.ZoomMatrix;
Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -1f, 1f);
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using CalamityMod.Effects;
using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Utilities.Daybreak;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -69,6 +70,9 @@ namespace CalamityMod.Projectiles.Melee
Effect shader = CalamityShaders.NanoblackSlashShader.Value;
shader.Parameters["uTime"]?.SetValue((float)Main.gameTimeCache.TotalGameTime.TotalSeconds);
Color tc = Terratomere.TerraColor1;
shader.Parameters["uColor"]?.SetValue(new Vector3(tc.R / 255f, tc.G / 255f, tc.B / 255f));
shader.Parameters["uBrightness"]?.SetValue(1f);
Matrix view = Main.GameViewMatrix.ZoomMatrix;
Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -1f, 1f);
+3
View File
@@ -91,6 +91,9 @@ namespace CalamityMod.Projectiles.Melee
Effect shader = CalamityShaders.NanoblackSlashShader.Value;
shader.Parameters["uTime"]?.SetValue((float)Main.gameTimeCache.TotalGameTime.TotalSeconds);
Color tc = Terratomere.TerraColor1;
shader.Parameters["uColor"]?.SetValue(new Vector3(tc.R / 255f, tc.G / 255f, tc.B / 255f));
shader.Parameters["uBrightness"]?.SetValue(1f);
Matrix view = Main.GameViewMatrix.ZoomMatrix;
Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -1f, 1f);
+1 -10
View File
@@ -46,16 +46,7 @@ namespace CalamityMod.Projectiles.Rogue
private void FrameOneEffects()
{
int dustID = IsPerfect ? 99 : 173;
int numDust = 96;
Vector2 p = Projectile.Center;
for (int i = 0; i < numDust; ++i)
{
p = Projectile.Center + (Vector2.UnitX * HitboxRadius).RotatedBy(i * MathHelper.TwoPi / numDust);
Dust.NewDust(p, 1, 1, dustID, 0f, 0f, 0, default, 2f);
}
// todo: multiplayer test
if (Main.netMode != NetmodeID.Server)
{
int slashVisualID = ModContent.ProjectileType<NanoblackLightspeedCarveSlashVisual>();
@@ -2,7 +2,9 @@
using System.Collections.Generic;
using CalamityMod.Effects;
using CalamityMod.Graphics.Primitives;
using CalamityMod.Items.Weapons.Rogue;
using CalamityMod.Utilities.Daybreak;
using CalamityMod.Utilities.Daybreak.Buffers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
@@ -16,17 +18,71 @@ namespace CalamityMod.Projectiles.Rogue
public new string LocalizationCategory => "Projectiles.Rogue";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
private const int VisualLifetime = 90;
private const int GrowTime = 16;
private const int FadeInTime = 10;
#region params
private const int VisualLifetime = 80;
private const int GrowTime = 8;
private const int FadeInTime = 1;
private const int FadeOutTime = 14;
private const int SlashDelay = 6;
private const int SlashDelay = 2;
private const int HoldTime = 8;
private const float FlashIntensity = 1.8f;
private const float FlashDuration = 0.15f;
private const float RangeMultiplier = 2.2f;
private const float MinWidthStandard = 14f;
private const float MaxWidthStandard = 46f;
private const float MinWidthPerfect = 28f;
private const float MaxWidthPerfect = 62f;
private const float RevealSoftEdge = 0.25f;
private const float RevealOvershoot = 0.22f;
private const float RetreatSoftEdge = 0.18f;
private const float RetreatOvershoot = 0.18f;
private const int SlashResolution = 12;
private const float LightningAmplitude = 2.5f;
private const float LightningAmplitudePerfect = 3.5f;
private const int LightningSubdivisions = 3;
private const float LightningDecay = 0.45f;
private const float LightningDriftSpeed = 4f;
private const float MaxDepth = 40f;
private const float DepthWobbleAmount = 8f;
private const float DepthWobbleSpeed = 6f;
private const float BreathingAmount = 0.06f;
private const float BreathingSpeed = 9f;
private const float CurveStrength = 0.12f;
private const float CurveStrengthPerfect = 0.18f;
private const int EchoCount = 1;
private const float EchoOpacityFalloff = 0.4f;
private const float EchoWidthFalloff = 0.75f;
private const float EchoTimeLag = 4.5f;
private const float GiantSlashLengthMult = 3.4f;
private const float GiantSlashWidth = 120f;
private const int GiantSlashGrowTime = 3;
private const int GiantSlashHoldTime = 5;
private const int GiantSlashFadeTime = 12;
private const int GiantSlashDelay = 4;
private const int GiantSlashStagger = 4;
private const float GiantSlashScreenShake = 0f;
private const float GiantSlashImpactFlash = 2.2f;
private const float GiantSlashImpactFlashDuration = 3f;
#endregion
private static readonly BlendState GiantSlashDarkenBlend = new BlendState
{
ColorSourceBlend = Blend.Zero,
ColorDestinationBlend = Blend.InverseSourceAlpha,
AlphaSourceBlend = Blend.Zero,
AlphaDestinationBlend = Blend.InverseSourceAlpha,
};
private int GiantSlashCount
{
get
{
float seed = Projectile.identity * 1.913f;
return Hash(seed * 3.91f) > 0.5f ? 2 : 1;
}
}
internal bool IsPerfect => Projectile.ai[0] == 1f;
public override void SetDefaults()
@@ -44,78 +100,454 @@ namespace CalamityMod.Projectiles.Rogue
public override bool ShouldUpdatePosition() => false;
public override void AI()
{
if (IsPerfect)
{
float age = VisualLifetime - Projectile.timeLeft;
int count = GiantSlashCount;
for (int g = 0; g < count; g++)
{
float giantAge = GetGiantAge(age, g);
if (giantAge >= 0f && giantAge < 1f)
{
Player owner = Main.player[Projectile.owner];
owner.SetScreenshake(GiantSlashScreenShake);
}
}
}
}
private static float Hash(float x)
{
// ty shadertoy :p
float s = MathF.Sin(x * 127.1f) * 43758.5453f;
return s - MathF.Floor(s);
}
private List<Vector3> BuildSlashPath(
Vector2 center,
Vector2 direction,
float halfLength,
float curveAmount,
float slashSeed,
float growProgress,
float time)
{
var path = new List<Vector3>(SlashResolution);
Vector2 perp = direction.RotatedBy(MathHelper.PiOver2);
bool valid = true;
for (int p = 0; p < SlashResolution; p++)
{
float t = (float)p / (SlashResolution - 1);
float s = t * 2f - 1f;
Vector2 basePos = center + direction * s * halfLength;
float curveBulge = (1f - s * s) * curveAmount * halfLength;
basePos += perp * curveBulge;
float lightning = 0f;
float amplitude = IsPerfect ? LightningAmplitudePerfect : LightningAmplitude;
float freq = 1f;
for (int oct = 0; oct < LightningSubdivisions; oct++)
{
float noiseInput = slashSeed * 13.7f + s * freq * 1.8f + oct * 5.3f + time * LightningDriftSpeed * (1f + oct * 0.3f);
lightning += (Hash(noiseInput) * 2f - 1f) * amplitude;
amplitude *= LightningDecay;
freq *= 1.8f;
}
float envelopeWindow = 1f - s * s;
lightning *= envelopeWindow * growProgress;
basePos += perp * lightning;
float depthWobble = MathF.Sin(time * DepthWobbleSpeed + slashSeed * 4.1f + s * 2f) * DepthWobbleAmount;
float z = (MathF.Sin(s * MathHelper.Pi + slashSeed * 2.9f) * MaxDepth + depthWobble) * (0.5f + 0.5f * growProgress);
Vector2 screenPos = basePos - Main.screenPosition;
if (float.IsNaN(screenPos.X) || float.IsNaN(screenPos.Y) || float.IsNaN(z) ||
float.IsInfinity(screenPos.X) || float.IsInfinity(screenPos.Y) || float.IsInfinity(z))
{
valid = false;
break;
}
path.Add(new Vector3(screenPos, z));
}
if (!valid || path.Count < 2)
{
path.Clear();
Vector2 start = center - direction * halfLength - Main.screenPosition;
Vector2 end = center + direction * halfLength - Main.screenPosition;
path.Add(new Vector3(start, 0f));
path.Add(new Vector3(end, 0f));
}
return path;
}
private static float SlashWidthFunc(float progress, float baseWidth, float cracklePhase, float revealProgress, float retreatProgress)
{
float taperInLinear = MathHelper.Clamp(progress / 0.08f, 0f, 1f);
float taperOutLinear = MathHelper.Clamp((1f - progress) / 0.08f, 0f, 1f);
float taperIn = 1f - MathF.Pow(1f - taperInLinear, 3f);
float taperOut = 1f - MathF.Pow(1f - taperOutLinear, 3f);
float taper = taperIn * taperOut;
float revealLinear = MathHelper.Clamp((revealProgress - progress) / RevealSoftEdge, 0f, 1f);
float reveal = 1f - MathF.Pow(1f - revealLinear, 4f);
float retreatRaw = MathHelper.Clamp((progress - retreatProgress + RetreatSoftEdge) / RetreatSoftEdge, 0f, 1f);
float retreat = 1f - MathF.Pow(1f - retreatRaw, 4f);
float crackle = 1f
+ 0.06f * MathF.Sin(progress * 13f + cracklePhase)
+ 0.04f * MathF.Sin(progress * 29f - cracklePhase * 1.7f);
return baseWidth * taper * crackle * reveal * retreat;
}
private static float GiantSlashWidthFunc(float progress, float baseWidth, float revealProgress, float retreatProgress)
{
float taperIn = 1f - MathF.Pow(1f - MathHelper.Clamp(progress / 0.06f, 0f, 1f), 4f);
float taperOut = 1f - MathF.Pow(1f - MathHelper.Clamp((1f - progress) / 0.06f, 0f, 1f), 4f);
float taper = taperIn * taperOut;
float centered = (progress - 0.5f) * 2f;
float starProfile = MathF.Pow(1f - centered * centered, 0.35f);
float starShape = MathHelper.Lerp(0.3f, 1f, starProfile);
float revealLinear = MathHelper.Clamp((revealProgress - progress) / 0.2f, 0f, 1f);
float reveal = 1f - MathF.Pow(1f - revealLinear, 5f);
float retreatRaw = MathHelper.Clamp((progress - retreatProgress + 0.2f) / 0.2f, 0f, 1f);
float retreat = 1f - MathF.Pow(1f - retreatRaw, 5f);
return baseWidth * taper * starShape * reveal * retreat;
}
public override bool PreDraw(ref Color lightColor)
{
int slashCount = IsPerfect ? 12 : 8;
if (slashCount <= 0)
return false;
float age = VisualLifetime - Projectile.timeLeft;
float fadeOut = Utils.GetLerpValue(0f, FadeOutTime, Projectile.timeLeft, true);
if (fadeOut <= 0f)
return false;
Effect shader = CalamityShaders.NanoblackSlashShader.Value;
shader.Parameters["uTime"]?.SetValue((float)Main.gameTimeCache.TotalGameTime.TotalSeconds);
float time = (float)Main.gameTimeCache.TotalGameTime.TotalSeconds;
shader.Parameters["uTime"]?.SetValue(time);
Color c = NanoblackReaper.NanoblackSlashColor1;
shader.Parameters["uColor"]?.SetValue(new Vector3(c.R / 255f, c.G / 255f, c.B / 255f));
shader.Parameters["uBrightness"]?.SetValue(1f);
Matrix view = Main.GameViewMatrix.ZoomMatrix;
Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -1f, 1f);
Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -200f, 200f);
float baseLength = NanoblackLightspeedCarve.HitboxRadius * 0.9f * RangeMultiplier;
float rotationOffset = Main.GlobalTimeWrappedHourly * 0.6f;
float seed = Projectile.identity * 1.913f;
float curveBase = IsPerfect ? CurveStrengthPerfect : CurveStrength;
var device = Main.instance.GraphicsDevice;
using var lease = RenderTargetPool.Shared.Rent(
device,
Main.screenWidth,
Main.screenHeight,
RenderTargetDescriptor.Default
);
Main.spriteBatch.End(out var ss);
for (int i = 0; i < slashCount; i++)
using (lease.Scope(clearColor: Color.Transparent))
{
float startDelay = i * SlashDelay;
float growProgress = Utils.GetLerpValue(startDelay, startDelay + GrowTime, age, true);
float fadeIn = Utils.GetLerpValue(startDelay, startDelay + FadeInTime, age, true);
if (growProgress <= 0f)
continue;
using var scope = SanePrimitiveRenderer.BeginShaderScope(shader, Matrix.Identity, view, projection,
depthState: DepthStencilState.None, blendState: BlendState.Additive);
float angle = rotationOffset + MathHelper.TwoPi * i / slashCount + seed * 0.1f;
float lengthScale = (0.75f + 0.2f * MathF.Sin(seed + i * 1.7f)) * growProgress;
float offsetScale = 0.25f * MathF.Cos(seed * 1.3f + i * 2.1f);
float widthInterpolant = 0.5f + 0.5f * MathF.Sin(seed * 0.7f + i * 2.3f);
float minWidth = IsPerfect ? MinWidthPerfect : MinWidthStandard;
float maxWidth = IsPerfect ? MaxWidthPerfect : MaxWidthStandard;
float slashWidth = MathHelper.Lerp(minWidth, maxWidth, widthInterpolant) * growProgress;
DrawAllSlashes(scope, slashCount, age, time, seed, baseLength, curveBase);
Vector2 direction = angle.ToRotationVector2();
Vector2 perpendicular = direction.RotatedBy(MathHelper.PiOver2);
Vector2 offset = perpendicular * baseLength * offsetScale;
Vector2 start = Projectile.Center + direction * baseLength * lengthScale + offset;
Vector2 end = Projectile.Center - direction * baseLength * lengthScale + offset;
var path = new List<Vector3>(2)
if (IsPerfect)
{
new Vector3(start - Main.screenPosition, 0f),
new Vector3(end - Main.screenPosition, 0f)
};
int giantCount = GiantSlashCount;
for (int g = 0; g < giantCount; g++)
DrawGiantSlash(scope, age, time, seed, baseLength, g);
}
}
float opacity = fadeOut * fadeIn;
PrimitiveMesh mesh = TriangleStripBuilder.BuildStrip(
path,
_ => slashWidth,
Color.White * opacity,
textured: true,
smoothingSegments: 2);
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp,
DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);
Main.spriteBatch.Draw(lease.Target, Vector2.Zero, Color.White);
Main.spriteBatch.End();
SanePrimitiveRenderer.DrawMesh(
Matrix.Identity,
view,
projection,
mesh,
shader,
blendState: BlendState.Additive);
Effect bloomShader = CalamityShaders.GaussianBloomShader.Value;
bloomShader.Parameters["uSource"]?.SetValue(new Vector4(Main.screenWidth, Main.screenHeight, 0f, 0f));
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp,
DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);
bloomShader.CurrentTechnique.Passes["BloomShader"].Apply();
Main.spriteBatch.Draw(lease.Target, Vector2.Zero, Color.White);
Main.spriteBatch.End();
if (IsPerfect)
{
int giantCount = GiantSlashCount;
for (int g = 0; g < giantCount; g++)
DrawGiantSlashBlackCore(age, time, seed, baseLength, g);
}
Main.spriteBatch.Begin(ss);
return false;
}
private void DrawAllSlashes(
SanePrimitiveRenderer.ShaderScope scope,
int slashCount, float age, float time,
float seed, float baseLength, float curveBase)
{
for (int i = 0; i < slashCount; i++)
{
float startDelay = i * SlashDelay;
float growLinear = Utils.GetLerpValue(startDelay, startDelay + GrowTime, age, true);
if (growLinear <= 0f)
continue;
float growProgress = 1f - MathF.Pow(1f - growLinear, 2.5f);
float fadeIn = Utils.GetLerpValue(startDelay, startDelay + FadeInTime, age, true);
float angle = MathHelper.TwoPi * i / slashCount + seed * 0.1f;
float lengthScale = 0.75f + 0.2f * MathF.Sin(seed + i * 1.7f);
float offsetScale = 0.25f * MathF.Cos(seed * 1.3f + i * 2.1f);
float widthInterpolant = 0.5f + 0.5f * MathF.Sin(seed * 0.7f + i * 2.3f);
float minWidth = IsPerfect ? MinWidthPerfect : MinWidthStandard;
float maxWidth = IsPerfect ? MaxWidthPerfect : MaxWidthStandard;
float slashWidth = MathHelper.Lerp(minWidth, maxWidth, widthInterpolant);
Vector2 direction = angle.ToRotationVector2();
Vector2 perpendicular = direction.RotatedBy(MathHelper.PiOver2);
Vector2 offset = perpendicular * baseLength * offsetScale;
Vector2 center = Projectile.Center + offset;
float halfLength = baseLength * lengthScale;
float slashSeed = seed + i * 3.17f;
float curveDirection = (i % 2 == 0) ? 1f : -1f;
float curveSigned = curveBase * curveDirection * (0.7f + 0.6f * Hash(slashSeed * 0.43f));
float retreatStartAge = startDelay + GrowTime + HoldTime;
float retreatAge = Utils.GetLerpValue(retreatStartAge, retreatStartAge + FadeOutTime, age, true);
float slashFadeOut = 1f - retreatAge;
if (slashFadeOut <= 0f)
continue;
float smoothFadeOut = MathF.Pow(slashFadeOut, 0.5f);
float flashProgress = 1f - slashFadeOut;
float flash = 1f;
if (flashProgress > 0f && flashProgress < FlashDuration)
{
float flashT = flashProgress / FlashDuration;
flash = 1f + (FlashIntensity - 1f) * (1f - MathF.Pow(1f - MathF.Sin(flashT * MathHelper.Pi), 2f));
}
float widthCollapse = 0.7f + 0.3f * MathF.Pow(smoothFadeOut, 3f);
float retreatT = 1f - smoothFadeOut;
float retreatProgress = MathF.Pow(retreatT, 0.4f) * (1f + RetreatOvershoot);
float colorShift = MathF.Pow(1f - smoothFadeOut, 2f);
Color aliveColor = NanoblackReaper.NanoblackSlashColor1;
Color dyingColor = NanoblackReaper.ZeroPointLineColor;
Color baseColor = Color.Lerp(aliveColor, dyingColor, colorShift);
float opacityFade = MathF.Pow(MathHelper.Clamp(smoothFadeOut / 0.2f, 0f, 1f), 0.3f);
float shimmer = 1f + 0.08f * MathF.Sin(time * 14f + slashSeed * 7.7f)
+ 0.05f * MathF.Sin(time * 23f - slashSeed * 4.1f);
float opacity = opacityFade * fadeIn * flash * shimmer;
float cracklePhase = slashSeed * 11f + time * 12f;
float breathing = 1f + BreathingAmount * MathF.Sin(time * BreathingSpeed + slashSeed * 3.3f);
float fadedWidth = slashWidth * widthCollapse * breathing;
for (int echo = EchoCount; echo >= 0; echo--)
{
float echoAge = age - echo * EchoTimeLag;
float echoGrowLinear = Utils.GetLerpValue(startDelay, startDelay + GrowTime, echoAge, true);
if (echoGrowLinear <= 0f)
continue;
float echoGrow = 1f - MathF.Pow(1f - echoGrowLinear, 2.5f);
float echoFadeIn = Utils.GetLerpValue(startDelay, startDelay + FadeInTime, echoAge, true);
float echoOpacity = opacity * echoFadeIn * MathF.Pow(EchoOpacityFalloff, echo);
float echoWidth = fadedWidth * MathF.Pow(EchoWidthFalloff, echo);
float echoTime = time - echo * 0.06f;
float echoLength = halfLength * (echo == 0 ? 1f : 0.97f - echo * 0.02f);
List<Vector3> path = BuildSlashPath(
center, direction, echoLength,
curveSigned, slashSeed, echoGrow, echoTime);
Color echoTint = NanoblackReaper.NanoblackSlashColor2;
Color echoColor = echo == 0
? baseColor * echoOpacity
: Color.Lerp(echoTint, dyingColor, colorShift) * echoOpacity;
float capturedEchoWidth = echoWidth;
float capturedCrackle = cracklePhase - echo * 5f;
float capturedReveal = echoGrow * (1f + RevealOvershoot);
float capturedRetreat = retreatProgress;
using var mesh = TriangleStripBuilder.BuildStripPooled(
path,
progress => SlashWidthFunc(progress, capturedEchoWidth, capturedCrackle, capturedReveal, capturedRetreat),
echoColor,
PrimitiveMeshCache.Shared,
textured: true,
smoothingSegments: 2);
scope.Draw(mesh.View);
}
}
}
private void DrawGiantSlash(
SanePrimitiveRenderer.ShaderScope scope,
float age, float time, float seed, float baseLength, int giantIndex)
{
float giantAge = GetGiantAge(age, giantIndex);
if (!TryGetGiantTimeline(giantAge, out float growProgress, out float fadeLinear, out float smoothFade))
return;
float impactFlash = CalculateImpactFlash(giantAge);
List<Vector3> path = BuildGiantSlashPath(time, seed, baseLength, giantIndex, growProgress);
float widthCollapse = 0.6f + 0.4f * MathF.Pow(smoothFade, 3f);
float impactWidthBoost = 1f + 0.15f * MathF.Max(impactFlash - 1f, 0f);
float currentWidth = GiantSlashWidth * widthCollapse * impactWidthBoost;
float opacity = MathF.Pow(MathHelper.Clamp(smoothFade / 0.15f, 0f, 1f), 0.3f) * MathF.Min(impactFlash, 2.5f);
Color edgeColor = NanoblackReaper.NanoblackSlashColor1 * opacity;
float retreatProgress = CalculateGiantRetreatProgress(fadeLinear);
float capturedWidth = currentWidth;
float capturedReveal = growProgress * 1.22f;
float capturedRetreat = retreatProgress;
using var mesh = TriangleStripBuilder.BuildStripPooled(
path,
progress => GiantSlashWidthFunc(progress, capturedWidth, capturedReveal, capturedRetreat),
edgeColor,
PrimitiveMeshCache.Shared,
textured: true,
smoothingSegments: 2);
scope.Draw(mesh.View);
}
private void DrawGiantSlashBlackCore(
float age, float time, float seed, float baseLength, int giantIndex)
{
float giantAge = GetGiantAge(age, giantIndex);
if (!TryGetGiantTimeline(giantAge, out float growProgress, out float fadeLinear, out float smoothFade))
return;
List<Vector3> path = BuildGiantSlashPath(time, seed, baseLength, giantIndex, growProgress);
float widthCollapse = 0.6f + 0.4f * MathF.Pow(smoothFade, 3f);
float coreWidth = GiantSlashWidth * 0.65f * widthCollapse;
float opacity = MathF.Pow(MathHelper.Clamp(smoothFade / 0.15f, 0f, 1f), 0.3f);
Color coreColor = Color.White * opacity;
float retreatProgress = CalculateGiantRetreatProgress(fadeLinear);
float capturedWidth = coreWidth;
float capturedReveal = growProgress * 1.22f;
float capturedRetreat = retreatProgress;
Effect shader = CalamityShaders.NanoblackSlashShader.Value;
shader.Parameters["uColor"]?.SetValue(new Vector3(1f, 1f, 1f));
shader.Parameters["uBrightness"]?.SetValue(1.5f);
Matrix view = Main.GameViewMatrix.ZoomMatrix;
Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -200f, 200f);
using var scope = SanePrimitiveRenderer.BeginShaderScope(shader, Matrix.Identity, view, projection,
depthState: DepthStencilState.None, blendState: GiantSlashDarkenBlend);
using var mesh = TriangleStripBuilder.BuildStripPooled(
path,
progress => GiantSlashWidthFunc(progress, capturedWidth, capturedReveal, capturedRetreat),
coreColor,
PrimitiveMeshCache.Shared,
textured: true,
smoothingSegments: 2);
scope.Draw(mesh.View);
Color c = NanoblackReaper.NanoblackSlashColor1;
shader.Parameters["uColor"]?.SetValue(new Vector3(c.R / 255f, c.G / 255f, c.B / 255f));
shader.Parameters["uBrightness"]?.SetValue(1f);
}
private static float CalculateGiantRetreatProgress(float fadeLinear)
=> fadeLinear > 0f ? MathF.Pow(fadeLinear, 0.4f) * 1.2f : 0f;
private float GetGiantAge(float age, int giantIndex)
=> age - GiantSlashDelay - giantIndex * GiantSlashStagger;
private static bool TryGetGiantTimeline(float giantAge, out float growProgress, out float fadeLinear, out float smoothFade)
{
growProgress = 0f;
fadeLinear = 0f;
smoothFade = 0f;
if (giantAge < 0f)
return false;
float growLinear = MathHelper.Clamp(giantAge / GiantSlashGrowTime, 0f, 1f);
growProgress = 1f - MathF.Pow(1f - growLinear, 4f);
float fadeStartAge = GiantSlashGrowTime + GiantSlashHoldTime;
fadeLinear = MathHelper.Clamp((giantAge - fadeStartAge) / GiantSlashFadeTime, 0f, 1f);
float fadeOut = 1f - fadeLinear;
if (fadeOut <= 0f)
return false;
smoothFade = MathF.Pow(fadeOut, 0.5f);
return true;
}
private static float CalculateImpactFlash(float giantAge)
{
if (giantAge >= GiantSlashImpactFlashDuration)
return 1f;
float flashT = 1f - (giantAge / GiantSlashImpactFlashDuration);
return 1f + (GiantSlashImpactFlash - 1f) * flashT * flashT;
}
private List<Vector3> BuildGiantSlashPath(float time, float seed, float baseLength, int giantIndex, float growProgress)
{
float angle = Hash(seed * 2.71f + giantIndex * 7.13f) * MathHelper.TwoPi;
Vector2 direction = angle.ToRotationVector2();
float halfLength = baseLength * GiantSlashLengthMult;
float slashSeed = seed * 5.13f + giantIndex * 11.7f;
return BuildSlashPath(
Projectile.Center,
direction,
halfLength,
0f,
slashSeed,
growProgress,
time);
}
}
}
+59 -4
View File
@@ -4,6 +4,7 @@ using CalamityMod.Items.Weapons.Rogue;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
@@ -25,6 +26,41 @@ namespace CalamityMod.Projectiles.Rogue
internal const float RotationIncrement = 0.22f;
private static readonly SoundStyle LightspeedMissSound = new("CalamityMod/Sounds/Item/NanoblackReaper/NanoblackReaper_LightspeedMiss")
{
Volume = 0.8f,
PitchVariance = 0.1f,
MaxInstances = 8,
};
private static readonly SoundStyle LightspeedPerfectMissSound = new("CalamityMod/Sounds/Item/NanoblackReaper/NanoblackReaper_LightspeedMissPerfect")
{
Volume = 0.9f,
PitchVariance = 0.08f,
MaxInstances = 8,
};
private static readonly SoundStyle LightspeedSlashBaseSound = new("CalamityMod/Sounds/Item/NanoblackReaper/NanoblackReaper_LightspeedSlash")
{
Volume = 0.85f,
PitchVariance = 0.08f,
MaxInstances = 10,
};
private static readonly SoundStyle LightspeedSlashVariantSound = new("CalamityMod/Sounds/Item/NanoblackReaper/NanoblackReaper_LightspeedSlash", 3)
{
Volume = 0.65f,
PitchVariance = 0.12f,
MaxInstances = 10,
};
private static readonly SoundStyle LightspeedPerfectSlashSound = new("CalamityMod/Sounds/Item/NanoblackReaper/NanoblackReaper_PerfectLightspeedSlash")
{
Volume = 0.95f,
PitchVariance = 0.06f,
MaxInstances = 8,
};
private Player Owner => Main.player[Projectile.owner];
internal ref float RealFrameCounter => ref Projectile.ai[0];
internal ref float TesselationSpawnCooldown => ref Projectile.ai[1];
@@ -124,7 +160,7 @@ namespace CalamityMod.Projectiles.Rogue
if (imperfectWindowPassed)
LightspeedCarveState = LightspeedCarveState_Performed;
}
BoomerangMovement();
}
@@ -210,7 +246,7 @@ namespace CalamityMod.Projectiles.Rogue
private void SpawnTesselation()
{
int numTessSpawns = 3;
// Each tesselation spawns with a random delay before it chooses to fire.
// For consistent RNG iteration, these RNG values are obtained even if they are not needed.
static float GetStrikeDelay() => Main.rand.NextFloat(NanoblackTesselation.MinDelay, NanoblackTesselation.MaxDelay);
@@ -272,12 +308,21 @@ namespace CalamityMod.Projectiles.Rogue
if (target is null || !target.active)
target = Projectile.Center.ClosestNPCAt(NanoblackLightspeedCarve.TargetingRange, bossPriority: true);
if (target is not null && target.active)
bool foundTarget = target is not null && target.active;
if (foundTarget)
pos = target.Center;
else
{
SoundStyle missSound = lcs == LightspeedCarveState_CanPerfect ? LightspeedPerfectMissSound : LightspeedMissSound;
SoundEngine.PlaySound(missSound, Projectile.Center);
}
float fuzz = NanoblackLightspeedCarve.PlacementRandomness;
pos += Main.rand.NextVector2Circular(fuzz, fuzz);
if (foundTarget)
PlayLightspeedCarveSounds(lcs == LightspeedCarveState_CanPerfect, pos);
if (lcs == LightspeedCarveState_CanPerfect)
{
Projectile perf = Projectile.NewProjectileDirect(source, pos, Vector2.Zero, projType, damage, kb, Projectile.owner, ai0: 1f);
@@ -296,6 +341,16 @@ namespace CalamityMod.Projectiles.Rogue
Projectile.netUpdate = true;
}
private static void PlayLightspeedCarveSounds(bool perfect, Vector2 position)
{
if (perfect)
SoundEngine.PlaySound(LightspeedPerfectSlashSound, position);
else
{
SoundEngine.PlaySound(LightspeedSlashVariantSound, position);
}
}
private void RotateScytheInFlight()
{
float spin = Projectile.direction <= 0 ? -1f : 1f;
@@ -308,7 +363,7 @@ namespace CalamityMod.Projectiles.Rogue
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
// No gameplay effects; just spawns slash impact particles at a slightly random angle.
Color color = NanoblackReaper.NanoblackSlashColor1;
Color color = NanoblackReaper.NanoblackSlashColor1;
float scale = 0.12f;
Vector2 slashDir = -Projectile.velocity.SafeNormalize(-Vector2.UnitY);
Vector2 vel = 0.01f * slashDir.RotatedByRandom(MathHelper.Pi / 8f);