Skip to content

Commit

Permalink
Fix skin matrices texture affect other textures bug. Release 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Mar 28, 2018
1 parent 0ecbf3c commit d9ecfee
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
6 changes: 5 additions & 1 deletion example/app_gbuffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion example/app_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions example/deferred_skinning.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "claygl",
"version": "1.1.2",
"version": "1.1.3",
"description": "WebGL graphic library",
"keywords": [
"graphic",
Expand Down
12 changes: 7 additions & 5 deletions src/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -799,15 +800,14 @@ 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
if (skeleton) {
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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* @name clay.version
*/
export default '1.1.2';
export default '1.1.3';

0 comments on commit d9ecfee

Please sign in to comment.