1
+ #version 450
2
+
3
+ //
4
+ // Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
5
+ //
6
+ // This code is released under an unmodified zlib license.
7
+ // For conditions of distribution and use, please see:
8
+ // https://opensource.org/licenses/Zlib
9
+ //
10
+
11
+ // Per instance data
12
+ layout (location = 0 ) in vec3 inPosition;
13
+ layout (location = 1 ) in vec3 inScale;
14
+ layout (location = 2 ) in vec4 inColour;
15
+ layout (location = 3 ) in vec4 inUv;
16
+
17
+ layout (location = 0 ) out vec4 outColour;
18
+ layout (location = 1 ) out vec2 outUv;
19
+ layout (location = 2 ) out flat uint outTexId;
20
+
21
+ layout (push_constant) uniform PushConstant {
22
+ uint textureIndex;
23
+ } pushConstant;
24
+
25
+ vec3 quadVertices[4 ] = {
26
+ vec3 (1.0 , 1.0 , 0 ),
27
+ vec3 (1.0 , - 1.0 , 0 ),
28
+ vec3 (- 1.0 , - 1.0 , 0 ),
29
+ vec3 (- 1.0 , 1.0 , 0 )
30
+ };
31
+
32
+ struct CameraData
33
+ {
34
+ mat4 projectionMatrix;
35
+ mat4 viewMatrix;
36
+ };
37
+
38
+ layout (binding = 0 ) uniform GlobalData {
39
+ CameraData cameraData;
40
+ } globalData;
41
+
42
+ CameraData camera = globalData.cameraData;
43
+
44
+ void main() {
45
+ vec4 quadInCameraSpace = camera.viewMatrix * vec4 (inPosition, 1.0 );
46
+
47
+ vec4 positionInCameraSpace = quadInCameraSpace + vec4 (quadVertices[gl_VertexIndex].xy * (inScale.xy * 0.5 ), 0.0 , 0.0 );
48
+
49
+ gl_Position = camera.projectionMatrix * positionInCameraSpace;
50
+
51
+ float uvx = (float (gl_VertexIndex == 0 || gl_VertexIndex == 1 ) * (inUv.x + inUv.z))
52
+ + (float (gl_VertexIndex == 2 || gl_VertexIndex == 3 ) * (inUv.x));
53
+ float uvy = (float (gl_VertexIndex == 0 || gl_VertexIndex == 3 ) * (inUv.y + inUv.w))
54
+ + (float (gl_VertexIndex == 1 || gl_VertexIndex == 2 ) * (inUv.y));
55
+
56
+ outColour = inColour;
57
+ outUv = vec2 (uvx, uvy);
58
+ outTexId = pushConstant.textureIndex;
59
+ }
0 commit comments