From a3912f1cf39ec16fccf16d607407ad30f7e420ea Mon Sep 17 00:00:00 2001 From: shadowisLORD Date: Mon, 27 May 2013 21:29:35 +0000 Subject: [PATCH] * Fixed bug where verts uninfluenced by bones would not work correctly in hardware skinning git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10633 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../core-data/Common/ShaderLib/Skinning.glsllib | 72 ++++++++++++---------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/engine/src/core-data/Common/ShaderLib/Skinning.glsllib b/engine/src/core-data/Common/ShaderLib/Skinning.glsllib index 6452b34b0..399e9e3fb 100644 --- a/engine/src/core-data/Common/ShaderLib/Skinning.glsllib +++ b/engine/src/core-data/Common/ShaderLib/Skinning.glsllib @@ -11,56 +11,62 @@ attribute vec4 inBoneIndex; uniform mat4 m_BoneMatrices[NUM_BONES]; void Skinning_Compute(inout vec4 position){ + if (inBoneWeight.x != 0.0) { #if NUM_WEIGHTS_PER_VERT == 1 - position = m_BoneMatrices[int(inBoneIndex.x)] * position; + position = m_BoneMatrices[int(inBoneIndex.x)] * position; #else - mat4 mat = mat4(0.0); - mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x; - mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y; - mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z; - mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w; - position = mat * position; + mat4 mat = mat4(0.0); + mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x; + mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y; + mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z; + mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w; + position = mat * position; #endif + } } void Skinning_Compute(inout vec4 position, inout vec3 normal){ + if (inBoneWeight.x != 0.0) { #if NUM_WEIGHTS_PER_VERT == 1 - position = m_BoneMatrices[int(inBoneIndex.x)] * position; - normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz, - m_BoneMatrices[int(inBoneIndex.x)][1].xyz, - m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal); + position = m_BoneMatrices[int(inBoneIndex.x)] * position; + normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz, + m_BoneMatrices[int(inBoneIndex.x)][1].xyz, + m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal); #else - mat4 mat = mat4(0.0); - mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x; - mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y; - mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z; - mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w; - position = mat * position; + mat4 mat = mat4(0.0); + mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x; + mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y; + mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z; + mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w; + position = mat * position; - mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz); - normal = rotMat * normal; + mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz); + normal = rotMat * normal; #endif + } } void Skinning_Compute(inout vec4 position, inout vec3 tangent, inout vec3 normal){ + if (inBoneWeight.x != 0.0) { #if NUM_WEIGHTS_PER_VERT == 1 - position = m_BoneMatrices[int(inBoneIndex.x)] * position; - tangent = m_BoneMatrices[int(inBoneIndex.x)] * tangent; - normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz, - m_BoneMatrices[int(inBoneIndex.x)][1].xyz, - m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal); + position = m_BoneMatrices[int(inBoneIndex.x)] * position; + tangent = m_BoneMatrices[int(inBoneIndex.x)] * tangent; + normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz, + m_BoneMatrices[int(inBoneIndex.x)][1].xyz, + m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal); #else - mat4 mat = mat4(0.0); - mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x; - mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y; - mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z; - mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w; - position = mat * position; + mat4 mat = mat4(0.0); + mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x; + mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y; + mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z; + mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w; + position = mat * position; - mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz); - tangent = rotMat * tangent; - normal = rotMat * normal; + mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz); + tangent = rotMat * tangent; + normal = rotMat * normal; #endif + } } #endif \ No newline at end of file -- 2.11.0