-
Notifications
You must be signed in to change notification settings - Fork 4
/
GBufferPass.hlsl
79 lines (61 loc) · 1.51 KB
/
GBufferPass.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
75
76
77
78
79
struct VSInput
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD;
};
struct PSInput
{
float3 normal : NORMAL;
float2 uv : TEXCOORD;
float4 position : SV_POSITION;
};
cbuffer GPrepassCB : register(b0)
{
float4x4 ViewProjection;
float MipBias;
float3 pad;
};
cbuffer perModelInstanceCB : register(b1)
{
float4x4 World;
float AlbedoID;
float NormalID;
float Roughness;
float Metalness;
float2 UVscale;
float2 NormalScale;
};
Texture2D<float4> Textures[] : register(t0);
SamplerState SamplerLinear : register(s0);
PSInput VSMain(VSInput input)
{
PSInput result;
result.position = mul(World, float4(input.position.xyz, 1));
result.position = mul(ViewProjection, result.position);
result.normal = mul((float3x3)World, input.normal.xyz);
result.uv = input.uv;
return result;
}
struct PSOutput
{
float4 colour : SV_Target0;
float4 normal : SV_Target1;
};
PSOutput PSMain(PSInput input)
{
PSOutput output = (PSOutput)0;
float3 n = 0;
if (NormalID >= 0)
{
n = Textures[NormalID].SampleBias(SamplerLinear, UVscale * input.uv, MipBias).rgb * 2 - 1;
}
float3 normal = normalize(input.normal.xyz + float3(NormalScale * n.xy, 0));
float4 albedo = Textures[AlbedoID].SampleBias(SamplerLinear, UVscale * input.uv, MipBias).rgba;
clip(albedo.a - 0.5f);
output.colour.rgb = albedo;
output.colour.a = Metalness;
output.normal.xyz = normal;
output.normal.w = Roughness;
return output;
}