-
Notifications
You must be signed in to change notification settings - Fork 14
/
triangles.hlsl
77 lines (64 loc) · 1.4 KB
/
triangles.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
struct VS_INPUT
{
uint VertexID : SV_VertexID;
};
struct VS_OUTPUT
{
float4 Position : SV_Position;
float4 Color : COLOR;
#if NUM_EXTRA_FLOATs > 0
float ExtraFloats[NUM_EXTRA_FLOATs] : EXTRAFLOATS;
#endif
};
struct PS_OUTPUT
{
float4 Color : SV_Target;
};
RWStructuredBuffer<uint> PixelCounterUAV : register(u1);
cbuffer MaxNumPixelsCBV : register(b0) { uint MaxNumPixels; };
VS_OUTPUT VSmain(VS_INPUT input)
{
VS_OUTPUT output;
if (input.VertexID % 3 == 0)
output.Position = float4(-1, 1, 0, 1);
else if (input.VertexID % 3 == 1)
output.Position = float4(1, 1, 0, 1);
else if (input.VertexID % 3 == 2)
output.Position = float4(-1, -1, 0, 1);
const float4 colors[7] = {
float4(1,0,0,1),
float4(0,1,0,1),
float4(0,0,1,1),
float4(1,1,0,1),
float4(0,1,1,1),
float4(1,0,1,1),
float4(1,1,1,1)
};
output.Color = colors[(input.VertexID / 3) % 7] * float4(0.4,0.4,0.4,1);
#if NUM_EXTRA_FLOATs > 0
[unroll]
for (int i = 0; i < NUM_EXTRA_FLOATs; i++)
{
output.ExtraFloats[i] = input.VertexID + i;
}
#endif
return output;
}
PS_OUTPUT PSmain(VS_OUTPUT input)
{
if (PixelCounterUAV.IncrementCounter() > MaxNumPixels)
{
discard;
}
PS_OUTPUT output;
output.Color = input.Color;
// just to force it not to optimize this out
#if NUM_EXTRA_FLOATs > 0
[unroll]
for (int i = 0; i < NUM_EXTRA_FLOATs; i++)
{
output.Color.r += input.ExtraFloats[i] * 0.00001;
}
#endif
return output;
}