forked from doodlum/skyrim-community-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISBlur.hlsl
74 lines (61 loc) · 1.73 KB
/
ISBlur.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Common/Color.hlsli"
#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);
SamplerState AvgLumSampler : register(s1);
Texture2D<float4> ImageTex : register(t0);
Texture2D<float4> AvgLumTex : register(t1);
cbuffer PerGeometry : register(b2)
{
float4 BlurBrightPass : packoffset(c0);
float4 BlurScale : packoffset(c1);
float BlurRadius : packoffset(c2);
float4 BlurOffsets[16] : packoffset(c3);
};
float4 GetImageColor(float2 texCoord, float blurScale)
{
return ImageTex.Sample(ImageSampler, texCoord) * float4(blurScale.xxx, 1);
}
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
float4 color = 0;
# if defined(TEXTAP)
int blurRadius = TEXTAP;
# else
uint blurRadius = asuint(BlurRadius);
# endif
float2 blurScale = BlurScale.zw;
# if !defined(TEXTAP) || !defined(COLORRANGE)
blurScale = 1;
# endif
for (int blurIndex = 0; blurIndex < blurRadius; ++blurIndex) {
float2 screenPosition = BlurOffsets[blurIndex].xy + input.TexCoord.xy;
float4 imageColor = 0;
[branch] if (BlurScale.x < 0.5)
{
imageColor = GetImageColor(FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(screenPosition), blurScale.y);
}
else
{
imageColor = GetImageColor(screenPosition, blurScale.y);
}
# if defined(BRIGHTPASS)
imageColor = BlurBrightPass.y * max(0, -BlurBrightPass.x + imageColor);
# endif
color += imageColor * BlurOffsets[blurIndex].z;
}
# if defined(BRIGHTPASS)
float avgLum = Color::RGBToLuminance(AvgLumTex.Sample(AvgLumSampler, input.TexCoord.xy).xyz);
color.w = avgLum;
# endif
psout.Color = color * float4(blurScale.xxx, 1);
return psout;
}
#endif