Vice-well polish on titanium railgun

This commit is contained in:
IbanPlay committed 2022-06-15 00:44:17 +02:00
1 parent f8d1a72549
commit ba68a0928f
10 files changed
+292 -8

No files matched your search

+4
View File
@@ -121,6 +121,10 @@ namespace CalamityMod.Effects
var screenRef = new Ref<Effect>(CalamityMod.Instance.Assets.Request<Effect>("Effects/SpreadTelegraph", AssetRequestMode.ImmediateLoad).Value);
Filters.Scene["SpreadTelegraph"] = new Filter(new ScreenShaderData(screenRef, "TelegraphPass"), EffectPriority.High);
Filters.Scene["SpreadTelegraph"].Load();
screenRef = new Ref<Effect>(CalamityMod.Instance.Assets.Request<Effect>("Effects/PixelatedSightLine", AssetRequestMode.ImmediateLoad).Value);
Filters.Scene["PixelatedSightLine"] = new Filter(new ScreenShaderData(screenRef, "SightLinePass"), EffectPriority.High);
Filters.Scene["PixelatedSightLine"].Load();
}
}
}
+105
View File
@@ -0,0 +1,105 @@
float3 color;
float3 darkerColor;
float bloomSize;
float bloomMaxOpacity;
float bloomFadeStrenght;
float mainOpacity;
float laserAngle;
float laserWidth;
float laserLightStrenght;
float noiseOffset;
float2 Resolution;
texture sampleTexture;
sampler2D Texture1Sampler = sampler_state { texture = <sampleTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; };
texture sampleTexture2;
sampler2D NoiseMap = sampler_state { texture = <sampleTexture2>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; };
//I can't believe it has gotten down to this.
float realCos(float value)
{
return sin(value + 1.57079);
}
//Hlsl's % operator applies a modulo but conserves the sign of the dividend, hence the need for a custom modulo
float mod(float a, float n)
{
return a - floor(a / n) * n;
}
//Gets the distance of a plot from a line with a specified origin and angle
float distanceFromLine
(
float2 origin, float angle, float2 plot)
{
return abs(realCos(angle) * (origin.y - plot.y) - sin(angle) * (origin.x - plot.x));
}
//Gets the distance of a plot from a line with a specified origin and angle, but crops the line so it only expands towards the angle
float distanceFromLineCropped
(
float2 origin, float angle, float2 plot, float plotAngle)
{
//If the angle between the line's angle and the plot's angle is less than 90° (aka , not BEHIND the half-line), return the distance from the line
if (abs(mod(angle - plotAngle + 3.1415926, 6.2831853) - 3.1415926) < 1.5707)
return distanceFromLine(origin, angle, plot);
//If we are behind the line, just give the distance between the start point and the plot
else
return length(origin - plot);
}
float4 main(float2 uv : TEXCOORD) : COLOR
{
//Pixelate
uv.x -= uv.x % (1 / (Resolution.x * 2));
uv.y -= uv.y % (1 / (Resolution.y * 2));
float2 mappedUv = float2(uv.x - 0.5, (1 - uv.y) - 0.5);
float halfLaserWidth = laserWidth / 2;
//get the length of the doubled distance, so that 0 = at the center of the sprite and 1 = at the very edge of the circle
float distanceFromCenter = length(mappedUv) * 2;
//Crop the sprite into a circle
if (distanceFromCenter > 1)
return float4(0, 0, 0, 0);
//Grabs the angle (only as a positive angle, since it's a mirror image udnerneath.
float angle = atan2(mappedUv.y, mappedUv.x);
//Grabs the distance of the point from the edge line.
float distanceFromLine = distanceFromLineCropped(float2(0, 0), laserAngle, mappedUv, angle);
//If we are further from the line than the bloom's blending lenght, just don't.
if (distanceFromLine > bloomSize + halfLaserWidth)
return float4(0, 0, 0, 0);
float4 noise = tex2D(NoiseMap, float2((distanceFromCenter + noiseOffset) % 1, distanceFromLine / (bloomSize + halfLaserWidth)));
float3 laserColor = lerp(color, darkerColor, noise.r);
float laserOpacity = (1 - pow(distanceFromCenter, laserLightStrenght)) * mainOpacity;
if (distanceFromLine <= halfLaserWidth)
return float4(laserColor * laserOpacity, laserOpacity);
//The higher this value is, the more we blend with the edge's opacity & color.
float bloomBlendFactor = pow(1 - (distanceFromLine - halfLaserWidth) / bloomSize, bloomFadeStrenght);
float3 colour = lerp(float3(0, 0, 0), laserColor, bloomBlendFactor);
float opacity = lerp(0, laserOpacity, bloomBlendFactor) * mainOpacity * bloomMaxOpacity;
colour = colour * opacity;
return float4(colour, opacity);
}
technique Technique1
{
pass SightLinePass
{
PixelShader = compile ps_3_0 main();
}
}
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

+96
View File
@@ -0,0 +1,96 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class TitaniumRailgunShell : Particle
{
public override string Texture => "CalamityMod/Particles/TitaniumRailgunShell";
public override bool UseCustomDraw => true;
public override bool SetLifetime => true;
public float Opacity;
public Point TileAttachement;
public Color GlowColor;
public bool isStuckToTile
{
get
{
if (Main.tile[TileAttachement].HasTile && Main.tile[TileAttachement].IsTileSolid())
return true;
else
{
for (int i = -1; i < 2; i++)
{
for (int j = -1; j < 2; j++)
{
if (Main.tile[TileAttachement + new Point(i, j)].HasTile && Main.tile[TileAttachement + new Point(i, j)].IsTileSolid())
return true;
}
}
return false;
}
}
}
public TitaniumRailgunShell(Vector2 position, Point tileCoords, float rotation, Color glowColor, int lifetime = 80)
{
Position = position;
Scale = 1f;
Color = Color.White;
GlowColor = glowColor;
Opacity = 1f;
Velocity = Vector2.Zero;
Rotation = rotation;
Lifetime = lifetime;
TileAttachement = tileCoords;
if (!isStuckToTile)
Opacity = 0;
}
public override void Update()
{
if (LifetimeCompletion > 0.7f)
Opacity = MathHelper.Lerp(1f, 0f, (LifetimeCompletion - 0.7f) / 0.3f);
Color = Lighting.GetColor(TileAttachement);
Velocity *= 0.9f;
if (!isStuckToTile)
Opacity = 0f;
if (Opacity <= 0.01f)
GeneralParticleHandler.RemoveParticle(this);
if (LifetimeCompletion < 0.2f && Main.rand.NextBool(2))
{
Vector2 dustPosition = Position + Main.rand.NextVector2Circular(8f, 8f);
Dust dust = Dust.NewDustPerfect(dustPosition, 6, Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2) * Main.rand.NextFloat(-1f, -5f), 0, Color.White, 1.2f);
dust.noGravity = true;
}
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
Texture2D texture = GeneralParticleHandler.GetTexture(Type);
Texture2D glowTexture = ModContent.Request<Texture2D>("CalamityMod/Particles/TitaniumRailgunShellGlow").Value;
Vector2 minorDisplacementToMakeItLookLikeItActuallyWasMovingButFast = Rotation.ToRotationVector2() * -13f * (float)Math.Pow(MathHelper.Clamp(1 - LifetimeCompletion * 3f, 0f, 1f), 3f);
spriteBatch.Draw(texture, Position + minorDisplacementToMakeItLookLikeItActuallyWasMovingButFast - Main.screenPosition, null, Color * Opacity, Rotation + MathHelper.PiOver2, texture.Size() * 0.5f, Scale, SpriteEffects.None, 0f);
GlowColor.A = 4;
float glowOpacity = 1 - Math.Clamp(LifetimeCompletion * 2f, 0f, 1f);
spriteBatch.Draw(glowTexture, Position + minorDisplacementToMakeItLookLikeItActuallyWasMovingButFast - Main.screenPosition, null, GlowColor * glowOpacity, Rotation + MathHelper.PiOver2, glowTexture.Size() * 0.5f, Scale, SpriteEffects.None, 0f);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

+3 -3
View File
@@ -84,8 +84,9 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(ref Color lightColor)
{
var effect = Filters.Scene["SpreadTelegraph"].GetShader().Shader;
float angle = (Owner.Calamity().mouseWorld - Owner.MountedCenter).ToRotation();
Effect effect = Filters.Scene["SpreadTelegraph"].GetShader().Shader;
effect.Parameters["centerOpacity"].SetValue(0.7f);
effect.Parameters["mainOpacity"].SetValue((float)Math.Sqrt(ChargeProgress));
effect.Parameters["halfSpreadAngle"].SetValue(Spread / 2f);
@@ -99,7 +100,6 @@ namespace CalamityMod.Projectiles.Magic
Texture2D texture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/InvisibleProj").Value;
float angle = (Owner.Calamity().mouseWorld - Owner.MountedCenter).ToRotation();
Main.EntitySpriteDraw(texture, Owner.MountedCenter - Main.screenPosition, null, Color.White, angle, new Vector2(texture.Width / 2f, texture.Height/2f), 700f, 0, 0);
Main.spriteBatch.End();
+51 -5
View File
@@ -6,6 +6,8 @@ using Terraria.ModLoader;
using Terraria.Audio;
using Microsoft.Xna.Framework.Graphics;
using CalamityMod.Particles;
using Terraria.Graphics.Effects;
using System;
namespace CalamityMod.Projectiles.Ranged
{
@@ -26,6 +28,8 @@ namespace CalamityMod.Projectiles.Ranged
public Color ScopeColor => Color.White;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Titanium Scope");
@@ -149,17 +153,59 @@ namespace CalamityMod.Projectiles.Ranged
if (Charge == -1)
return false;
// Opacity scales with charge
Color drawColor = ScopeColor * ChargePercent;
float sightsSize = 700f;
float sightsResolution = 0.2f;
// Converge the sights
float spread = (1f - ChargePercent) * MaxSightAngle;
float halfAngle = spread / 2f;
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
// Draw the sights
Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, drawColor, MathHelper.WrapAngle(Projectile.rotation + MathHelper.PiOver2 + halfAngle), new Vector2(texture.Width / 2f, texture.Height), new Vector2(0.65f, 0.85f), SpriteEffects.None, 0f);
Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, drawColor, MathHelper.WrapAngle(Projectile.rotation + MathHelper.PiOver2 - halfAngle), new Vector2(texture.Width / 2f, texture.Height), new Vector2(0.65f, 0.85f), SpriteEffects.None, 0f);
Color sightsColor = Color.Lerp(Color.LightBlue, Color.Crimson, ChargePercent);
//Setup the spread gradient effect.
Effect spreadEffect = Filters.Scene["SpreadTelegraph"].GetShader().Shader;
spreadEffect.Parameters["centerOpacity"].SetValue(0.9f);
spreadEffect.Parameters["mainOpacity"].SetValue(ChargePercent);
spreadEffect.Parameters["halfSpreadAngle"].SetValue(halfAngle);
spreadEffect.Parameters["edgeColor"].SetValue(sightsColor.ToVector3());
spreadEffect.Parameters["centerColor"].SetValue(sightsColor.ToVector3());
spreadEffect.Parameters["edgeBlendLenght"].SetValue(0.07f);
spreadEffect.Parameters["edgeBlendStrength"].SetValue(8f);
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, spreadEffect, Main.GameViewMatrix.TransformationMatrix);
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, null, Color.White, Projectile.rotation, new Vector2(texture.Width / 2f, texture.Height / 2f), sightsSize, 0, 0);
//Setup the laser sights effect.
Effect laserScopeEffect = Filters.Scene["PixelatedSightLine"].GetShader().Shader;
laserScopeEffect.Parameters["sampleTexture2"].SetValue(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/CertifiedCrustyNoise").Value);
laserScopeEffect.Parameters["noiseOffset"].SetValue(Main.GameUpdateCount * -0.003f);
laserScopeEffect.Parameters["mainOpacity"].SetValue(ChargePercent); //Opacity increases as the gun charges
laserScopeEffect.Parameters["Resolution"].SetValue(new Vector2(sightsResolution * sightsSize));
laserScopeEffect.Parameters["laserAngle"].SetValue(-Projectile.rotation + halfAngle);
laserScopeEffect.Parameters["laserWidth"].SetValue(0.0025f + (float)Math.Pow(ChargePercent, 5) * ((float)Math.Sin(Main.GlobalTimeWrappedHourly * 3f) * 0.002f + 0.002f));
laserScopeEffect.Parameters["laserLightStrenght"].SetValue(7f);
laserScopeEffect.Parameters["color"].SetValue(sightsColor.ToVector3());
laserScopeEffect.Parameters["darkerColor"].SetValue(Color.Black.ToVector3());
laserScopeEffect.Parameters["bloomSize"].SetValue(0.06f);
laserScopeEffect.Parameters["bloomMaxOpacity"].SetValue(0.4f);
laserScopeEffect.Parameters["bloomFadeStrenght"].SetValue(7f);
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, laserScopeEffect, Main.GameViewMatrix.TransformationMatrix);
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, null, Color.White, 0, new Vector2(texture.Width / 2f, texture.Height / 2f), sightsSize, 0, 0);
laserScopeEffect.Parameters["laserAngle"].SetValue(-Projectile.rotation - halfAngle);
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, null, Color.White, 0, new Vector2(texture.Width / 2f, texture.Height / 2f), sightsSize, 0, 0);
Main.spriteBatch.End();
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
return false;
}
+33
View File
@@ -5,6 +5,7 @@ using ReLogic.Content;
using Terraria;
using Terraria.Enums;
using Terraria.ModLoader;
using CalamityMod.Particles;
namespace CalamityMod.Projectiles.Ranged
{
@@ -46,6 +47,38 @@ namespace CalamityMod.Projectiles.Ranged
base.AI();
}
public override void ExtraBehavior()
{
if (Projectile.timeLeft == 15)
{
Vector2 beamVector = Projectile.velocity;
float beamLenght = DetermineLaserLength_CollideWithTiles(12);
//Rapid dust
int dustCount = Main.rand.Next(10, 30);
for (int i = 0; i < dustCount; i++)
{
float dustProgressAlongBeam = beamLenght * Main.rand.NextFloat(0f, 0.8f);
Vector2 dustPosition = Projectile.Center + dustProgressAlongBeam * beamVector + beamVector.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(-6f, 6f) * Projectile.scale;
Dust dust = Dust.NewDustPerfect(dustPosition, 187, beamVector * Main.rand.NextFloat(5f, 26f), 0, Color.White, 2.2f);
dust.noGravity = true;
}
//Put a titanium shell into the impact tile (if it collided with one)
if (beamLenght < MaxLaserLength)
{
Vector2 endPoint = beamLenght * beamVector + Projectile.Center + beamVector * 8.5f;
Point anchorPos = new Point((int)endPoint.X / 16, (int)endPoint.Y / 16);
Color burnColor = Main.rand.NextBool(4) ? Color.PaleGreen : Main.rand.NextBool(4) ? Color.PaleTurquoise : Color.OrangeRed;
Particle shell = new TitaniumRailgunShell(endPoint, anchorPos, Projectile.rotation + MathHelper.PiOver2, burnColor);
GeneralParticleHandler.SpawnParticle(shell);
}
}
}
public override void DetermineScale() => Projectile.scale = Projectile.timeLeft / Lifetime * MaxScale;
public override float DetermineLaserLength() => DetermineLaserLength_CollideWithTiles(5);