2022-09-19 00:00:07 +08:00
|
|
|
#version 450
|
|
|
|
#extension GL_KHR_vulkan_glsl : enable
|
|
|
|
|
2022-09-22 12:12:44 +08:00
|
|
|
//#include "ShaderDescriptorDefinitions.glsl"
|
|
|
|
|
2022-10-26 01:08:02 +08:00
|
|
|
|
2022-09-19 00:00:07 +08:00
|
|
|
layout(location = 0) in vec3 aVertexPos;
|
|
|
|
layout(location = 1) in vec2 aUV;
|
|
|
|
layout(location = 2) in vec3 aNormal;
|
|
|
|
layout(location = 3) in vec3 aTangent;
|
|
|
|
layout(location = 4) in mat4 worldTransform;
|
2022-10-26 01:08:02 +08:00
|
|
|
layout(location = 8) in uvec2 integerData;
|
2023-01-04 17:42:02 +08:00
|
|
|
layout(location = 9) in uvec4 aBoneIndices;
|
|
|
|
layout(location = 10) in vec4 aBoneWeights;
|
2023-01-30 14:57:46 +08:00
|
|
|
layout(location = 11) in uint firstBoneIndex;
|
2022-09-19 00:00:07 +08:00
|
|
|
|
|
|
|
layout(location = 0) out struct
|
|
|
|
{
|
2022-10-30 00:25:49 +08:00
|
|
|
vec4 vertPos; // location 0
|
2022-09-28 18:03:46 +08:00
|
|
|
vec2 uv; // location = 1
|
2022-10-30 00:25:49 +08:00
|
|
|
vec4 normal; // location = 2
|
2023-01-11 08:25:38 +08:00
|
|
|
vec4 worldPos; // location = 3
|
2023-03-06 00:02:06 +08:00
|
|
|
vec3 worldNormal; // location = 4
|
2022-09-19 00:00:07 +08:00
|
|
|
|
|
|
|
} Out;
|
|
|
|
|
2022-09-28 18:03:46 +08:00
|
|
|
// material stuff
|
2023-03-06 00:02:06 +08:00
|
|
|
layout(location = 5) out struct
|
2022-09-28 18:03:46 +08:00
|
|
|
{
|
|
|
|
int materialIndex;
|
2022-10-14 11:52:15 +08:00
|
|
|
uint eid;
|
2022-10-26 02:14:43 +08:00
|
|
|
uint lightLayerIndex;
|
2022-10-14 11:52:15 +08:00
|
|
|
|
2022-09-28 18:03:46 +08:00
|
|
|
} Out2;
|
|
|
|
|
2022-12-28 20:47:20 +08:00
|
|
|
layout(set = 1, binding = 0) uniform CameraData
|
2022-09-22 12:12:44 +08:00
|
|
|
{
|
|
|
|
vec4 position;
|
|
|
|
mat4 vpMat;
|
2022-10-30 16:35:55 +08:00
|
|
|
mat4 viewMat;
|
2022-12-28 10:22:01 +08:00
|
|
|
mat4 projMat;
|
2022-09-22 12:12:44 +08:00
|
|
|
} cameraData;
|
|
|
|
|
2022-09-19 00:00:07 +08:00
|
|
|
void main()
|
|
|
|
{
|
2022-09-28 18:03:46 +08:00
|
|
|
Out2.materialIndex = gl_InstanceIndex;
|
2022-10-26 02:14:43 +08:00
|
|
|
Out2.eid = integerData[0];
|
|
|
|
Out2.lightLayerIndex = integerData[1];
|
2022-10-30 00:25:49 +08:00
|
|
|
|
2022-10-30 16:52:40 +08:00
|
|
|
// for transforming gBuffer position and normal data
|
|
|
|
mat4 modelViewMat = cameraData.viewMat * worldTransform;
|
|
|
|
|
|
|
|
// gBuffer position will be in view space
|
|
|
|
Out.vertPos = modelViewMat * vec4(aVertexPos, 1.0f);
|
|
|
|
|
2023-01-11 08:25:38 +08:00
|
|
|
Out.worldPos = worldTransform * vec4 (aVertexPos, 1.0f);
|
|
|
|
|
2022-10-30 16:52:40 +08:00
|
|
|
// uvs for texturing in fragment shader
|
2022-10-30 00:25:49 +08:00
|
|
|
Out.uv = aUV;
|
2022-10-30 16:52:40 +08:00
|
|
|
|
2023-03-06 00:02:06 +08:00
|
|
|
mat3 mvTransInv = mat3 (transpose(inverse(modelViewMat)));
|
|
|
|
mat3 modelTransInv = mat3 (transpose(inverse(worldTransform)));
|
2022-10-31 20:49:28 +08:00
|
|
|
|
2022-10-30 16:52:40 +08:00
|
|
|
// normals are also in view space
|
2023-03-06 00:02:06 +08:00
|
|
|
Out.normal.rgb = mvTransInv * aNormal.rgb;
|
2022-10-30 00:25:49 +08:00
|
|
|
Out.normal.rgb = normalize (Out.normal.rgb);
|
2023-03-06 00:02:06 +08:00
|
|
|
Out.worldNormal = normalize (modelTransInv * aNormal);
|
2022-10-30 16:52:40 +08:00
|
|
|
|
|
|
|
// clip space for rendering
|
2022-09-22 20:53:03 +08:00
|
|
|
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f);
|
2022-09-19 00:00:07 +08:00
|
|
|
}
|