-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDemo.hlsl
205 lines (168 loc) · 5.33 KB
/
Demo.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//=================================================================================================
#if PS_0 || VS_1
#include "Common.h"
#endif // #if PS_0 || VS_1
//=================================================================================================
#if VS_0 || PS_0
#define RSI_0 "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
"DescriptorTable(UAV(u0), visibility = SHADER_VISIBILITY_PIXEL)"
struct VERTEX_OUTPUT
{
float4 position : SV_Position;
float3 normalized_coords : NCOORDS;
float3 color : COLOR;
};
#endif // #if VS_0 || PS_0
//-------------------------------------------------------------------------------------------------
#if VS_0
struct VERTEX_INPUT
{
float3 position : POSITION;
float3 color : COLOR;
};
[RootSignature(RSI_0)]
VERTEX_OUTPUT
VS0_Main(VERTEX_INPUT input)
{
VERTEX_OUTPUT output;
output.normalized_coords = input.position;
output.color = input.color;
output.position = float4(input.position, 1.0f);
return output;
}
#endif // #if VS_0
//-------------------------------------------------------------------------------------------------
#if PS_0
RWStructuredBuffer<FRAGMENT> uav_fragments : register(u0);
[earlydepthstencil]
[RootSignature(RSI_0)]
float4
PS0_Main(VERTEX_OUTPUT input) : SV_Target0
{
uint index = uav_fragments.IncrementCounter();
uav_fragments[index].position = input.normalized_coords;
float f = WaveGetLaneIndex() / (float)WaveGetLaneCount();
bool all_active = WaveActiveCountBits(WaveActiveBallot(true).x) == WaveGetLaneCount();
bool first = WaveIsFirstLane();
if (first)
{
uav_fragments[index].color = float3(1.0f, 1.0f, 0.5f + 0.5f * f);
}
else if (all_active)
{
uav_fragments[index].color = float3(0.0f, 0.5f + 0.5f * f, 0.0f);
}
else
{
uav_fragments[index].color = float3(0.5f + 0.5f * f, 0.0f, 0.0f);
}
return float4(0.0f, 0.5f, 0.0f, 1.0f);
}
#endif // #if PS_0
//=================================================================================================
#if VS_1 || PS_1
#define RSI_1 "RootFlags(0), " \
"DescriptorTable(SRV(t0), visibility = SHADER_VISIBILITY_VERTEX)"
struct VERTEX_OUTPUT
{
float4 position : SV_Position;
float3 color : COLOR;
};
#endif // #if VS_1 || PS_1
//-------------------------------------------------------------------------------------------------
#if VS_1
StructuredBuffer<FRAGMENT> srv_fragments : register(t0);
[RootSignature(RSI_1)]
VERTEX_OUTPUT
VS1_Main(uint vertex_id : SV_VertexID)
{
FRAGMENT frag = srv_fragments[vertex_id];
VERTEX_OUTPUT output;
output.position = float4(frag.position.xy, 0.0f, 1.0f);
output.color = frag.color;
return output;
}
#endif // #if VS_1
//-------------------------------------------------------------------------------------------------
#if PS_1
[RootSignature(RSI_1)]
float4
PS1_Main(VERTEX_OUTPUT input) : SV_Target0
{
return float4(input.color, 1.0);
}
#endif // #if PS_1
//=================================================================================================
#if VS_2 || PS_2
#define RSI_2 "RootFlags(0), " \
"DescriptorTable(SRV(t0), visibility = SHADER_VISIBILITY_PIXEL), " \
"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_POINT, visibility = SHADER_VISIBILITY_PIXEL)"
struct VERTEX_OUTPUT
{
float4 position : SV_Position;
float2 texcoord : TEXCOORD;
};
#endif // #if VS_2 || PS_2
//-------------------------------------------------------------------------------------------------
#if VS_2
[RootSignature(RSI_2)]
VERTEX_OUTPUT
VS2_Main(uint vertex_id : SV_VertexID)
{
float2 positions[3] = { float2(-1.0f, -1.0f), float2(-1.0f, 3.0f), float2(3.0f, -1.0f) };
float2 texcoords[3] = { float2(0.0f, 2.0f), float2(0.0f, 0.0f), float2(2.0f, 2.0f) };
VERTEX_OUTPUT output;
output.position = float4(positions[vertex_id], 0.0f, 1.0f);
output.texcoord = texcoords[vertex_id];
return output;
}
#endif // #if VS_2
//-------------------------------------------------------------------------------------------------
#if PS_2
Texture2D srv_t0 : register(t0);
SamplerState sam_s0 : register(s0);
[RootSignature(RSI_2)]
float4
PS2_Main(VERTEX_OUTPUT input) : SV_Target0
{
return srv_t0.Sample(sam_s0, input.texcoord);
}
#endif // #if PS_2
//=================================================================================================
#if VS_3 || PS_3
#define RSI_3 "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT)"
struct VERTEX_OUTPUT
{
float4 position : SV_Position;
float3 normalized_coords : NCOORDS;
float3 color : COLOR;
};
#endif // #if VS_3 || PS_3
//-------------------------------------------------------------------------------------------------
#if VS_3
struct VERTEX_INPUT
{
float3 position : POSITION;
float3 color : COLOR;
};
[RootSignature(RSI_3)]
VERTEX_OUTPUT
VS3_Main(VERTEX_INPUT input)
{
VERTEX_OUTPUT output;
output.normalized_coords = input.position;
output.color = input.color;
output.position = float4(input.position, 1.0f);
return output;
}
#endif // #if VS_3
//-------------------------------------------------------------------------------------------------
#if PS_3
[RootSignature(RSI_3)]
float4
PS3_Main(VERTEX_OUTPUT input) : SV_Target0
{
return float4(input.color, 1.0);
}
#endif // #if PS_1
//=================================================================================================