xref: /aosp_15_r20/external/angle/third_party/glslang/src/Test/spv.debuginfo.glsl.vert (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1/*
2The MIT License (MIT)
3
4Copyright (c) 2022 Sascha Willems
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#version 450
26
27// Vertex attributes
28layout (location = 0) in vec3 inPos;
29layout (location = 1) in vec3 inNormal;
30layout (location = 2) in vec2 inUV;
31layout (location = 3) in vec3 inColor;
32
33// Instanced attributes
34layout (location = 4) in vec3 instancePos;
35layout (location = 5) in vec3 instanceRot;
36layout (location = 6) in float instanceScale;
37layout (location = 7) in int instanceTexIndex;
38
39layout (binding = 0) uniform UBO
40{
41	mat4 projection;
42	mat4 modelview;
43	vec4 lightPos;
44	float locSpeed;
45	float globSpeed;
46} ubo;
47
48layout (location = 0) out vec3 outNormal;
49layout (location = 1) out vec3 outColor;
50layout (location = 2) out vec3 outUV;
51layout (location = 3) out vec3 outViewVec;
52layout (location = 4) out vec3 outLightVec;
53
54void main()
55{
56	outColor = inColor;
57	outUV = vec3(inUV, instanceTexIndex);
58
59	mat3 mx, my, mz;
60
61	// rotate around x
62	float s = sin(instanceRot.x + ubo.locSpeed);
63	float c = cos(instanceRot.x + ubo.locSpeed);
64
65	mx[0] = vec3(c, s, 0.0);
66	mx[1] = vec3(-s, c, 0.0);
67	mx[2] = vec3(0.0, 0.0, 1.0);
68
69	// rotate around y
70	s = sin(instanceRot.y + ubo.locSpeed);
71	c = cos(instanceRot.y + ubo.locSpeed);
72
73	my[0] = vec3(c, 0.0, s);
74	my[1] = vec3(0.0, 1.0, 0.0);
75	my[2] = vec3(-s, 0.0, c);
76
77	// rot around z
78	s = sin(instanceRot.z + ubo.locSpeed);
79	c = cos(instanceRot.z + ubo.locSpeed);
80
81	mz[0] = vec3(1.0, 0.0, 0.0);
82	mz[1] = vec3(0.0, c, s);
83	mz[2] = vec3(0.0, -s, c);
84
85	mat3 rotMat = mz * my * mx;
86
87	mat4 gRotMat;
88	s = sin(instanceRot.y + ubo.globSpeed);
89	c = cos(instanceRot.y + ubo.globSpeed);
90	gRotMat[0] = vec4(c, 0.0, s, 0.0);
91	gRotMat[1] = vec4(0.0, 1.0, 0.0, 0.0);
92	gRotMat[2] = vec4(-s, 0.0, c, 0.0);
93	gRotMat[3] = vec4(0.0, 0.0, 0.0, 1.0);
94
95	vec4 locPos = vec4(inPos.xyz * rotMat, 1.0);
96	vec4 pos = vec4((locPos.xyz * instanceScale) + instancePos, 1.0);
97
98	gl_Position = ubo.projection * ubo.modelview * gRotMat * pos;
99	outNormal = mat3(ubo.modelview * gRotMat) * inverse(rotMat) * inNormal;
100
101	pos = ubo.modelview * vec4(inPos.xyz + instancePos, 1.0);
102	vec3 lPos = mat3(ubo.modelview) * ubo.lightPos.xyz;
103	outLightVec = lPos - pos.xyz;
104	outViewVec = -pos.xyz;
105}
106