Files
UnleashedRecomp-hedge-dev/UnleashedRecomp/gpu/shader/gaussian_blur.hlsli
Skyth (Asilkan) d56b823b00 Aspect ratio adjustments. (Part 1) (#90)
* Map CSD structures by full path.

* Initial work for unstretching & aligning to edges.

* Add extend flag, fix cast lookups.

* Add right extend flag.

* Fill the flags map with a bunch of casts.

* Implement unstretching.

* Set more title casts to unscretch.

* Add some more flags.

* Move CSD patches to its own file.

* Replace CSD vertex shaders to get rid of pixel snapping.

* Snap to pixel on the CPU.

* Current work trying to get 3D screen position casts working correctly.

* Fix and properly align font, handle most 3D screen positions.

* Add stretch flags for background casts.

* Use 4:3 as the base aspect ratio instead of 16:9.

* Replicate the game's 4:3 downscaling behavior.

* World map now identical to original 4:3.

* Replace camera aspect ratio/field of view logic.

* Make original 4:3 scaling a separate option, use custom behavior for auto.

* Keep UI scale same only above Steam Deck aspect ratio.

* Release paths when the YNCP file gets freed.

* Add more path flags.

* Interpolate to original 4:3 scale.

* Scaling animation offset to prevent offscreen casts from showing up in ultrawide.

* Queue draw calls without actually executing anything to extract the corner.

* Clean unnecessary hooks.

* Add result screen modifiers.

* Stretch loading primitive 2D.

* Scale DoF correctly at different aspect ratios.

* Remove stretch option.

* Make aspect ratio a global variable.

* Ultrawide patch for HUD 3D items.

* Fix world map 3D to 2D projection.

* Right align world map info box.

* Set medal positions.

* Respect center option in more places.

* Implement the aspect ratio option.

* Use viewport dimensions for snapping CSD pixels.

* Fix DoF fix not using viewport height.

* Implement aspect ratio patches for 2D drop ring emitter.

* Implement inspire letterbox.

* Add cutscene aspect ratio option.

* Shift subtitles by aspect ratio.

* Fix crash in earth restoration cutscenes.

* Offset scale patches for Tornado Defense.

* Scale new record arrow casts.

* Expose aspect ratio variables globally.

* Properly center the achievements menu.

* 4:3 scaling for options menu.

* Fix procedural filtering logic in ImGui pixel shader.

* Fix button guide offset.

* UI scaling for installer.

* Remove grid snaps in the installer.

* Handle center UI scale option for rings going to HUD.

* Remove unnecessary diff.

* Revert temporary changes.

* Fix typo.
2025-01-18 01:51:45 +03:00

76 lines
2.4 KiB
HLSL

#include "../../../tools/ShaderRecomp/ShaderRecomp/shader_common.h"
#ifdef __spirv__
#define g_ViewportSize vk::RawBufferLoad<float4>(g_PushConstants.PixelShaderConstants + 384, 0x10)
#define g_offsets(INDEX) select((INDEX) < 74, vk::RawBufferLoad<float4>(g_PushConstants.PixelShaderConstants + (150 + min(INDEX, 73)) * 16, 0x10), 0.0)
#define g_weights vk::RawBufferLoad<float4>(g_PushConstants.PixelShaderConstants + 2656, 0x10)
#define s0_Texture2DDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 0)
#define s0_SamplerDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 192)
#else
cbuffer PixelShaderConstants : register(b1, space4)
{
float4 g_ViewportSize : packoffset(c24);
float4 g_offsets[2] : packoffset(c150);
#define g_offsets(INDEX) select((INDEX) < 74, g_offsets[min(INDEX, 73)], 0.0)
float4 g_weights : packoffset(c166);
};
cbuffer SharedConstants : register(b2, space4)
{
uint s0_Texture2DDescriptorIndex : packoffset(c0.x);
uint s0_SamplerDescriptorIndex : packoffset(c12.x);
DEFINE_SHARED_CONSTANTS();
};
#endif
#ifdef __INTELLISENSE__
#define KERNEL_SIZE 5
#endif
#define PI 3.14159265358979323846
float ComputeWeight(float x)
{
float std = 0.952;
return exp(-(x * x) / (2.0 * std * std)) / (std * sqrt(2.0 * PI));
}
float4 main(in float4 iPosition : SV_Position, in float4 iTexCoord0 : TEXCOORD0) : SV_Target
{
Texture2D<float4> texture = g_Texture2DDescriptorHeap[s0_Texture2DDescriptorIndex];
SamplerState samplerState = g_SamplerDescriptorHeap[s0_SamplerDescriptorIndex];
float scale;
if ((g_ViewportSize.x * g_ViewportSize.w) >= (16.0 / 9.0))
scale = g_ViewportSize.y / 360.0;
else
scale = g_ViewportSize.x / 640.0;
float2 offsets[3];
offsets[0] = g_offsets(0).xy * scale;
offsets[1] = g_offsets(0).zw * scale;
offsets[2] = g_offsets(1).xy * scale;
float4 color = 0.0;
float weightSum = 0.0;
[unroll]
for (int i = 0; i < KERNEL_SIZE; i++)
{
float step = i / float(KERNEL_SIZE - 1);
float scaled = step * 2;
float2 offset = lerp(offsets[int(scaled)], offsets[min(int(scaled) + 1, 2)], frac(scaled));
float offsetScale = 1.0 / 0.75;
float weight = ComputeWeight(lerp(-offsetScale, offsetScale, step));
color += texture.SampleLevel(samplerState, iTexCoord0.xy + offset, 0) * weight;
weightSum += weight;
}
return color / weightSum;
}