78 lines
2.1 KiB
GLSL
78 lines
2.1 KiB
GLSL
#version 450
|
|
#extension GL_KHR_vulkan_glsl : enable
|
|
|
|
//#include "ShaderDescriptorDefinitions.glsl"
|
|
|
|
|
|
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;
|
|
layout(location = 8) in uvec2 integerData;
|
|
layout(location = 9) in uvec4 aBoneIndices;
|
|
layout(location = 10) in vec4 aBoneWeights;
|
|
layout(location = 11) in uint firstBoneIndex;
|
|
|
|
layout(location = 0) out struct
|
|
{
|
|
vec4 vertPos; // location 0
|
|
vec2 uv; // location = 1
|
|
vec4 normal; // location = 2
|
|
vec4 worldPos; // location = 3
|
|
} Out;
|
|
|
|
// material stuff
|
|
layout(location = 4) out struct
|
|
{
|
|
int materialIndex;
|
|
uint eid;
|
|
uint lightLayerIndex;
|
|
|
|
} Out2;
|
|
|
|
layout(set = 1, binding = 0) uniform CameraData
|
|
{
|
|
vec4 position;
|
|
mat4 vpMat;
|
|
mat4 viewMat;
|
|
mat4 projMat;
|
|
} cameraData;
|
|
|
|
layout (std430, set = 2, binding = 1) buffer AnimBoneMatrices
|
|
{
|
|
mat4 data[];
|
|
} BoneMatrices;
|
|
|
|
void main()
|
|
{
|
|
Out2.materialIndex = gl_InstanceIndex;
|
|
Out2.eid = integerData[0];
|
|
Out2.lightLayerIndex = integerData[1];
|
|
|
|
// 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);
|
|
|
|
Out.worldPos = worldTransform * vec4 (aVertexPos, 1.0f);
|
|
|
|
// uvs for texturing in fragment shader
|
|
Out.uv = aUV;
|
|
|
|
mat3 transposeInv = mat3 (transpose(inverse(modelViewMat)));
|
|
|
|
// normals are also in view space
|
|
Out.normal.rgb = transposeInv * aNormal.rgb;
|
|
Out.normal.rgb = normalize (Out.normal.rgb);
|
|
|
|
// Compute bone matrix
|
|
mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0];
|
|
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[1]] * aBoneWeights[1];
|
|
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[2]] * aBoneWeights[2];
|
|
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[3]] * aBoneWeights[3];
|
|
|
|
// clip space for rendering
|
|
gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f);
|
|
} |