Files
dl/shader/csm.vert
T
2026-09-16 14:07:40 +08:00

68 lines
1.7 KiB
GLSL

#version 450
// 级联级数,创建管线时可覆盖
layout(constant_id = 0) const int SHADOW_MAP_CASCADE_COUNT = 4;
#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 (push_constant) uniform PushConstant
{
mat4 model;
uint cascadeIndex;
} constant;
#ifdef BONE
layout (set = 2, binding = 0) uniform UniformBufferBone
{
mat4 trans[256];
} bone;
#endif
// 注意与标准的位置不一样
layout (set = 0, binding = 0) uniform UniformBufferCascade
{
mat4 viewProj[SHADOW_MAP_CASCADE_COUNT];
} cascade;
layout (location = 0) out vec2 outUV;
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);
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;
#else
vec3 posL = inPosition;
#endif
outUV = inUV0;
vec4 pos = constant.model * vec4(posL, 1.0);
gl_Position = cascade.viewProj[constant.cascadeIndex] * pos;
}