using CalamityMod.Skies; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria.Graphics.Effects; using Terraria.Graphics.Shaders; using Terraria.ModLoader; namespace CalamityMod.Effects { // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. // TODO: SOURCEGEN: Get rid of this loader and replace references with sourcegenned references [Autoload(Side = ModSide.Client)] public sealed class CalamityShaders : ModSystem { private const string ShaderPath = "Effects/"; internal const string CalamityShaderPrefix = "CalamityMod:"; // made by boffin. Source code not available. Creates fog in the astral infection internal static Asset AstralFogShader; // // All below shaders created by Lucille Karma // #region Lucille's Shaders // The Dance of Light's Blinding Light internal static Asset DanceOfLightBlindingShader; // Calamity accessory internal static Asset CalamityAccessoryMouseShader; // Subsuming Vortex tentacles internal static Asset SubsumingVortexTentacleShader; // Draedon teleporting shader internal static Asset DraedonTeleportShader; // UNKNOWN -- PROBABLY UNUSED internal static Asset LightDistortionShader; // Phaseslayer red energy trail internal static Asset PhaseslayerRipShader; // Generic UV-fade streak trail shader. Used by many things? internal static Asset FadedUVMapStreakShader; // Generic flaming streak trail shader. Used by many things? internal static Asset FlameStreakShader; // Generic solid trail shader. Used by many things? internal static Asset FadingSolidTrailShader; // Typical projectile javelin glowing trail. BEWARE: Is used by many items! internal static Asset ScarletDevilShader; // Yharon border flame pillar trail. internal static Asset BordernadoFireShader; // Photon Ripper hardlight teeth trail shader internal static Asset PrismCrystalShader; // Generic flame trail. BEWARE: Reused by Apollo, Artemis, Cosmilamp, Gem Tech broken gems, and Persecuted enchant portal demons internal static Asset ImpFlameTrailShader; // Supreme Witch, Calamitas' force field (which is her visual hitbox) internal static Asset SCalShieldShader; // Rancor's alchemical / satanic circle which floats near the player. The laser is emitted from here internal static Asset RancorMagicCircleShader; // Generic colored glow shader. BEWARE: Used by about a billion things, including Ares telegraphs, the Biome Blade line, etc. internal static Asset BasicTintShader; // Generic "pie chart" shader that renders only certain arc sectors of things. Used for the Cooldown Rack and various other visuals. internal static Asset CircularBarShader; // Cooldown Rack shader used to draw the cooldown's icon appropriately. internal static Asset CircularBarSpriteShader; // Devourer of Gods' death animation where he disintegrates into purple energy stuff. internal static Asset DoGDisintegrationShader; // Art Attack's main projectile trail shader (Visually designed to match Paper Mario) internal static Asset ArtAttackTrailShader; // Generic AoE telegraph. Used for Ares' nukes to denote their area of effect. internal static Asset CircularAoETelegraph; // Clips a sprite along a fixed plane. Used by Stream Gouge to have half-spears come out of portals. internal static Asset IntersectionClipShader; // Was previously used by Dom's Bladecrest Oathsword. Appears to govern the swing animation. internal static Asset LocalLinearTransformationShader; // UNUSED -- Probably leftover from Lucille's experiments with applying shaders to primitives (arbitrary GPU-rendered triangles) internal static Asset BasicPrimitiveShader; // Artemis Ohio Beam. Also used by get fixed boi Nuclear Terror's "G-FUEL BEAM" internal static Asset ArtemisLaserShader; // Exoblade's melee slash trails. Also used by Terratomere internal static Asset ExobladeSlashShader; // Exoblade's projectile on-hit "anime slash marks". Also used by Terratomere internal static Asset ExobladePierceShader; // Used by Subsuming Vortex's various vortices. Draws the main vortices. BEWARE: Reused by Burning Sea's fireball. internal static Asset ExoVortexShader; // Used by Subsuming Vortex's small vortices. Draws the trailing energy tendrils. internal static Asset SideStreakTrailShader; // Used by Heavenly Gale's hardlight arrows. internal static Asset HeavenlyGaleTrailShader; // Used by Heavenly Gale's exo lightning strikes. Also used by Stormfront Razor lightning. internal static Asset HeavenlyGaleLightningShader; // Used in the Codebreaker on Draedon's sprite while communicating with him. internal static Asset BlueStaticShader; // Used by Acid Eels, presumably to have their snaking movements look more smooth. internal static Asset PrimTextureOverlayShader; // Used as a default for primitive drawing when no specific shader is supplied. This shader simply renders the vertex color data without modification. internal static Asset StandardPrimitiveShader; // Used by Devourer of Gods. Renders the portal that he escapes through at the end of phase 1. internal static Asset DoGPortalShader; // Used to render all-encompassing fog in the Floral Paradise biome. internal static Asset FogShader; // Used to render background water features in the Floral Paradise biome. internal static Asset WaterfallShader; // Metaballs. See the MetaballManager class for comments on how this system works. // These shaders are leveraged to render the results of the metaball simulation to the screen. // The "Base" shader draws the particles themselves. // The "Additive" shader actually FUSES the particles into their blobby mess. // // Backing textures vary. The primary use of this system is Gruesome Eminence. internal static Asset MetaballEdgeShader; internal static Asset AdditiveMetaballEdgeShader; // Used to render the results of Navier-Stokes fluid simulations. internal static Asset FluidShaders; // Used by projectiles fired by the Sylvestaff. internal static Asset SylvestaffProjectileShader; // Used by the ribbons on the Sylvestaff. internal static Asset SylvestaffRibbonShader; #endregion // // All below shaders were added to Calamity by IbanPlay // Authorship between IbanPlay and other SLR devs unknown // #region Iban's Shaders // Used by Coral Spout and Titanium Railgun while charging to indicate current projectile spread. internal static Asset SpreadTelegraph; // Used by Wulfrum Screwdriver and Titanium Railgun. Renders a pixelly "laser sight". internal static Asset PixelatedSightLine; // Used by the Wulfrum Treasure Pinger to highlight tiles in range internal static Asset WulfrumTilePing; // Used by the Wulfrum Scaffold Kit to highlight locations where Scaffold tiles will be placed internal static Asset WulfrumScaffoldSelection; // Used to render the Rover Drive's force field around the player internal static Asset RoverDriveShield; // UNUSED -- Probably leftover from Iban's work on the Biome Blade and Ark lines. internal static Asset RotateSprite; // Used on Exoblade to draw the sword swinging dramatically. This was the edit Iban made to Dom's Exoblade. internal static Asset SwingSprite; #endregion // // All below shaders created by Ozzatron // #region Ozz's Shaders // Used on players and NPCs when they have the Miracle Blight debuff. internal static Asset MiracleBlight; #endregion #region Aqua's Shaders internal static Asset CircularGradientWithEdge; internal static Asset GaleforceArrowTrailShader; internal static Asset WavyOpacity; internal static Asset HellBall; #endregion // // All below shaders were added or created by Amber // Authorship for the PrimitiveClearShader goes to Toasty // #region Amber's Shaders internal static Asset PrimitiveClearShader; internal static Asset HolyInfernoShader; #endregion #region YuH's Shaders internal static Asset TeslaTrailShader; #endregion #region Doze's Shaders /// /// The shader used for Abyss's custom light system. /// Basically works by turning textures into an opacity mask /// internal static Asset DozeLightingShader; /// /// Flips the screen. Used for Gravity Globe. /// internal static Asset FlipScreenShader; /// /// Distorts a texture towards the center based on a provided noisemap. Meant to emulate the Terraria Otherworld barrier effects. /// Opacity is the intensity of this distortion, and Saturation is the speed the noisemap moves at. /// internal static Asset OtherworldBarrierDistortionShader; #endregion // // All below shaders were created by fryzahh // #region fryzahh's Shaders // A simple shader which distorts an image using a provided texture of choice. internal static Asset BasicTextureDistortionShader; // The underwater rays seen at the top of the Sunken Sea Mod Menu. internal static Asset UnderwaterRaysShader; // The blowing wind-like effect seen in the background during DoG's fight. internal static Asset DoGDistortionWindsShader; // The rolling fog clouds seen behind the Distortion Winds effect during DoG's fight. internal static Asset DoGBackgroundFogShader; // Allows a texture to control its opacity from the edges to the center in the shape of a circle. internal static Asset CircularOpacityShader; // The shader effect imposed onto the static crack textures seen during DoG's fight. Fades out the texture from its edges to its center and // allows it to lerp between two colors depending on the brightness of individual pixels along the sampled texture. internal static Asset DoGRealityCrackShader; // The distorted circular effect seen emanating from the distortion rift during DoG's fight. internal static Asset DoGRiftAuraShader; // The shader effect used for Voidragon's Abyssal Fire laser projectile. internal static Asset AbyssalFireShader; #endregion #region Big E's Shaders internal static Asset RadialBlur; internal static Asset SeaPrismColorBlendingShader; internal static Asset Dissolve; internal static Asset BrainOfCthulhuForcefield; #endregion #region jasper's shaders internal static Asset NanoblackSlashShader; // static gaussian bloom, cannot change parameters. do not reuse this if that binds you. internal static Asset GaussianBloomShader; #endregion internal static Asset SunkenSeaMenuLogoWater; public override void PostSetupContent() { AssetRepository calAss = CalamityMod.Instance.Assets; // Shorthand to load shaders immediately. // Strings provided to LoadShader are the .xnb file paths. Asset LoadShader(string path) => calAss.Request($"{ShaderPath}{path}", AssetRequestMode.ImmediateLoad); // // Loading and registering each individual compiled shader for use. // AstralFogShader = LoadShader("AstralFogShader"); var astralPassReg = new AstralScreenShaderData(AstralFogShader, "AstralPass").UseColor(0.18f, 0.08f, 0.24f); RegisterSceneFilter(astralPassReg, "Astral", EffectPriority.VeryHigh); #region Loading Lucille's Shaders DanceOfLightBlindingShader = LoadShader("LightBurstShader"); RegisterScreenShader(DanceOfLightBlindingShader, "BurstPass", "LightBurst"); SubsumingVortexTentacleShader = LoadShader("TentacleShader"); RegisterMiscShader(SubsumingVortexTentacleShader, "BurstPass", "SubsumingTentacle"); DraedonTeleportShader = LoadShader("TeleportDisplacementShader"); RegisterMiscShader(DraedonTeleportShader, "GlitchPass", "TeleportDisplacement"); CalamityAccessoryMouseShader = LoadShader("SCalMouseShader"); RegisterMiscShader(CalamityAccessoryMouseShader, "DyePass", "FireMouse"); // THIS SHADER IS UNUSED. LightDistortionShader = LoadShader("DistortionShader"); PhaseslayerRipShader = LoadShader("PhaseslayerRipShader"); RegisterMiscShader(PhaseslayerRipShader, "TrailPass", "PhaseslayerRipEffect"); FadedUVMapStreakShader = LoadShader("FadedUVMapStreak"); RegisterMiscShader(FadedUVMapStreakShader, "TrailPass", "TrailStreak"); FlameStreakShader = LoadShader("Flame"); RegisterMiscShader(FlameStreakShader, "TrailPass", "Flame"); FadingSolidTrailShader = LoadShader("FadingSolidTrail"); RegisterMiscShader(FadingSolidTrailShader, "TrailPass", "FadingSolidTrail"); ScarletDevilShader = LoadShader("ScarletDevilStreak"); RegisterMiscShader(ScarletDevilShader, "TrailPass", "OverpoweredTouhouSpearShader"); BordernadoFireShader = LoadShader("BordernadoFire"); RegisterMiscShader(BordernadoFireShader, "TrailPass", "Bordernado"); PrismCrystalShader = LoadShader("PrismCrystalStreak"); RegisterMiscShader(PrismCrystalShader, "TrailPass", "PrismaticStreak"); ImpFlameTrailShader = LoadShader("ImpFlameTrail"); RegisterMiscShader(ImpFlameTrailShader, "TrailPass", "ImpFlameTrail"); SCalShieldShader = LoadShader("SupremeShieldShader"); RegisterMiscShader(SCalShieldShader, "ShieldPass", "SupremeShield"); RancorMagicCircleShader = LoadShader("RancorMagicCircle"); RegisterMiscShader(RancorMagicCircleShader, "ShieldPass", "RancorMagicCircle"); BasicTintShader = LoadShader("BasicTint"); RegisterMiscShader(BasicTintShader, "TintPass", "BasicTint"); CircularBarShader = LoadShader("CircularBarShader"); RegisterMiscShader(CircularBarShader, "Pass0", "CircularBarShader"); CircularBarSpriteShader = LoadShader("CircularBarSpriteShader"); RegisterMiscShader(CircularBarSpriteShader, "Pass0", "CircularBarSpriteShader"); DoGDisintegrationShader = LoadShader("DoGDisintegration"); RegisterMiscShader(DoGDisintegrationShader, "DisintegrationPass", "DoGDisintegration"); ArtAttackTrailShader = LoadShader("ArtAttackTrail"); RegisterMiscShader(ArtAttackTrailShader, "TrailPass", "ArtAttack"); CircularAoETelegraph = LoadShader("CircularAoETelegraph"); RegisterMiscShader(CircularAoETelegraph, "TelegraphPass", "CircularAoETelegraph"); IntersectionClipShader = LoadShader("IntersectionClipShader"); RegisterMiscShader(IntersectionClipShader, "ClipPass", "IntersectionClip"); LocalLinearTransformationShader = LoadShader("LocalLinearTransformationShader"); RegisterMiscShader(LocalLinearTransformationShader, "TransformationPass", "LinearTransformation"); // NOTE: despite being registered, this shader is UNUSED BasicPrimitiveShader = LoadShader("BasicPrimitiveShader"); RegisterMiscShader(BasicPrimitiveShader, "TrailPass", "PrimitiveDrawer"); ArtemisLaserShader = LoadShader("ArtemisLaserShader"); RegisterMiscShader(ArtemisLaserShader, "TrailPass", "ArtemisLaser"); ExobladeSlashShader = LoadShader("ExobladeSlashShader"); RegisterMiscShader(ExobladeSlashShader, "TrailPass", "ExobladeSlash"); ExobladePierceShader = LoadShader("ExobladePierceShader"); RegisterMiscShader(ExobladePierceShader, "PiercePass", "ExobladePierce"); ExoVortexShader = LoadShader("ExoVortexShader"); RegisterMiscShader(ExoVortexShader, "VortexPass", "ExoVortex"); SideStreakTrailShader = LoadShader("SideStreakTrail"); RegisterMiscShader(SideStreakTrailShader, "TrailPass", "SideStreakTrail"); HeavenlyGaleTrailShader = LoadShader("HeavenlyGaleTrailShader"); RegisterMiscShader(HeavenlyGaleTrailShader, "PiercePass", "HeavenlyGaleTrail"); HeavenlyGaleLightningShader = LoadShader("HeavenlyGaleLightningShader"); RegisterMiscShader(HeavenlyGaleLightningShader, "TrailPass", "HeavenlyGaleLightningArc"); BlueStaticShader = LoadShader("BlueStaticShader"); RegisterMiscShader(BlueStaticShader, "GlitchPass", "BlueStatic"); PrimTextureOverlayShader = LoadShader("PrimTextureOverlayShader"); RegisterMiscShader(PrimTextureOverlayShader, "TrailPass", "PrimitiveTexture"); StandardPrimitiveShader = LoadShader("StandardPrimitiveShader"); RegisterMiscShader(StandardPrimitiveShader, "PrimitivePass", "StandardPrimitiveShader"); DoGPortalShader = LoadShader("ScreenShaders/DoGPortalShader"); RegisterMiscShader(DoGPortalShader, "ScreenPass", "DoGPortal"); FogShader = LoadShader("ScreenShaders/Fog"); RegisterMiscShader(FogShader, "DyePass", "Fog"); WaterfallShader = LoadShader("WaterfallShader"); RegisterMiscShader(WaterfallShader, "TrailPass", "Waterfall"); // These two shaders are often (but not always) used together. MetaballEdgeShader = LoadShader("Metaballs/MetaballEdgeShader"); RegisterMiscShader(MetaballEdgeShader, "ParticlePass", "MetaballEdge"); AdditiveMetaballEdgeShader = LoadShader("Metaballs/AdditiveMetaballEdgeShader"); RegisterMiscShader(AdditiveMetaballEdgeShader, "ParticlePass", "AdditiveMetaballEdge"); // This shader is not registered with the game but is invoked directly to render the results of fluid simulation. FluidShaders = LoadShader("FluidShaders"); SylvestaffProjectileShader = LoadShader("SylvestaffProjectileShader"); RegisterMiscShader(SylvestaffProjectileShader, "TrailPass", "SylvestaffProjectile"); SylvestaffRibbonShader = LoadShader("SylvestaffRibbonShader"); RegisterMiscShader(SylvestaffRibbonShader, "AutoloadPass", "SylvestaffRibbon"); #endregion #region Loading Iban's Shaders SpreadTelegraph = LoadShader("SpreadTelegraph"); RegisterScreenShader(SpreadTelegraph, "TelegraphPass", "SpreadTelegraph"); PixelatedSightLine = LoadShader("PixelatedSightLine"); RegisterScreenShader(PixelatedSightLine, "SightLinePass", "PixelatedSightLine"); WulfrumTilePing = LoadShader("WulfrumTilePing"); RegisterScreenShader(WulfrumTilePing, "TilePingPass", "WulfrumTilePing"); WulfrumScaffoldSelection = LoadShader("WulfrumScaffoldSelection"); RegisterScreenShader(WulfrumScaffoldSelection, "TilePingPass", "WulfrumScaffoldSelection"); RoverDriveShield = LoadShader("RoverDriveShield"); RegisterScreenShader(RoverDriveShield, "ShieldPass", "RoverDriveShield"); // THIS SHADER IS UNUSED. RotateSprite = LoadShader("RotateSprite"); RegisterScreenShader(RotateSprite, "RotationPass", "RotateSprite"); SwingSprite = LoadShader("SwingSprite"); RegisterScreenShader(SwingSprite, "SwingPass", "SwingSprite"); #endregion #region Loading Ozz's Shaders MiracleBlight = LoadShader("MiracleBlight"); RegisterMiscShader(MiracleBlight, "BlightPass", "MiracleBlight"); #endregion #region Loading Aqua's Shaders CircularGradientWithEdge = LoadShader("CircularGradientWithEdge"); RegisterMiscShader(CircularGradientWithEdge, "CircularGradientWithEdgePass", "CircularGradientWithEdge"); GaleforceArrowTrailShader = LoadShader("GaleforceArrowTrail"); RegisterMiscShader(ArtAttackTrailShader, "TrailPass", "GaleforceArrowTrail"); WavyOpacity = LoadShader("WavyOpacity"); RegisterMiscShader(WavyOpacity, "WavyOpacityPass", "WavyOpacity"); HellBall = LoadShader("HellBall"); RegisterScreenShader(HellBall, "HellBallPass", "HellBall"); #endregion #region Loading Amber's Shaders PrimitiveClearShader = LoadShader("PrimitiveClearShader"); RegisterScreenShader(PrimitiveClearShader, "AutoloadPass", "PrimitiveClearShader"); HolyInfernoShader = LoadShader("ScreenShaders/HolyInfernoShader"); RegisterMiscShader(HolyInfernoShader, "InfernoPass", "HolyInfernoShader"); #endregion #region Loading YuH's Shaders TeslaTrailShader = LoadShader("TeslaTrail"); RegisterMiscShader(TeslaTrailShader, "TrailPass", "TeslaTrail"); #endregion #region Loading Doze's Shaders DozeLightingShader = LoadShader("DozeLightingShader"); RegisterMiscShader(DozeLightingShader, "ShadowPass", "DozeLightingShader"); FlipScreenShader = LoadShader("ScreenShaders/FlipScreen"); RegisterScreenShader(FlipScreenShader, "FlipTheScreen", "FlipScreen",EffectPriority.VeryHigh); OtherworldBarrierDistortionShader = LoadShader("OtherworldBarrierDistortion"); RegisterMiscShader(OtherworldBarrierDistortionShader, "DistortionPass", "OtherworldBarrierDistortion"); #endregion #region Loading fryzahh's Shaders BasicTextureDistortionShader = LoadShader("BasicTextureDistortionShader"); RegisterMiscShader(BasicTextureDistortionShader, "DistortionPass", "BasicTextureDistortion"); UnderwaterRaysShader = LoadShader("UnderwaterRaysShader"); RegisterMiscShader(UnderwaterRaysShader, "UnderwaterRayPass", "UnderwaterRays"); DoGDistortionWindsShader = LoadShader("DoGDistortionWindsShader"); RegisterMiscShader(DoGDistortionWindsShader, "DistortionWindsPass", "DoGDistortionWinds"); DoGBackgroundFogShader = LoadShader("DoGBackgroundFogShader"); RegisterMiscShader(DoGBackgroundFogShader, "DoGFogPass", "DoGBackgroundFog"); CircularOpacityShader = LoadShader("CircularOpacityShader"); RegisterMiscShader(CircularOpacityShader, "CircularOpacityPass", "CircularOpacity"); DoGRealityCrackShader = LoadShader("DoGRealityCrackShader"); RegisterMiscShader(DoGRealityCrackShader, "DoGRealityCrackPass", "DoGRealityCrack"); DoGRiftAuraShader = LoadShader("DoGRiftAuraShader"); RegisterMiscShader(DoGRiftAuraShader, "DoGRiftAuraPass", "DoGRiftAura"); AbyssalFireShader = LoadShader("AbyssalFireShader"); RegisterMiscShader(AbyssalFireShader, "LaserPass", "AbyssalFire"); #endregion #region Loading Big E's Shaders RadialBlur = LoadShader("ScreenShaders/RadialBlur"); RegisterScreenShader(RadialBlur, "RadialBlurPass", "RadialBlurShader"); SeaPrismColorBlendingShader = LoadShader("SeaPrismColorBlending"); RegisterMiscShader(SeaPrismColorBlendingShader, "SeaPrismBlendingPass", "SeaPrismColorBlending"); Dissolve = LoadShader("Dissolve"); RegisterMiscShader(Dissolve, "DissolvePass", "Dissolve"); BrainOfCthulhuForcefield = LoadShader("ScreenShaders/BrainOfCthulhuForcefield"); RegisterScreenShader(BrainOfCthulhuForcefield, "BoCShieldPass", "BrainOfCthulhuForcefield"); #endregion NanoblackSlashShader = LoadShader("SlashEffects/NanoblackSlash"); RegisterMiscShader(NanoblackSlashShader, "SlashPass", "NanoblackSlash"); GaussianBloomShader = LoadShader("SlashEffects/GaussianBloom"); RegisterMiscShader(GaussianBloomShader, "BloomShader", "GaussianBloom"); SunkenSeaMenuLogoWater = LoadShader("UI/SunkenSeaMenuLogoWater"); } // Shorthand to register a loaded shader in Terraria's graphics engine // All shaders registered this way are accessible under GameShaders.Misc // They will use the prefix described above private static void RegisterMiscShader(Asset shader, string passName, string registrationName) { MiscShaderData passParamRegistration = new(shader, passName); GameShaders.Misc[$"{CalamityShaderPrefix}{registrationName}"] = passParamRegistration; } private static void RegisterSceneFilter(ScreenShaderData passReg, string registrationName, EffectPriority priority = EffectPriority.High) { string prefixedRegistrationName = $"{CalamityShaderPrefix}{registrationName}"; Filters.Scene[prefixedRegistrationName] = new Filter(passReg, priority); Filters.Scene[prefixedRegistrationName].Load(); } // Shorthand to register a loaded shader in Terraria's graphics engine // All shaders registered this way are accessible under Filters.Scene // They will use the prefix described above private static void RegisterScreenShader(Asset shader, string passName, string registrationName, EffectPriority priority = EffectPriority.High) { ScreenShaderData passParamRegistration = new(shader, passName); RegisterSceneFilter(passParamRegistration, registrationName, priority); } } }