From 77d7a18c024bb999b4f972584e4afcd2ff97dab6 Mon Sep 17 00:00:00 2001 From: doze-zoze Date: Mon, 3 Nov 2025 23:25:59 -0600 Subject: [PATCH] added barrier shader --- Effects/CalamityShaders.cs | 11 ++++ Effects/OtherworldBarrierDistortion.fx | 73 ++++++++++++++++++++++++ Effects/OtherworldBarrierDistortion.xnb | Bin 0 -> 2412 bytes 3 files changed, 84 insertions(+) create mode 100644 Effects/OtherworldBarrierDistortion.fx create mode 100644 Effects/OtherworldBarrierDistortion.xnb diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 83d6559fb6..39e43d9f4e 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -213,7 +213,15 @@ namespace CalamityMod.Effects #endregion #region Doze's Shaders + /// + /// Flips the screen. Used for Gravity Globe. + /// internal static Effect 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 Effect OtherworldBarrierDistortionShader; #endregion // @@ -458,6 +466,9 @@ namespace CalamityMod.Effects #region Loading Doze's Shaders FlipScreenShader = LoadShader("ScreenShaders/FlipScreen"); RegisterScreenShader(FlipScreenShader, "FlipTheScreen", "FlipScreen",EffectPriority.VeryHigh); + + OtherworldBarrierDistortionShader = LoadShader("OtherworldBarrierDistortion"); + RegisterMiscShader(OtherworldBarrierDistortionShader, "DistortionPass", "OtherworldBarrierDistortion"); #endregion #region Loading fryzahh's Shaders diff --git a/Effects/OtherworldBarrierDistortion.fx b/Effects/OtherworldBarrierDistortion.fx new file mode 100644 index 0000000000..f58bad5207 --- /dev/null +++ b/Effects/OtherworldBarrierDistortion.fx @@ -0,0 +1,73 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; //Opacity works as the intensity of the filter +float uSaturation; //Saturation works as the speed of the noise movement +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +float4 uShaderSpecificData; + +float2 RotateUV(float2 uv, float radians) +{ + // Translate UV so center is origin + float2 centered = uv - 0.5; + + // Apply rotation + float cosTheta = cos(radians); + float sinTheta = sin(radians); + float2 rotated; + rotated.x = centered.x * cosTheta - centered.y * sinTheta; + rotated.y = centered.x * sinTheta + centered.y * cosTheta; + + // Translate back + return rotated + 0.5; +} + +float4 AdjustPixelPosition(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0 +{ + + //Drift to offset the noisemap. X multiplier is a prime number to ensure the "loop time" of this is very high, it takes 100 uTime to return to the original state + float2 drift = float2(0.23 * uTime * uSaturation, uTime * uSaturation); + + //double the noise so that it like... looks less like it's just moving in one direction or something? idk how to do this best. Also applying this one in a perpendicular direction. + float offsetToHave1 = tex2D(uImage1, coords + drift.yx).x; + + //Gets the offset from the red channel of whatever pixel this should get from the noisemap. This is fine because the noisemap is greyscale. + float offsetToHave = tex2D(uImage1, coords + offsetToHave1).x; + + + //Run a second noise check to make it look less like a texture moving in a straight line + offsetToHave = tex2D(uImage1, coords + drift).x; + + //This is the uv distance from the center of the texture + float2 uvOffsetFromCenter = (coords - 0.5); + + float2 modifiedCoords = coords + uvOffsetFromCenter * offsetToHave * uOpacity; + + //This mask is to prevent weird stretching effects at the edge of the tecture + float mask = step(0, modifiedCoords.x) * step(modifiedCoords.y, 1) * + step(0, modifiedCoords.y) * step(modifiedCoords.x, 1); + + //This makes a greyscale, "additive" draw input image transparent + // I would like to just draw additive but i've been unable to figure that out. Yay. + float4 distortedColor = tex2D(uImage0, modifiedCoords); + distortedColor.a = distortedColor.x; + + return distortedColor * sampleColor * mask; +} + + +technique Technique1 +{ + pass DistortionPass + { + PixelShader = compile ps_2_0 AdjustPixelPosition(); + } +} \ No newline at end of file diff --git a/Effects/OtherworldBarrierDistortion.xnb b/Effects/OtherworldBarrierDistortion.xnb new file mode 100644 index 0000000000000000000000000000000000000000..78c87d3356591a2e388e19fedefa97d00f3955aa GIT binary patch literal 2412 zcmbtVL2nyX5T4yQsoT0*gg78%i9K*AQe-(ML9UdD61#y21IFusIknr(bG@qLb=SK} zf;gBP5*&i)k%J|AsG3U-y-^7cTzaUexX?q7KIV{L;O#fNe(Ogd0>LEX_kFW7^JZqB zpIaZT@6J>AJdyUD_Mz+e-oR@Ig;vilZ20z$*!BF|g^Je;L@y{@Yqy0HG=#k^{6+ID z@ArJW-*KJ6qWP)t2d>v!TP_s&Z_%uT-5~VET2F+5Z+92XdU&(zIvEz zr(M1&mbS%8ab@K#V$puh68(1Z*k_8f4p)Ve0Umzl`Q7chH*n*2(tdL6JQa?SaTkHZ zs_SD9Za>|ps`$&gWjwE!IIia2>I7C?BpHSw{k~LUPuCdt6`wE5{Q_r9#vJ|YnAw>- zR$|VY<11XJ)!}cS)fbN2cAcsn*m3_nFOE}%ZB=&=cs|dgZVv`TJfo&?Iz9JJD3&N< zAD$n_atXY?3YBshU{w;VHE2iSL*O42{s{P)!jFNo@&y6sfy)Z70e2L>2YgrI4}qU5 z{1`Z^%qkCDR(K0IQ24jN_Z9vN@N~cN`ub${l13()~&LgX^X1MN02<^K#=&^ZlAtGm`^nR=l0Q+ZDcf zrBHgiaAl=bD3zC&X%g*Hy>ZRb^w!2CDyIE^gY0bM9^(ErGP$QJRQ6Q|z5(U_^|&L7 z`)8YakNs2a$({7q9)rFA(oYWkSexpcPGjb(Z4$jkmD*;L?}PsvJ@p z`V(xAho}qxaXdJUI1lI0D9J&{!7)0W8zMh^#s>+{f^&}O0C`bE2AICmX={Y>r~v#hjU>ToI8!fzB=Xr+jz*cd;#QcJxc%p literal 0 HcmV?d00001