#version 450 layout (set = 0, binding = 0) uniform UniformBufferObject { mat4 proj; mat4 view; vec3 camPos; float pad; } ubo; layout (push_constant) uniform PushConstant { mat4 model; vec4 color; } constant; #ifdef BONE layout (set = 2, binding = 0) uniform UniformBufferBone { mat4 trans[256]; } bone; #endif #ifdef BONE layout(location = 0) in vec3 inPosition; layout(location = 1) in vec2 inUV0; layout(location = 2) in vec2 inUV1; layout(location = 3) in vec3 inNormal; layout(location = 4) in vec3 inTangent; layout(location = 5) in vec3 boneWeight; layout(location = 6) in uvec4 boneIndex; layout(location = 7) in vec4 inColor; #else layout(location = 0) in vec3 inPosition; layout(location = 1) in vec2 inUV0; layout(location = 2) in vec2 inUV1; layout(location = 3) in vec3 inNormal; layout(location = 4) in vec3 inTangent; layout(location = 5) in vec4 inColor; #endif layout (location = 0) out vec3 outPosition; layout (location = 1) out vec3 outNormal; layout (location = 2) out vec2 outUV0; layout (location = 3) out vec2 outUV1; layout (location = 4) out vec4 outColor; layout (location = 5) out vec3 outViewPos; void main() { #ifdef BONE vec4 weights; weights.x = boneWeight.x; weights.y = boneWeight.y; weights.z = boneWeight.z; weights.w = 1.0 - weights.x - weights.y - weights.z; vec3 posL = vec3(0, 0, 0); vec3 normalL = vec3(0, 0, 0); posL = weights[0] * (bone.trans[boneIndex[0]] * vec4(inPosition,1)).xyz + weights[1] * (bone.trans[boneIndex[1]] * vec4(inPosition,1)).xyz + weights[2] * (bone.trans[boneIndex[2]] * vec4(inPosition,1)).xyz + weights[3] * (bone.trans[boneIndex[3]] * vec4(inPosition,1)).xyz; normalL = weights[0] * mat3(bone.trans[boneIndex[0]]) * inNormal + weights[1] * mat3(bone.trans[boneIndex[1]]) * inNormal + weights[2] * mat3(bone.trans[boneIndex[2]]) * inNormal + weights[3] * mat3(bone.trans[boneIndex[3]]) * inNormal; #else vec3 posL = inPosition; vec3 normalL = inNormal; #endif vec4 worldPos = constant.model * vec4(posL, 1.0); mat3 normalMat = transpose(inverse(mat3(constant.model))); vec3 worldNormal = normalize(normalMat * normalL); vec4 viewPos = ubo.view * worldPos; // 相机空间位置 outPosition = worldPos.xyz; outNormal = worldNormal; outUV0 = inUV0; outUV1 = inUV1; outColor = inColor * constant.color; outViewPos = viewPos.xyz; gl_Position = ubo.proj * ubo.view * worldPos; }