Files
CalamityModPublic/Effects/MiracleBlight.fx
T
Toasty a88be3282f Added a new drawer system, and fixed some miracle blight visual issues. (#3)
* - Added ManagedRenderTarget to better handle RenderTarget2Ds.
- Added a Graphics folder that contains the above.
- Made all existing RenderTarget2Ds use the above instead.
- Removed some old/reduntant loading code for metaballs.
- Moved PrimitiveTrail to the new Graphics folder.

* - Manually unload the event, as afaik TMod will not do this.

* - Added a drawer system, for making doing more advanced visual effects easier.
- Moved miracle blight's shader effect to use this instead of the old method.
- Ares Body is now vulnerable to miracle blight again, as the visual effect is disabled seperately.
2023-11-02 12:34:11 -04:00

78 lines
2.4 KiB
HLSL

sampler uImage0 : register(s0);
sampler uImage1 : register(s1);
float3 uColor;
float3 uSecondaryColor;
float uOpacity : register(C0);
float uSaturation;
float uRotation;
float uTime;
float4 uSourceRect;
float2 uWorldPosition;
float uDirection;
float3 uLightSource;
float2 uImageSize0;
float2 uImageSize1;
float4 uShaderSpecificData;
// Cosine does not work in shaders in Terraria 1.4. It returns incredibly corrupted values and nobody is sure why.
// This reimplements cosine using trigonometric identities.
//
// Discovery of malfunctioning cosine attributed to ScalarVector from SLR:
// https://discord.com/channels/103110554649894912/445276626352209920/979928448300634175
float realCos(float value)
{
return sin(value + 1.57079);
}
//
// Based on Devourer of Gods' death animation (by Dominic)
// in turn, that was based on ExampleMod's cool death animation
//
float4 PixelShaderFunction(float2 coords : TEXCOORD0) : COLOR0
{
float4 color = tex2D(uImage0, coords);
if (!any(color))
return color;
// Temporal drift to make the sprite slide through the noise texture
float2 drift = float2(5 * sin(0.04165 * uTime), 1.1 * uTime);
float2 noiseMapTexCoords = coords + drift + uWorldPosition;
float4 noiseColor = tex2D(uImage1, noiseMapTexCoords);
// Define thresholds for total pixel erasure and glowing lines.
//
// Rapidly flickering sinewave produced by Desmos, loosely based on the Weierstrass function
// (infinitely sharp vague sinewave, periodic, continuous everywhere but differentiable nowhere)
// https://en.wikipedia.org/wiki/Weierstrass_function
float flickerOne = 0.05 * realCos(7 * uTime);
float flickerTwo = 0.06 * realCos(31 * uTime);
float flickerThree = 0.04 * sin(167 * uTime);
float fullErasureThreshold = uOpacity + flickerOne + flickerTwo + flickerThree;
float glowThreshold = fullErasureThreshold - 0.1;
// If the noise over the erasure threshold, completely erase this pixel.
if (noiseColor.r > fullErasureThreshold)
{
color.rgba = 0;
}
// Otherwise, if it's over the slightly lower threshold, replace it with a bright color.
else if (noiseColor.r > glowThreshold)
{
// Ensure it accounts for the original alpha.
color = float4(0.4902, 1, 0, 1) * color.a;
}
return color;
}
technique Technique1
{
pass BlightPass
{
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}