diff --git a/data/shaders/instanced_skinning.vert b/data/shaders/instanced_skinning.vert index 69aa38ecd..391bfcda9 100644 --- a/data/shaders/instanced_skinning.vert +++ b/data/shaders/instanced_skinning.vert @@ -37,43 +37,19 @@ void main(void) { mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale); mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix); - vec4 idle_position = vec4(Position, 1.); vec4 idle_normal = vec4(Normal, 0.); vec4 skinned_position = vec4(0.); vec4 skinned_normal = vec4(0.); - // Note : For normal we assume no scale factor in bone (otherwise we'll have to compute inversematrix for each bones...) - vec4 single_bone_influenced_position; - vec4 single_bone_influenced_normal; - - // First bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[0] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[0] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[0] * single_bone_influenced_position; - skinned_normal += Weight[0] * single_bone_influenced_normal; - - // Second bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[1] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[1] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[1] * single_bone_influenced_position; - skinned_normal += Weight[1] * single_bone_influenced_normal; - - // Third bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[2] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[2] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[2] * single_bone_influenced_position; - skinned_normal += Weight[2] * single_bone_influenced_normal; - - // Fourth bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[3] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[3] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[3] * single_bone_influenced_position; - skinned_normal += Weight[3] * single_bone_influenced_normal; + for (int i = 0; i < 4; i++) + { + vec4 single_bone_influenced_position = joint_matrices[clamp(Joint[i] + skinning_offset, 0, MAX_BONES)] * idle_position; + single_bone_influenced_position /= single_bone_influenced_position.w; + vec4 single_bone_influenced_normal = joint_matrices[clamp(Joint[i] + skinning_offset, 0, MAX_BONES)] * idle_normal; + skinned_position += Weight[i] * single_bone_influenced_position; + skinned_normal += Weight[i] * single_bone_influenced_normal; + } gl_Position = ProjectionViewMatrix * ModelMatrix * skinned_position; // Keep orthogonality diff --git a/data/shaders/instanced_skinning_shadow.vert b/data/shaders/instanced_skinning_shadow.vert index 359980dc1..2d2542e1e 100644 --- a/data/shaders/instanced_skinning_shadow.vert +++ b/data/shaders/instanced_skinning_shadow.vert @@ -32,27 +32,12 @@ void main(void) mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale); vec4 idle_position = vec4(Position, 1.); vec4 skinned_position = vec4(0.); - vec4 single_bone_influenced_position; - - // First bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[0] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - skinned_position += Weight[0] * single_bone_influenced_position; - - // Second bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[1] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - skinned_position += Weight[1] * single_bone_influenced_position; - - // Third bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[2] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - skinned_position += Weight[2] * single_bone_influenced_position; - - // Fourth bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[3] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - skinned_position += Weight[3] * single_bone_influenced_position; + for (int i = 0; i < 4; i++) + { + vec4 single_bone_influenced_position = joint_matrices[clamp(Joint[i] + skinning_offset, 0, MAX_BONES)] * idle_position; + single_bone_influenced_position /= single_bone_influenced_position.w; + skinned_position += Weight[i] * single_bone_influenced_position; + } #ifdef VSLayer gl_Layer = layer; diff --git a/data/shaders/skinning.vert b/data/shaders/skinning.vert index 25718a9cc..d4a0d65e8 100644 --- a/data/shaders/skinning.vert +++ b/data/shaders/skinning.vert @@ -41,38 +41,15 @@ void main(void) vec4 idle_normal = vec4(Normal, 0.); vec4 skinned_position = vec4(0.); vec4 skinned_normal = vec4(0.); - // Note : For normal we assume no scale factor in bone (otherwise we'll have to compute inversematrix for each bones...) - vec4 single_bone_influenced_position; - vec4 single_bone_influenced_normal; - - // First bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[0] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[0] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[0] * single_bone_influenced_position; - skinned_normal += Weight[0] * single_bone_influenced_normal; - - // Second bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[1] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[1] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[1] * single_bone_influenced_position; - skinned_normal += Weight[1] * single_bone_influenced_normal; - - // Third bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[2] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[2] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[2] * single_bone_influenced_position; - skinned_normal += Weight[2] * single_bone_influenced_normal; - - // Fourth bone: - single_bone_influenced_position = joint_matrices[clamp(Joint[3] + skinning_offset, 0, MAX_BONES)] * idle_position; - single_bone_influenced_position /= single_bone_influenced_position.w; - single_bone_influenced_normal = joint_matrices[clamp(Joint[3] + skinning_offset, 0, MAX_BONES)] * idle_normal; - skinned_position += Weight[3] * single_bone_influenced_position; - skinned_normal += Weight[3] * single_bone_influenced_normal; + for (int i = 0; i < 4; i++) + { + vec4 single_bone_influenced_position = joint_matrices[clamp(Joint[i] + skinning_offset, 0, MAX_BONES)] * idle_position; + single_bone_influenced_position /= single_bone_influenced_position.w; + vec4 single_bone_influenced_normal = joint_matrices[clamp(Joint[i] + skinning_offset, 0, MAX_BONES)] * idle_normal; + skinned_position += Weight[i] * single_bone_influenced_position; + skinned_normal += Weight[i] * single_bone_influenced_normal; + } gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * skinned_position; // Keep orthogonality