-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDecalsPS.hlsl
59 lines (48 loc) · 1.46 KB
/
DecalsPS.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 "GBufferCommon.hlsli"
struct GBufferOut
{
float4 graphicsBuffer0 : SV_Target0;
float4 graphicsBuffer1 : SV_Target1;
float4 graphicsBuffer2 : SV_Target2;
};
SamplerState g_TextureSampler : register(s0);
Texture2D<float4> g_MultiTexture0 : register(t0);
Texture2D<float4> g_MultiTexture1 : register(t1);
Texture2D<float4> g_MultiTexture2 : register(t2);
Texture2D<float> g_DepthBuffer : register(t5);
float3 samplePosition(float2 tex)
{
float4 position = float4(
tex.x * ( 2) - 1,
tex.y * (-2) + 1,
g_DepthBuffer.Sample(g_TextureSampler, tex),
1.0f
);
position = mul(inverseProjection, position);
position = mul(inverseView, position);
position = mul(inverseWorld, position);
return position.xyz / position.w;
}
GBufferOut main(VSOut input)
{
GBufferOut output;
float2 screenPos = input.position.xy / float2(width, height);
float3 cubePos = samplePosition(screenPos);
float3 checkPos = abs(cubePos);
if (checkPos.x < 1 &&
checkPos.y < 1 &&
checkPos.z < 1)
{
output.graphicsBuffer0 = g_MultiTexture0.Sample(g_TextureSampler, 0.5f+cubePos.xy*0.5f);
output.graphicsBuffer1 = g_MultiTexture1.Sample(g_TextureSampler, 0.5f+cubePos.xy*0.5f);
output.graphicsBuffer2 = g_MultiTexture2.Sample(g_TextureSampler, 0.5f+cubePos.xy*0.5f);
output.graphicsBuffer0 *= colorize;
}
else
{
output.graphicsBuffer0 = float4(0, 0, 0, 0);
output.graphicsBuffer1 = float4(0, 0, 0, 0);
output.graphicsBuffer2 = float4(0, 0, 0, 0);
}
return output;
}