提交 cf0649f4 编写于 作者: S sunag

gethash and customProgramCacheKey

上级 62b8e18b
......@@ -100,6 +100,28 @@ Node.prototype = {
},
getHash: function() {
var hash = '{';
for(var prop in this) {
var obj = this[ prop ];
if (obj instanceof Node) {
hash += '"' + prop + '":' + obj.getHash() + ',';
}
}
hash += '"id":"' + this.uuid + '"}';
return hash;
},
appendDepsNode: function ( builder, data, output ) {
data.deps = ( data.deps || 0 ) + 1;
......
......@@ -26,32 +26,6 @@ function NodeMaterial( vertex, fragment ) {
this.updaters = [];
// onBeforeCompile can't be in the prototype because onBeforeCompile.toString varies per material
this.onBeforeCompile = function ( shader, renderer ) {
var materialProperties = renderer.properties.get( this );
if ( this.version !== materialProperties.__version ) {
this.build( { renderer: renderer } );
shader.uniforms = this.uniforms;
shader.vertexShader = this.vertexShader;
shader.fragmentShader = this.fragmentShader;
}
};
// it fix the programCache and share the code with others materials
this.onBeforeCompile.toString = function () {
return scope.needsCompile;
};
}
NodeMaterial.prototype = Object.create( ShaderMaterial.prototype );
......@@ -91,6 +65,43 @@ Object.defineProperties( NodeMaterial.prototype, {
} );
NodeMaterial.prototype.onBeforeCompile = function ( shader, renderer ) {
var materialProperties = renderer.properties.get( this );
if ( this.version !== materialProperties.__version ) {
this.build( { renderer: renderer } );
shader.uniforms = this.uniforms;
shader.vertexShader = this.vertexShader;
shader.fragmentShader = this.fragmentShader;
}
};
NodeMaterial.prototype.customProgramCacheKey = function () {
var hash = this.getHash();
return hash;
};
NodeMaterial.prototype.getHash = function () {
var hash = '{';
hash += '"vertex":' + this.vertex.getHash() + ',\n';
hash += '"fragment":' + this.fragment.getHash() + '\n';
hash += '}'
return hash;
};
NodeMaterial.prototype.updateFrame = function ( frame ) {
for ( var i = 0; i < this.updaters.length; ++ i ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册