mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-29 18:38:04 +03:00
Before this, the BoneTransforms uniform block consumed (4 * 4 * sizeof(float) * MAX_BONES) = 19712 bytes, which exceeds 16384, the minimum possible value of GL_MAX_UNIFORM_BLOCK_SIZE in OpenGL ES 3.2. Since the bone matrices are affine, we can drop the 4th rows and pack them into a mat4x3 array. Now the BoneTransforms block is 14784 bytes and it should work with all OpenGL ES 3.2 implementations.
49 lines
1.5 KiB
GLSL
49 lines
1.5 KiB
GLSL
/* Copyright (C) 2022 kichikuou <KichikuouChrome@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, see <http://gnu.org/licenses/>.
|
|
*/
|
|
|
|
uniform mat4 local_transform;
|
|
uniform mat4 view_transform;
|
|
|
|
const int MAX_BONES = 308; // see 3d_internal.h
|
|
const int NR_WEIGHTS = 4;
|
|
uniform bool has_bones;
|
|
layout(std140, row_major) uniform BoneTransforms {
|
|
mat4x3 bone_matrices[MAX_BONES];
|
|
};
|
|
|
|
in vec3 vertex_pos;
|
|
in ivec4 vertex_bone_index;
|
|
in vec4 vertex_bone_weight;
|
|
|
|
void main() {
|
|
mat4 local_bone_transform = local_transform;
|
|
if (has_bones) {
|
|
mat4x3 bone_transform = mat4x3(0.0);
|
|
for (int i = 0; i < NR_WEIGHTS; i++) {
|
|
if (vertex_bone_index[i] >= 0) {
|
|
bone_transform += bone_matrices[vertex_bone_index[i]] * vertex_bone_weight[i];
|
|
}
|
|
}
|
|
local_bone_transform *= mat4(
|
|
vec4(bone_transform[0], 0.0),
|
|
vec4(bone_transform[1], 0.0),
|
|
vec4(bone_transform[2], 0.0),
|
|
vec4(bone_transform[3], 1.0));
|
|
}
|
|
|
|
gl_Position = view_transform * local_bone_transform * vec4(vertex_pos, 1.0);
|
|
}
|