forked from doodlum/skyrim-community-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISRadialBlur.hlsl
55 lines (44 loc) · 1.37 KB
/
ISRadialBlur.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsli"
typedef VS_OUTPUT PS_INPUT;
struct PS_OUTPUT
{
float4 Color : SV_Target0;
};
#if defined(PSHADER)
SamplerState ImageSampler : register(s0);
Texture2D<float4> ImageTex : register(t0);
cbuffer PerGeometry : register(b2)
{
float4 Params : packoffset(c0);
float4 Center : packoffset(c1);
};
float GetCircleParam(float centerDistance, float param1, float param2)
{
float circleDistance = max(0, centerDistance - param1);
float result = 0;
if (circleDistance > 0) {
result = Params.x * (1 - 1 / (param2 * circleDistance + 1));
}
return result;
}
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
float2 offset = Center.xy - input.TexCoord;
float centerDistance = length(offset);
float2 sampleDelta =
0.5 * (normalize(offset) * max(0, GetCircleParam(centerDistance, Params.z, Params.y) -
GetCircleParam(centerDistance, Center.z, Params.w)));
float4 color = 0;
for (float sampleIndex = -NUM_STEPS; sampleIndex <= NUM_STEPS; ++sampleIndex) {
float2 texCoord = input.TexCoord + sampleDelta * sampleIndex;
float2 adjustedTexCoord = FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(texCoord);
float4 currentColor = ImageTex.SampleLevel(ImageSampler, adjustedTexCoord, 0);
color += currentColor;
}
color *= (1. / (2. * NUM_STEPS + 1.));
psout.Color = color;
return psout;
}
#endif