Improved visuals for Voidragon's deathray

- Self explanatory, new shader and some visual updates for the AbyssalFire projectile
This commit is contained in:
fryzahh committed 2025-05-10 23:26:05 -04:00
1 parent 97ee0e9a85
commit aab48464b3
4 files changed
+166 -13

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
sampler noiseTexture1 : register(s1);
sampler noiseTexture2 : register(s2);
float time;
float4 secondaryColor;
matrix uWorldViewProjection;
struct VertexShaderInput
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float3 TextureCoordinates : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float3 TextureCoordinates : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput) 0;
float4 pos = mul(input.Position, uWorldViewProjection);
output.Position = pos;
output.Color = input.Color;
output.TextureCoordinates = input.TextureCoordinates;
return output;
}
float InverseLerp(float from, float to, float x)
{
return saturate((x - from) / (to - from));
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float4 color = input.Color;
float2 coords = input.TextureCoordinates;
// Account for texture distortion artifacts.
coords.y = (coords.y - 0.5) / input.TextureCoordinates.z + 0.5;
// Read the fade map as a streak.
float bloomFadeout = pow(sin(coords.y * 3.141), 4);
float4 noiseColor = tex2D(noiseTexture1, float2(frac(coords.x * 5 - time * 3.5), coords.y - time * 1.5));
float opacity = (0.5 + noiseColor.g) * bloomFadeout;
// Calculate secondary noise colors.
float noiseFade2 = tex2D(noiseTexture2, float2(frac(coords.x * 2.5 - time * 2.75), coords.y)).r;
float4 noiseColor2 = InverseLerp(0.4, 0.5, noiseFade2 * bloomFadeout) * secondaryColor;
// Fade out at the ends of the streak.
if (coords.x < 0.018)
opacity *= pow(coords.x / 0.018, 6);
if (coords.x > 0.95)
opacity *= pow(1 - (coords.x - 0.95) / 0.05, 6);
return color * 1.4 * opacity + noiseColor2 * opacity;
}
technique Technique1
{
pass LaserPass
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Binary file not shown.
+12
View File
@@ -210,6 +210,13 @@ namespace CalamityMod.Effects
internal static Effect FlipScreenShader;
#endregion
//
// All below shaders created by fryzahh
//
#region fryzahh's Shaders
internal static Effect AbyssalFireShader;
#endregion
public override void PostSetupContent()
{
AssetRepository calAss = CalamityMod.Instance.Assets;
@@ -417,6 +424,11 @@ namespace CalamityMod.Effects
FlipScreenShader = LoadShader("ScreenShaders/FlipScreen");
RegisterScreenShader(FlipScreenShader, "FlipTheScreen", "FlipScreen",EffectPriority.VeryHigh);
#endregion
#region Loading fryzahh's Shaders
AbyssalFireShader = LoadShader("AbyssalFireShader");
RegisterMiscShader(AbyssalFireShader, "LaserPass", "AbyssalFire");
#endregion
}
// Shorthand to register a loaded shader in Terraria's graphics engine
+83 -13
View File
@@ -3,11 +3,17 @@ using System.Collections.Generic;
using System.Linq;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Buffs.StatDebuffs;
using CalamityMod.DataStructures;
using CalamityMod.Dusts;
using CalamityMod.Effects;
using CalamityMod.Graphics.Metaballs;
using CalamityMod.Graphics.Primitives;
using CalamityMod.Packets.Entities;
using CalamityMod.Particles;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
@@ -19,16 +25,19 @@ namespace CalamityMod.Projectiles.Ranged
public class AbyssalFire : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
public Vector2[] ControlPoints = new Vector2[32];
public Player Owner => Main.player[Projectile.owner];
public Projectile VoidragonHoldout => Main.projectile[(int)Projectile.ai[0]];
public ref float LaserLength => ref Projectile.ai[1];
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public const float MaxLaserLength = 3330f;
public override void SetDefaults()
{
Projectile.width = Projectile.height = 32;
Projectile.width = Projectile.height = 75;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Ranged;
Projectile.penetrate = -1;
@@ -48,18 +57,63 @@ namespace CalamityMod.Projectiles.Ranged
return;
}
// Grow bigger up to a point.
Projectile.scale = MathHelper.Clamp(Projectile.scale + 0.15f, 0.05f, 2f);
// Set the control points for the primitive drawing.
for (int i = 0; i < ControlPoints.Length; i++)
ControlPoints[i] = Projectile.Center + Projectile.velocity * i / (ControlPoints.Length - 1f) * LaserLength;
// Grow and shrink depending on how long left the laser has to remain active.
int beamTimer = VoidragonHoldout.ModProjectile<VoidragonHoldout>().beamTimer;
if (beamTimer <= 500 && beamTimer >= 425)
Projectile.scale += 0.1f;
else if (beamTimer <= 75 && beamTimer >= 0 && Projectile.scale > 0f)
Projectile.scale -= 0.1f;
Projectile.scale = MathHelper.Clamp(Projectile.scale, 0f, 2f);
// Decide where to position the laserbeam.
Vector2 circlePointDirection = Projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction);
Projectile.Center = VoidragonHoldout.Center;
Projectile.Center = VoidragonHoldout.ModProjectile<VoidragonHoldout>().GunTipPosition;
LaserLength = MaxLaserLength;
// Update aim.
UpdateAim();
// Spawn a bunch of particles along the length of the laser.
if (Projectile.scale >= 0.25f)
{
BezierCurve curve = new(ControlPoints);
for (int i = 0; i < 10; i++)
{
Vector2 fireSpawnPosition = curve.Evaluate(Main.rand.NextFloat(0.05f, 1f));
Vector2 fireVelocity = Projectile.velocity + Main.rand.NextVector2Circular(1f, 1f) * Main.rand.NextFloat(10f, 15f);
Color fireColor = Color.Lerp(Color.DarkOrchid, Color.DarkMagenta, Main.rand.NextFloat());
int fireLifetime = Main.rand.Next(45, 60);
float fireScale = Main.rand.NextFloat(0.45f, 1f) * Projectile.scale;
float fireOpacity = Main.rand.NextFloat(0.65f, 0.95f);
HeavySmokeParticle abyssalFlames = new(fireSpawnPosition, fireVelocity, fireColor, fireLifetime, fireScale, fireOpacity, 0.03f, true);
GeneralParticleHandler.SpawnParticle(abyssalFlames);
}
for (int i = 0; i < 6; i++)
{
Vector2 sparkSpawnPosition = curve.Evaluate(Main.rand.NextFloat(0.05f, 1f));
Vector2 sparkVelocity = Projectile.velocity.RotatedBy(MathHelper.PiOver2 * Main.rand.NextBool().ToDirectionInt()) * Main.rand.NextFloat(9f, 18f) * Main.rand.NextVector2Circular(1f, 1f);
Dust dust = Dust.NewDustDirect(sparkSpawnPosition, 1, 1, ModContent.DustType<LightDust>());
dust.noGravity = true;
dust.velocity = sparkVelocity;
dust.scale = Main.rand.NextFloat(0.8f, 1.2f) * Projectile.scale;
dust.color = Main.rand.NextBool() ? Color.MediumOrchid : Color.BlueViolet;
dust.noLightEmittence = true;
}
}
// Shake the screen slightly.
if (Owner.Calamity().GeneralScreenShakePower < 1.15f)
Owner.Calamity().GeneralScreenShakePower = MathHelper.Lerp(0f, 1.15f, Projectile.scale / 2f);
// Make the beam cast light along its length. The brightness of the light is reliant on the scale of the beam.
DelegateMethods.v3_1 = Color.DarkViolet.ToVector3() * Projectile.scale * 0.4f;
Utils.PlotTileLine(Projectile.Center, Projectile.Center + Projectile.velocity * LaserLength, Projectile.width * Projectile.scale, DelegateMethods.CastLight);
@@ -83,26 +137,42 @@ namespace CalamityMod.Projectiles.Ranged
Projectile.velocity = newAimDirection;
}
private float PrimitiveWidthFunction(float completionRatio) => Projectile.scale * 25f;
private float PrimitiveWidthFunction(float completionRatio)
{
float width;
float maxBodyWidth = Projectile.scale * 75f;
float shrinkRatio = 0.1f;
if (completionRatio < shrinkRatio)
width = MathF.Sin(completionRatio / shrinkRatio * MathHelper.PiOver2) * maxBodyWidth + shrinkRatio;
else
width = Utils.Remap(completionRatio, shrinkRatio, 1f, maxBodyWidth, 0f);
return width;
}
private Color PrimitiveColorFunction(float completionRatio)
{
Color vibrantColor = Color.Lerp(Color.Indigo, Color.Purple, (float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.67f - completionRatio / LaserLength * 29f) * 0.5f + 0.5f);
Color vibrantColor = Color.Lerp(Color.Indigo, Color.MediumPurple, (float)Math.Cos(Main.GlobalTimeWrappedHourly * 0.67f - completionRatio / LaserLength * 29f) * 0.5f + 0.5f);
float opacity = Projectile.Opacity * Utils.GetLerpValue(0.97f, 0.9f, completionRatio, true) *
Utils.GetLerpValue(0f, MathHelper.Clamp(15f / LaserLength, 0f, 0.5f), completionRatio, true) *
(float)Math.Pow(Utils.GetLerpValue(60f, 270f, LaserLength, true), 3D);
return Color.Lerp(vibrantColor, Color.Violet, 0.5f) * opacity * 2f;
MathF.Pow(Utils.GetLerpValue(60f, 270f, LaserLength, true), 3f);
return Color.Lerp(vibrantColor, Color.Black, 0.5f) * opacity * 2f;
}
public override bool PreDraw(ref Color lightColor)
{
GameShaders.Misc["CalamityMod:Flame"].UseImage1("Images/Misc/Perlin");
Asset<Texture2D> mainStreakTexture = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/Neurons2");
Asset<Texture2D> secondaryStreakTexture = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleGradients/Neurons2");
Vector2[] basePoints = new Vector2[24];
for (int i = 0; i < basePoints.Length; i++)
basePoints[i] = Projectile.Center + Projectile.velocity * i / (basePoints.Length - 1f) * LaserLength;
MiscShaderData shader = GameShaders.Misc["CalamityMod:AbyssalFire"];
shader.Shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly);
shader.Shader.Parameters["secondaryColor"].SetValue(Color.Lerp(Color.MediumPurple, Color.White, 0.65f).ToVector4());
shader.SetShaderTexture(mainStreakTexture);
Main.instance.GraphicsDevice.Textures[2] = secondaryStreakTexture.Value;
PrimitiveRenderer.RenderTrail(basePoints, new(PrimitiveWidthFunction, PrimitiveColorFunction, shader: GameShaders.Misc["CalamityMod:Flame"]), 92);
PrimitiveRenderer.RenderTrail(ControlPoints, new(PrimitiveWidthFunction, PrimitiveColorFunction, shader: shader), ControlPoints.Length + 12);
return false;
}