Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / avatar / src / main / rust / shaders / yuu_avatar.vert
yuu_avatar.vert42 lines · 1.5 KiBRaw
| 1 | #version 450 |
| 2 | // Skinned Yuu avatar vertex shader: 4-bone linear-blend skinning against the |
| 3 | // bone-matrix UBO, then the shared view-projection. Matches YuuVkVertex |
| 4 | // locations 0..4 in vulkan/buffers.rs. |
| 5 | // |
| 6 | // NOTE(Mali): joints arrive as vec4, NOT uvec4 — the Mali SPIR-V frontend |
| 7 | // SIGSEGVs parsing integer vertex inputs (fault inside vkCreateGraphics- |
| 8 | // Pipelines, uncatchable). int() conversion at index time is exact for our |
| 9 | // small joint ids. |
| 10 | layout(location = 0) in vec3 inPos; |
| 11 | layout(location = 1) in vec3 inNormal; |
| 12 | layout(location = 2) in vec2 inUv; |
| 13 | layout(location = 3) in vec4 inJoints; |
| 14 | layout(location = 4) in vec4 inWeights; |
| 15 | |
| 16 | layout(location = 0) out vec3 vNormal; |
| 17 | layout(location = 1) out vec2 vUv; |
| 18 | layout(location = 2) out vec3 vWorld; |
| 19 | |
| 20 | layout(set = 0, binding = 0) uniform Ubo { |
| 21 | mat4 viewProj; |
| 22 | vec3 sunDir; |
| 23 | vec3 camPos; |
| 24 | mat4 bones[32]; |
| 25 | } ubo; |
| 26 | |
| 27 | void main() { |
| 28 | mat4 skin = |
| 29 | inWeights.x * ubo.bones[int(inJoints.x)] + |
| 30 | inWeights.y * ubo.bones[int(inJoints.y)] + |
| 31 | inWeights.z * ubo.bones[int(inJoints.z)] + |
| 32 | inWeights.w * ubo.bones[int(inJoints.w)]; |
| 33 | vec4 world = skin * vec4(inPos, 1.0); |
| 34 | vWorld = world.xyz; |
| 35 | vNormal = normalize(mat3(skin) * inNormal); |
| 36 | vUv = inUv; |
| 37 | vec4 clip = ubo.viewProj * world; |
| 38 | // Vulkan Y flip: NDC Y points down, and the flip inverts winding (hence |
| 39 | // CULL_NONE in the pipeline) — same arrangement as games/voxels and kart. |
| 40 | clip.y = -clip.y; |
| 41 | gl_Position = clip; |
| 42 | } |