114 lines
3.3 KiB
GLSL
114 lines
3.3 KiB
GLSL
#ifndef MAX_BONES
|
|
#define MAX_BONES 110
|
|
#endif
|
|
uniform mat3x4 vsBoneMatrix[MAX_BONES];
|
|
uniform bool SKINNED = false;
|
|
|
|
uniform mat4 VP;
|
|
|
|
#if 0
|
|
|
|
for (size_t di = 0; di < mesh->blend_deformers.count; di++) {
|
|
ufbx_blend_deformer *deformer = mesh->blend_deformers.data[di];
|
|
for (size_t ci = 0; ci < deformer->channels.count; ci++) {
|
|
ufbx_blend_channel *chan = deformer->channels.data[ci];
|
|
if (chan->keyframes.count == 0) continue;
|
|
if (num_blend_shapes < MAX_BLEND_SHAPES) {
|
|
blend_channels[num_blend_shapes] = chan;
|
|
vmesh->blend_channel_indices[num_blend_shapes] = (int32_t)chan->typed_id;
|
|
num_blend_shapes++;
|
|
}
|
|
}
|
|
}
|
|
if (num_blend_shapes > 0) {
|
|
vmesh->blend_shape_image = pack_blend_channels_to_image(mesh, blend_channels, num_blend_shapes);
|
|
vmesh->num_blend_shapes = num_blend_shapes;
|
|
}
|
|
|
|
ubo.f_num_blend_shapes = (float)mesh->num_blend_shapes;
|
|
for (size_t i = 0; i < mesh->num_blend_shapes; i++) {
|
|
ubo.blend_weights[i] = view->scene.blend_channels[mesh->blend_channel_indices[i]].weight;
|
|
}
|
|
|
|
sg_image blend_shapes = mesh->num_blend_shapes > 0 ? mesh->blend_shape_image : view->empty_blend_shape_image;
|
|
#endif
|
|
|
|
|
|
#ifndef MAX_BLENDSHAPES
|
|
#define MAX_BLENDSHAPES 16
|
|
#endif
|
|
uniform vec4 blend_weights[MAX_BLENDSHAPES];
|
|
uniform float f_num_blend_shapes;
|
|
uniform sampler2DArray blend_shapes;
|
|
|
|
in vec3 att_position;
|
|
in vec2 att_texcoord;
|
|
in vec3 att_normal;
|
|
in vec4 att_tangent;
|
|
in mat4 att_instanced_matrix;
|
|
in vec4 att_indexes;
|
|
in vec4 att_weights;
|
|
in float att_vertexindex;
|
|
in vec4 att_color;
|
|
in vec3 att_bitangent;
|
|
out vec4 v_color;
|
|
out vec3 v_position;
|
|
out vec3 v_normal, v_normal_ws;
|
|
out vec2 v_texcoord;
|
|
|
|
|
|
|
|
uniform mat4 model, view;
|
|
uniform mat4 cameraToShadowProjector;
|
|
out vec4 vneye;
|
|
out vec4 vpeye;
|
|
out vec4 sc;
|
|
void do_shadow() {
|
|
vneye = view * model * vec4(att_normal, 0.0f);
|
|
vpeye = view * model * vec4(att_position, 1.0);
|
|
sc = cameraToShadowProjector * model * vec4(att_position, 1.0f);
|
|
}
|
|
|
|
|
|
vec3 evaluate_blend_shape(int vertex_index) {
|
|
ivec2 coord = ivec2(vertex_index & (2048 - 1), vertex_index >> 11);
|
|
int num_blend_shapes = int(f_num_blend_shapes);
|
|
vec3 offset = vec3(0.0);
|
|
for (int i = 0; i < num_blend_shapes; i++) {
|
|
vec4 packedw = blend_weights[i >> 2];
|
|
float weight = packedw[i & 3];
|
|
offset += weight * texelFetch(blend_shapes, ivec3(coord, i), 0).xyz;
|
|
}
|
|
return offset;
|
|
}
|
|
|
|
void main() {
|
|
vec3 objPos;
|
|
if(!SKINNED) {
|
|
objPos = att_position;
|
|
v_normal = att_normal;
|
|
} else {
|
|
mat3x4 m = vsBoneMatrix[int(att_indexes.x)] * att_weights.x;
|
|
m += vsBoneMatrix[int(att_indexes.y)] * att_weights.y;
|
|
m += vsBoneMatrix[int(att_indexes.z)] * att_weights.z;
|
|
m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w;
|
|
objPos = vec4(att_position, 1.0) * m;
|
|
|
|
|
|
|
|
|
|
v_normal = vec4(att_normal, 0.0) * m;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v_normal_ws = normalize(vec3(model * vec4(v_normal, 0.)));
|
|
v_normal = normalize(v_normal);
|
|
v_position = att_position;
|
|
v_texcoord = att_texcoord;
|
|
v_color = att_color;
|
|
gl_Position = VP * att_instanced_matrix * vec4( objPos, 1.0 );
|
|
do_shadow();
|
|
} |