xref: /aosp_15_r20/external/angle/third_party/glslang/src/Test/spv.debuginfo.hlsl.tese (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1/*
2The MIT License (MIT)
3
4Copyright (c) 2022 Google LLC
5Copyright (c) 2022 Sascha Willems
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24*/
25
26struct UBO
27{
28	float4x4 projection;
29	float4x4 modelview;
30	float4 lightPos;
31	float4 frustumPlanes[6];
32	float displacementFactor;
33	float tessellationFactor;
34	float2 viewportDim;
35	float tessellatedEdgeSize;
36};
37cbuffer ubo : register(b0) { UBO ubo; };
38
39Texture2D displacementMapTexture : register(t1);
40SamplerState displacementMapSampler : register(s1);
41
42struct HSOutput
43{
44[[vk::location(2)]]	float4 Pos : SV_POSITION;
45[[vk::location(0)]] float3 Normal : NORMAL0;
46[[vk::location(1)]] float2 UV : TEXCOORD0;
47};
48
49struct ConstantsHSOutput
50{
51    float TessLevelOuter[4] : SV_TessFactor;
52    float TessLevelInner[2] : SV_InsideTessFactor;
53};
54
55struct DSOutput
56{
57	float4 Pos : SV_POSITION;
58[[vk::location(0)]] float3 Normal : NORMAL0;
59[[vk::location(1)]] float2 UV : TEXCOORD0;
60[[vk::location(2)]] float3 ViewVec : TEXCOORD1;
61[[vk::location(3)]] float3 LightVec : TEXCOORD2;
62[[vk::location(4)]] float3 EyePos : POSITION1;
63[[vk::location(5)]] float3 WorldPos : POSITION0;
64};
65
66[domain("quad")]
67DSOutput main(ConstantsHSOutput input, float2 TessCoord : SV_DomainLocation, const OutputPatch<HSOutput, 4> patch)
68{
69	// Interpolate UV coordinates
70	DSOutput output = (DSOutput)0;
71	float2 uv1 = lerp(patch[0].UV, patch[1].UV, TessCoord.x);
72	float2 uv2 = lerp(patch[3].UV, patch[2].UV, TessCoord.x);
73	output.UV = lerp(uv1, uv2, TessCoord.y);
74
75	float3 n1 = lerp(patch[0].Normal, patch[1].Normal, TessCoord.x);
76	float3 n2 = lerp(patch[3].Normal, patch[2].Normal, TessCoord.x);
77	output.Normal = lerp(n1, n2, TessCoord.y);
78
79	// Interpolate positions
80	float4 pos1 = lerp(patch[0].Pos, patch[1].Pos, TessCoord.x);
81	float4 pos2 = lerp(patch[3].Pos, patch[2].Pos, TessCoord.x);
82	float4 pos = lerp(pos1, pos2, TessCoord.y);
83	// Displace
84	pos.y -= displacementMapTexture.SampleLevel(displacementMapSampler, output.UV, 0.0).r * ubo.displacementFactor;
85	// Perspective projection
86	output.Pos = mul(ubo.projection, mul(ubo.modelview, pos));
87
88	// Calculate vectors for lighting based on tessellated position
89	output.ViewVec = -pos.xyz;
90	output.LightVec = normalize(ubo.lightPos.xyz + output.ViewVec);
91	output.WorldPos = pos.xyz;
92	output.EyePos = mul(ubo.modelview, pos).xyz;
93	return output;
94}
95