-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathISWorldMap.hlsl
59 lines (47 loc) · 1.48 KB
/
ISWorldMap.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
#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 DepthSampler : register(s1);
Texture2D<float4> ImageTex : register(t0);
Texture2D<float4> DepthTex : register(t1);
cbuffer PerGeometry : register(b2)
{
float4 CameraParams : packoffset(c0);
float4 DepthParams : packoffset(c1);
float4 TexelSize : packoffset(c2);
};
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
float2 adjustedTexCoord = FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(input.TexCoord);
float depth = DepthTex.Sample(DepthSampler, adjustedTexCoord).x;
float depthFactor = DepthParams.w / ((1 - depth) * DepthParams.z + DepthParams.y);
float offsetDelta = min(TexelSize.y, TexelSize.z * abs(depthFactor - TexelSize.x));
# if defined(NO_SKY)
if (1 - depth <= 1e-4) {
offsetDelta = 0;
}
# endif
if (depthFactor < TexelSize.x) {
offsetDelta *= TexelSize.w;
}
float2 startOffset = input.TexCoord - 3 * (CameraParams.xy * offsetDelta);
float4 color = 0;
for (int i = 0; i < 7; ++i) {
for (int j = 0; j < 7; ++j) {
float2 currentTexCoord = FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(
startOffset + CameraParams.xy * offsetDelta * float2(i, j));
float4 currentColor = ImageTex.Sample(ImageSampler, currentTexCoord);
color += currentColor;
}
}
psout.Color = 0.0204081628 * color;
return psout;
}
#endif