Files
dl_old/shader/shader.vert
T
2024-12-31 02:33:01 +08:00

59 lines
1.3 KiB
GLSL

#version 450
layout (binding = 0) uniform UniformBufferObject
{
mat4 viewProj;
} ubo;
layout (push_constant) uniform PushConstant
{
mat4 model;
vec3 color;
} constant;
#ifdef BONE
layout (set = 1, binding = 0) uniform UniformBufferBone
{
mat4 trans[96];
} bone;
#endif
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inTexCoord;
layout(location = 3) in vec3 inTangent;
#ifdef BONE
layout(location = 4) in vec4 boneWeight;
layout(location = 5) in uvec4 boneIndex;
layout(location = 6) in vec2 inTexCoord1;
layout(location = 7) in vec4 inColor;
#endif
layout(location = 0) out vec3 fragColor;
layout(location = 1) out vec2 fragTexCoord;
void main()
{
#ifdef BONE
vec3 posL = vec3(0, 0, 0);
vec3 normalL = vec3(0, 0, 0);
vec3 tangentL = vec3(0, 0, 0);
for(int i = 0; i < 4; ++i)
{
posL += boneWeight[i] * (bone.trans[boneIndex[i]] * vec4(inPosition, 1.0)).xyz;
normalL += boneWeight[i] * (mat3(bone.trans[boneIndex[i]]) * inNormal);
tangentL += boneWeight[i] * (mat3(bone.trans[boneIndex[i]]) * inTangent);
}
//inPosition = posL;
//inNormal = normalL;
//inTangent = tangentL;
#else
vec3 posL = inPosition;
#endif
gl_Position = ubo.viewProj * constant.model * vec4(posL, 1.0);
fragColor = constant.color;
fragTexCoord = inTexCoord;
}