77# original triangle, so the result is validated against the same golden image.
88
99#--- vertex.hlsl
10- struct VSOutput
11- {
12- float4 position : POSITION;
10+ struct VSOutput {
11+ float4 position : POSITION;
1312};
1413
15- VSOutput main(float4 position : POSITION)
16- {
17- VSOutput o;
18- o.position = position;
19- return o;
14+ VSOutput main(float4 position : POSITION) {
15+ VSOutput o;
16+ o.position = position;
17+ return o;
2018}
2119
2220#--- hull.hlsl
23- struct HSInput
24- {
25- float4 position : POSITION;
21+ struct HSInput {
22+ float4 position : POSITION;
2623};
2724
28- struct HSOutput
29- {
30- float4 position : POSITION;
25+ struct HSOutput {
26+ float4 position : POSITION;
3127};
3228
33- struct HSPatchConstants
34- {
35- float Edges[4] : SV_TessFactor;
36- float Inside[2] : SV_InsideTessFactor;
29+ struct HSPatchConstants {
30+ float Edges[4] : SV_TessFactor;
31+ float Inside[2] : SV_InsideTessFactor;
3732};
3833
3934// A quad domain with every factor at 1 produces exactly four domain vertices
4035// (the quad corners) and no interior points. With the "point" output topology
4136// below, the tessellator hands the Geometry stage four point primitives -- one
4237// slot per sub-triangle of the midpoint subdivision.
4338HSPatchConstants PatchConstants(InputPatch<HSInput, 1> patch,
44- uint patchID : SV_PrimitiveID)
45- {
46- HSPatchConstants c;
47- c.Edges[0] = 1.0;
48- c.Edges[1] = 1.0;
49- c.Edges[2] = 1.0;
50- c.Edges[3] = 1.0;
51- c.Inside[0] = 1.0;
52- c.Inside[1] = 1.0;
53- return c;
39+ uint patchID : SV_PrimitiveID) {
40+ HSPatchConstants c;
41+ c.Edges[0] = 1.0;
42+ c.Edges[1] = 1.0;
43+ c.Edges[2] = 1.0;
44+ c.Edges[3] = 1.0;
45+ c.Inside[0] = 1.0;
46+ c.Inside[1] = 1.0;
47+ return c;
5448}
5549
5650[domain("quad")]
5751[partitioning("integer")]
5852[outputtopology("point")]
5953[outputcontrolpoints(1)]
6054[patchconstantfunc("PatchConstants")]
61- HSOutput main(InputPatch<HSInput, 1> patch,
62- uint i : SV_OutputControlPointID)
63- {
64- HSOutput o;
65- o.position = patch[i].position;
66- return o;
55+ HSOutput main(InputPatch<HSInput, 1> patch, uint i : SV_OutputControlPointID) {
56+ HSOutput o;
57+ o.position = patch[i].position;
58+ return o;
6759}
6860
6961#--- domain.hlsl
70- struct DSInput
71- {
72- float4 position : POSITION;
62+ struct DSInput {
63+ float4 position : POSITION;
7364};
7465
75- struct DSPatchConstants
76- {
77- float Edges[4] : SV_TessFactor;
78- float Inside[2] : SV_InsideTessFactor;
66+ struct DSPatchConstants {
67+ float Edges[4] : SV_TessFactor;
68+ float Inside[2] : SV_InsideTessFactor;
7969};
8070
81- struct DSOutput
82- {
83- float4 position : SV_POSITION; // the sub-triangle centroid
84- float2 bigCenter : BIGCENTER; // big triangle centroid, forwarded
85- nointerpolation uint subTri : SUBTRI; // which sub-triangle (0..3)
71+ struct DSOutput {
72+ float4 position : SV_POSITION; // the sub-triangle centroid
73+ float2 bigCenter : BIGCENTER; // big triangle centroid, forwarded
74+ nointerpolation uint subTri : SUBTRI; // which sub-triangle (0..3)
8675};
8776
8877// Classify each of the four tessellated points (at quad-domain corners
@@ -91,43 +80,42 @@ struct DSOutput
9180// central (inverted) one sits at G. The Geometry stage expands each centroid
9281// back into a full sub-triangle.
9382[domain("quad")]
94- DSOutput main(DSPatchConstants constants,
95- float2 uv : SV_DomainLocation,
96- const OutputPatch<DSInput, 1> patch)
97- {
98- float2 g = patch[0].position.xy;
99-
100- // Big triangle corner offsets from its centroid (SimpleTriangle layout).
101- const float2 d0 = float2( 0.0, 0.33333333);
102- const float2 d1 = float2( 0.25, -0.16666667);
103- const float2 d2 = float2(-0.25, -0.16666667);
104-
105- uint id = (uv.x > 0.5 ? 1u : 0u) + (uv.y > 0.5 ? 2u : 0u);
106-
107- float2 sc = g; // central sub-triangle centroid == big centroid
108- if (id == 0) sc = g + 0.5 * d0;
109- else if (id == 1) sc = g + 0.5 * d1;
110- else if (id == 2) sc = g + 0.5 * d2;
111-
112- DSOutput o;
113- o.position = float4(sc, 0.0, 1.0);
114- o.bigCenter = g;
115- o.subTri = id;
116- return o;
83+ DSOutput main(DSPatchConstants constants, float2 uv : SV_DomainLocation,
84+ const OutputPatch<DSInput, 1> patch) {
85+ float2 g = patch[0].position.xy;
86+
87+ // Big triangle corner offsets from its centroid (SimpleTriangle layout).
88+ const float2 d0 = float2(0.0, 0.33333333);
89+ const float2 d1 = float2(0.25, -0.16666667);
90+ const float2 d2 = float2(-0.25, -0.16666667);
91+
92+ uint id = (uv.x > 0.5 ? 1u : 0u) + (uv.y > 0.5 ? 2u : 0u);
93+
94+ float2 sc = g; // central sub-triangle centroid == big centroid
95+ if (id == 0)
96+ sc = g + 0.5 * d0;
97+ else if (id == 1)
98+ sc = g + 0.5 * d1;
99+ else if (id == 2)
100+ sc = g + 0.5 * d2;
101+
102+ DSOutput o;
103+ o.position = float4(sc, 0.0, 1.0);
104+ o.bigCenter = g;
105+ o.subTri = id;
106+ return o;
117107}
118108
119109#--- geometry.hlsl
120- struct GSInput
121- {
122- float4 position : SV_POSITION;
123- float2 bigCenter : BIGCENTER;
124- nointerpolation uint subTri : SUBTRI;
110+ struct GSInput {
111+ float4 position : SV_POSITION;
112+ float2 bigCenter : BIGCENTER;
113+ nointerpolation uint subTri : SUBTRI;
125114};
126115
127- struct GSOutput
128- {
129- float4 position : SV_POSITION;
130- float4 color : COLOR;
116+ struct GSOutput {
117+ float4 position : SV_POSITION;
118+ float4 color : COLOR;
131119};
132120
133121// Expand one sub-triangle centroid into its three corners. The midpoint
@@ -137,51 +125,77 @@ struct GSOutput
137125// (corners = R/G/B, edge midpoints = their averages), so the reassembled image
138126// reproduces SimpleTriangle's gradient pixel-for-pixel.
139127[maxvertexcount(3)]
140- void main(point GSInput input[1], inout TriangleStream<GSOutput> stream)
141- {
142- float2 g = input[0].bigCenter;
143- uint id = input[0].subTri;
144-
145- const float2 d0 = float2( 0.0, 0.33333333);
146- const float2 d1 = float2( 0.25, -0.16666667);
147- const float2 d2 = float2(-0.25, -0.16666667);
148-
149- float2 V0 = g + d0, V1 = g + d1, V2 = g + d2;
150- float2 M01 = 0.5 * (V0 + V1);
151- float2 M12 = 0.5 * (V1 + V2);
152- float2 M02 = 0.5 * (V0 + V2);
153-
154- const float3 cR = float3(1.0, 0.0, 0.0);
155- const float3 cG = float3(0.0, 1.0, 0.0);
156- const float3 cB = float3(0.0, 0.0, 1.0);
157- const float3 cM01 = float3(0.5, 0.5, 0.0);
158- const float3 cM12 = float3(0.0, 0.5, 0.5);
159- const float3 cM02 = float3(0.5, 0.0, 0.5);
160-
161- float2 p0, p1, p2;
162- float3 q0, q1, q2;
163- if (id == 0) { p0 = V0; q0 = cR; p1 = M01; q1 = cM01; p2 = M02; q2 = cM02; }
164- else if (id == 1) { p0 = M01; q0 = cM01; p1 = V1; q1 = cG; p2 = M12; q2 = cM12; }
165- else if (id == 2) { p0 = M02; q0 = cM02; p1 = M12; q1 = cM12; p2 = V2; q2 = cB; }
166- else { p0 = M01; q0 = cM01; p1 = M12; q1 = cM12; p2 = M02; q2 = cM02; }
167-
168- GSOutput o;
169- o.position = float4(p0, 0.0, 1.0); o.color = float4(q0, 1.0); stream.Append(o);
170- o.position = float4(p1, 0.0, 1.0); o.color = float4(q1, 1.0); stream.Append(o);
171- o.position = float4(p2, 0.0, 1.0); o.color = float4(q2, 1.0); stream.Append(o);
128+ void main(point GSInput input[1], inout TriangleStream<GSOutput> stream) {
129+ float2 g = input[0].bigCenter;
130+ uint id = input[0].subTri;
131+
132+ const float2 d0 = float2(0.0, 0.33333333);
133+ const float2 d1 = float2(0.25, -0.16666667);
134+ const float2 d2 = float2(-0.25, -0.16666667);
135+
136+ float2 V0 = g + d0, V1 = g + d1, V2 = g + d2;
137+ float2 M01 = 0.5 * (V0 + V1);
138+ float2 M12 = 0.5 * (V1 + V2);
139+ float2 M02 = 0.5 * (V0 + V2);
140+
141+ const float3 cR = float3(1.0, 0.0, 0.0);
142+ const float3 cG = float3(0.0, 1.0, 0.0);
143+ const float3 cB = float3(0.0, 0.0, 1.0);
144+ const float3 cM01 = float3(0.5, 0.5, 0.0);
145+ const float3 cM12 = float3(0.0, 0.5, 0.5);
146+ const float3 cM02 = float3(0.5, 0.0, 0.5);
147+
148+ float2 p0, p1, p2;
149+ float3 q0, q1, q2;
150+ if (id == 0) {
151+ p0 = V0;
152+ q0 = cR;
153+ p1 = M01;
154+ q1 = cM01;
155+ p2 = M02;
156+ q2 = cM02;
157+ } else if (id == 1) {
158+ p0 = M01;
159+ q0 = cM01;
160+ p1 = V1;
161+ q1 = cG;
162+ p2 = M12;
163+ q2 = cM12;
164+ } else if (id == 2) {
165+ p0 = M02;
166+ q0 = cM02;
167+ p1 = M12;
168+ q1 = cM12;
169+ p2 = V2;
170+ q2 = cB;
171+ } else {
172+ p0 = M01;
173+ q0 = cM01;
174+ p1 = M12;
175+ q1 = cM12;
176+ p2 = M02;
177+ q2 = cM02;
178+ }
179+
180+ GSOutput o;
181+ o.position = float4(p0, 0.0, 1.0);
182+ o.color = float4(q0, 1.0);
183+ stream.Append(o);
184+ o.position = float4(p1, 0.0, 1.0);
185+ o.color = float4(q1, 1.0);
186+ stream.Append(o);
187+ o.position = float4(p2, 0.0, 1.0);
188+ o.color = float4(q2, 1.0);
189+ stream.Append(o);
172190}
173191
174192#--- pixel.hlsl
175- struct PSInput
176- {
177- float4 position : SV_POSITION;
178- float4 color : COLOR;
193+ struct PSInput {
194+ float4 position : SV_POSITION;
195+ float4 color : COLOR;
179196};
180197
181- float4 main(PSInput input) : SV_TARGET
182- {
183- return input.color;
184- }
198+ float4 main(PSInput input) : SV_TARGET { return input.color; }
185199
186200#--- pipeline.yaml
187201---
0 commit comments