提交 308d0aee 编写于 作者: I Ian Kerr

This commit fixes a skinning bug that occurs when two or more SkinnedMesh...

This commit fixes a skinning bug that occurs when two or more SkinnedMesh objects share a common material and have bone textures of different sizes.  Currently, bone texture sizes are hard coded into the shader program, requiring the program to be re-built when the bone texture size changes; however, the current implementation does not handle this correctly, which can lead to the shader accessing incorrect bone transforms.

This commit uses two uniforms to store the bone texture dimensions.  These uniforms are updated as needed, eliminating the need to re-build the shader and fixing the bug.
上级 eafdc4d3
......@@ -4381,8 +4381,6 @@ THREE.WebGLRenderer = function ( parameters ) {
skinning: material.skinning,
maxBones: maxBones,
useVertexTexture: _supportsBoneTextures && object && object.useVertexTexture,
boneTextureWidth: object && object.boneTextureWidth,
boneTextureHeight: object && object.boneTextureHeight,
morphTargets: material.morphTargets,
morphNormals: material.morphNormals,
......@@ -4541,6 +4539,18 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( p_uniforms.boneTextureWidth !== null ) {
_gl.uniform1i( p_uniforms.boneTextureWidth, object.boneTextureWidth );
}
if ( p_uniforms.boneTextureHeight !== null ) {
_gl.uniform1i( p_uniforms.boneTextureHeight, object.boneTextureHeight );
}
} else {
if ( p_uniforms.boneGlobalMatrices !== null ) {
......@@ -5755,8 +5765,6 @@ THREE.WebGLRenderer = function ( parameters ) {
parameters.skinning ? "#define USE_SKINNING" : "",
parameters.useVertexTexture ? "#define BONE_TEXTURE" : "",
parameters.boneTextureWidth ? "#define N_BONE_PIXEL_X " + parameters.boneTextureWidth.toFixed( 1 ) : "",
parameters.boneTextureHeight ? "#define N_BONE_PIXEL_Y " + parameters.boneTextureHeight.toFixed( 1 ) : "",
parameters.morphTargets ? "#define USE_MORPHTARGETS" : "",
parameters.morphNormals ? "#define USE_MORPHNORMALS" : "",
......@@ -5922,6 +5930,8 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( parameters.useVertexTexture ) {
identifiers.push( 'boneTexture' );
identifiers.push( 'boneTextureWidth' );
identifiers.push( 'boneTextureHeight' );
} else {
......
......@@ -1251,15 +1251,17 @@ THREE.ShaderChunk = {
"#ifdef BONE_TEXTURE",
"uniform sampler2D boneTexture;",
"uniform int boneTextureWidth;",
"uniform int boneTextureHeight;",
"mat4 getBoneMatrix( const in float i ) {",
"float j = i * 4.0;",
"float x = mod( j, N_BONE_PIXEL_X );",
"float y = floor( j / N_BONE_PIXEL_X );",
"float x = mod( j, float( boneTextureWidth ) );",
"float y = floor( j / float( boneTextureWidth ) );",
"const float dx = 1.0 / N_BONE_PIXEL_X;",
"const float dy = 1.0 / N_BONE_PIXEL_Y;",
"const float dx = 1.0 / float( boneTextureWidth );",
"const float dy = 1.0 / float( boneTextureHeight );",
"y = dy * ( y + 0.5 );",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册