1617a3babSopenharmony_ci/*
2617a3babSopenharmony_ciThe MIT License (MIT)
3617a3babSopenharmony_ci
4617a3babSopenharmony_ciCopyright (c) 2022 Google LLC
5617a3babSopenharmony_ciCopyright (c) 2022 Sascha Willems
6617a3babSopenharmony_ci
7617a3babSopenharmony_ciPermission is hereby granted, free of charge, to any person obtaining a copy
8617a3babSopenharmony_ciof this software and associated documentation files (the "Software"), to deal
9617a3babSopenharmony_ciin the Software without restriction, including without limitation the rights
10617a3babSopenharmony_cito use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11617a3babSopenharmony_cicopies of the Software, and to permit persons to whom the Software is
12617a3babSopenharmony_cifurnished to do so, subject to the following conditions:
13617a3babSopenharmony_ci
14617a3babSopenharmony_ciThe above copyright notice and this permission notice shall be included in all
15617a3babSopenharmony_cicopies or substantial portions of the Software.
16617a3babSopenharmony_ci
17617a3babSopenharmony_ciTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18617a3babSopenharmony_ciIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19617a3babSopenharmony_ciFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20617a3babSopenharmony_ciAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21617a3babSopenharmony_ciLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22617a3babSopenharmony_ciOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23617a3babSopenharmony_ciSOFTWARE.
24617a3babSopenharmony_ci*/
25617a3babSopenharmony_ci
26617a3babSopenharmony_cistruct UBO
27617a3babSopenharmony_ci{
28617a3babSopenharmony_ci	float4x4 projection[2];
29617a3babSopenharmony_ci	float4x4 modelview[2];
30617a3babSopenharmony_ci	float4 lightPos;
31617a3babSopenharmony_ci};
32617a3babSopenharmony_ci
33617a3babSopenharmony_cicbuffer ubo : register(b0) { UBO ubo; }
34617a3babSopenharmony_ci
35617a3babSopenharmony_cistruct VSOutput
36617a3babSopenharmony_ci{
37617a3babSopenharmony_ci	float4 Pos : SV_POSITION;
38617a3babSopenharmony_ci[[vk::location(0)]] float3 Normal : NORMAL0;
39617a3babSopenharmony_ci[[vk::location(1)]] float3 Color : COLOR0;
40617a3babSopenharmony_ci};
41617a3babSopenharmony_ci
42617a3babSopenharmony_cistruct GSOutput
43617a3babSopenharmony_ci{
44617a3babSopenharmony_ci	float4 Pos : SV_POSITION;
45617a3babSopenharmony_ci	uint ViewportIndex : SV_ViewportArrayIndex;
46617a3babSopenharmony_ci	uint PrimitiveID : SV_PrimitiveID;
47617a3babSopenharmony_ci[[vk::location(0)]] float3 Normal : NORMAL0;
48617a3babSopenharmony_ci[[vk::location(1)]] float3 Color : COLOR0;
49617a3babSopenharmony_ci[[vk::location(2)]] float3 ViewVec : TEXCOOR1;
50617a3babSopenharmony_ci[[vk::location(3)]] float3 LightVec : TEXCOOR2;
51617a3babSopenharmony_ci};
52617a3babSopenharmony_ci
53617a3babSopenharmony_ci[maxvertexcount(3)]
54617a3babSopenharmony_ci[instance(2)]
55617a3babSopenharmony_civoid main(triangle VSOutput input[3], inout TriangleStream<GSOutput> outStream, uint InvocationID : SV_GSInstanceID, uint PrimitiveID : SV_PrimitiveID)
56617a3babSopenharmony_ci{
57617a3babSopenharmony_ci	for(int i = 0; i < 3; i++)
58617a3babSopenharmony_ci	{
59617a3babSopenharmony_ci		GSOutput output = (GSOutput)0;
60617a3babSopenharmony_ci		output.Normal = mul((float3x3)ubo.modelview[InvocationID], input[i].Normal);
61617a3babSopenharmony_ci		output.Color = input[i].Color;
62617a3babSopenharmony_ci
63617a3babSopenharmony_ci		float4 pos = input[i].Pos;
64617a3babSopenharmony_ci		float4 worldPos = mul(ubo.modelview[InvocationID], pos);
65617a3babSopenharmony_ci
66617a3babSopenharmony_ci		float3 lPos = mul(ubo.modelview[InvocationID], ubo.lightPos).xyz;
67617a3babSopenharmony_ci		output.LightVec = lPos - worldPos.xyz;
68617a3babSopenharmony_ci		output.ViewVec = -worldPos.xyz;
69617a3babSopenharmony_ci
70617a3babSopenharmony_ci		output.Pos = mul(ubo.projection[InvocationID], worldPos);
71617a3babSopenharmony_ci
72617a3babSopenharmony_ci		// Set the viewport index that the vertex will be emitted to
73617a3babSopenharmony_ci		output.ViewportIndex = InvocationID;
74617a3babSopenharmony_ci      	output.PrimitiveID = PrimitiveID;
75617a3babSopenharmony_ci		outStream.Append( output );
76617a3babSopenharmony_ci	}
77617a3babSopenharmony_ci
78617a3babSopenharmony_ci	outStream.RestartStrip();
79617a3babSopenharmony_ci}
80