Files
CalamityModPublic/Effects/DoGDistortionWindsShader.fx
fryzahh 10fcee19a0 DoGSky full revamp
- Entirely revamped DoGSky and cleaned up some of its older code
- - Moved DoGSky and DoGShaderData from CalamityMod/NPCs/DevourerofGods to CalamityMod/Skies
- - Added three new shaders which are used in the new sky, DoGDistortionWindsShader, DoGBackgroundFogShader and CircularOpacityShader
- - Removed MonolithDistortionScene and adjusted DoGBackgroundScene to account for both monoliths when activating background visuals
- - Added a new field to PrimitiveSettings which allows primitives to render with the same unscaled perspective matrices used for pixelating them. This was a necessary addition as the new DoGSky utilizes the primitive drawing system for a special visual effect and wasn't scaling correctly with the rest of the background due to the normal perspective matrices for primitives using the game's zoom setting to scale them accordingly. Backgrounds and any associated effects do not scale with zoom, for further context.
2025-06-30 18:17:39 -04:00

77 lines
2.8 KiB
HLSL

sampler mainWindTexture : register(s0);
sampler windHighlightsTexture : register(s1);
sampler distortionTexture : register(s2);
sampler erosionTexture : register(s3);
float time;
float overallOpacity;
float distortionStrength;
float mainNoiseTextureScale;
float distortionTextureScale;
float erosionTextureScale;
float erosionMin;
float gradientPrecision;
float2 pixelationFactor;
float2 worldOffset;
float3 darkerPixelColor;
float3 brighterPixelColor;
float3 highlightsColor;
float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
// Pixelation.
coords = round(coords * pixelationFactor) / pixelationFactor;
// Stretch the coords out to better mimic a blowing wind effect.
coords *= float2(0.25, 1.25);
// Distort the coords in a sine wave so that they bend up and down.
coords.y += sin(coords.x * 10 + time) * 0.25;
// Move with the player in the world.
coords += worldOffset;
// Calculate the distortion that'll be applied to our base noise coordinates.
float2 distortedCoords = coords + float2(time * -0.18, 0) * distortionTextureScale;
float distortion = tex2D(distortionTexture, distortedCoords).r * distortionStrength;
// Calculate the base noise colors.
float2 adjustedCoords = (coords + distortion) * mainNoiseTextureScale;
float4 scrollingNoise1 = tex2D(mainWindTexture, adjustedCoords + float2(time * -0.092, 0));
float4 scrollingNoise2 = tex2D(mainWindTexture, adjustedCoords + float2(time * -0.031, 0));
// Multiply the red values of the noise maps together to get the horizontal brightness of both noise maps.
float combinedBrightness = scrollingNoise1.r * scrollingNoise2.r;
// Lerp between the two colors based on the brightness of a pixel.
float3 colorFromBrightness = lerp(darkerPixelColor, brighterPixelColor, combinedBrightness);
// Sample another texture to be used as highlights alongside the two noise textures.
float4 highlightNoise = tex2D(windHighlightsTexture, adjustedCoords + float2(time * -0.115, 0));
float4 windHighlights = highlightNoise * float4(highlightsColor, 1);
// Erode the final output to break up the entire effect slightly.
float erosionColor = tex2D(erosionTexture, adjustedCoords + float2(time * -0.087, 0) * erosionTextureScale);
float erosionMax = erosionMin + 1;
float erosion = smoothstep(erosionMin, erosionMax, erosionColor.r);
float4 finalColor = (float4(colorFromBrightness, 1) * (scrollingNoise1 + scrollingNoise2)) + (windHighlights * 2.25);
finalColor *= erosion;
// Apply posterization.
finalColor = round(finalColor * gradientPrecision) / gradientPrecision;
return finalColor * overallOpacity;
}
technique Technique1
{
pass DistortionWindsPass
{
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}