From d9ecfee15fcf47504680ec4661db3c5f17033e36 Mon Sep 17 00:00:00 2001 From: pissang Date: Wed, 28 Mar 2018 22:29:32 +0800 Subject: [PATCH] Fix skin matrices texture affect other textures bug. Release 1.1.3 --- example/app_gbuffer.html | 6 +++++- example/app_model.html | 2 +- example/deferred_skinning.html | 12 ++++++------ package.json | 2 +- src/Renderer.js | 12 +++++++----- src/version.js | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/example/app_gbuffer.html b/example/app_gbuffer.html index 50dc04421..eced10703 100644 --- a/example/app_gbuffer.html +++ b/example/app_gbuffer.html @@ -41,7 +41,11 @@ this._camera = app.createCamera([0, 150, 200], [0, 100, 0]); // Load boombox model. - app.loadModel('./assets/models/SambaDancing/SambaDancing.gltf'); + app.loadModel('./assets/models/SambaDancing/SambaDancing.gltf').then(function (result) { + result.materials.forEach(function (mat) { + mat.set('metalness', 1); + }); + }); // Create light app.createDirectionalLight([-1, -1, -1]); diff --git a/example/app_model.html b/example/app_model.html index 85b75c4da..d2d577721 100644 --- a/example/app_model.html +++ b/example/app_model.html @@ -31,7 +31,7 @@ }); // Load boombox model. return a load promise to make sure the look will be start after model loaded. - return app.loadModel('./assets/models/BoomBox/BoomBox.gltf', { + app.loadModel('./assets/models/BoomBox/BoomBox.gltf', { waitTextureLoaded: true }).then(function (result) { result.rootNode.scale.set(100, 100, 100); diff --git a/example/deferred_skinning.html b/example/deferred_skinning.html index 02a27a370..daa2626eb 100644 --- a/example/deferred_skinning.html +++ b/example/deferred_skinning.html @@ -120,17 +120,17 @@ timeline.start(); timeline.addClip(clip); - var skeletonDebugScene = createSkeletonDebugScene(skeleton, clay); - skeletonDebugScene.position.x = -10; + // var skeletonDebugScene = createSkeletonDebugScene(skeleton, clay); + // skeletonDebugScene.position.x = -10; timeline.on('frame', function() { control.update(50); skeleton.update(); deferredRenderer.render(renderer, scene, camera); - renderer.saveClear(); - renderer.clearBit = renderer.gl.DEPTH_BUFFER_BIT; - renderer.render(skeletonDebugScene, camera); - renderer.restoreClear(); + // renderer.saveClear(); + // renderer.clearBit = renderer.gl.DEPTH_BUFFER_BIT; + // renderer.render(skeletonDebugScene, camera); + // renderer.restoreClear(); }); }); diff --git a/package.json b/package.json index e13bbc830..f1830166a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "claygl", - "version": "1.1.2", + "version": "1.1.3", "description": "WebGL graphic library", "keywords": [ "graphic", diff --git a/src/Renderer.js b/src/Renderer.js index 29996f570..028ef9646 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -62,7 +62,7 @@ function PlaceHolderTexture(renderer) { } gl.bindTexture(gl.TEXTURE_2D, webglTexture); if (firstBind) { - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.FLOAT, blankCanvas); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, blankCanvas); } }; this.unbind = function (renderer) { @@ -631,6 +631,7 @@ var Renderer = Base.extend(function () { var transparent; var drawID; var currentVAO; + var materialTakesTextureSlot; var vaoExt = this.getGLExtension('OES_vertex_array_object'); @@ -737,7 +738,7 @@ var Renderer = Base.extend(function () { } } - this._bindMaterial( + materialTakesTextureSlot = this._bindMaterial( renderable, material, program, prevRenderable || null, prevMaterial || null, prevProgram || null, passConfig.getUniform @@ -773,7 +774,7 @@ var Renderer = Base.extend(function () { culling ? _gl.enable(_gl.CULL_FACE) : _gl.disable(_gl.CULL_FACE); } // TODO Not update skeleton in each renderable. - this._updateSkeleton(renderable, program); + this._updateSkeleton(renderable, program, materialTakesTextureSlot); if (drawIDChanged) { currentVAO = this._bindVAO(vaoExt, shader, geometry, program); } @@ -799,7 +800,7 @@ var Renderer = Base.extend(function () { return this._glinfo.getMaxJointNumber(); }, - _updateSkeleton: function (object, program) { + _updateSkeleton: function (object, program, slot) { var _gl = this.gl; var skeleton = object.skeleton; // Set pose matrices of skinned mesh @@ -807,7 +808,6 @@ var Renderer = Base.extend(function () { skeleton.update(); if (object.joints.length > this._glinfo.getMaxJointNumber()) { var skinMatricesTexture = skeleton.getSubSkinMatricesTexture(object.__uid__, object.joints); - var slot = program.currentTextureSlot(); program.useTextureSlot(this, skinMatricesTexture, slot); program.setUniform(_gl, '1i', 'skinMatricesTexture', slot); program.setUniform(_gl, '1f', 'skinMatricesTextureSize', skinMatricesTexture.width); @@ -970,8 +970,10 @@ var Renderer = Base.extend(function () { program.setUniform(_gl, uniform.type, symbol, uniformValue); } } + var newSlot = program.currentTextureSlot(); // Texture slot maybe used out of material. program.resetTextureSlot(currentTextureSlot); + return newSlot; }, _bindVAO: function (vaoExt, shader, geometry, program) { diff --git a/src/version.js b/src/version.js index 1fccde1b5..a6c3cda8d 100644 --- a/src/version.js +++ b/src/version.js @@ -1,4 +1,4 @@ /** * @name clay.version */ -export default '1.1.2'; +export default '1.1.3';