提交 c1cd65e6 编写于 作者: S SUNAG

cache improvement (multilayer) and TextureNode support for PBR`M environment

上级 0f239f31
...@@ -6,19 +6,60 @@ THREE.BuilderNode = function( material ) { ...@@ -6,19 +6,60 @@ THREE.BuilderNode = function( material ) {
this.material = material; this.material = material;
this.require = {}; this.caches = [];
this.isVerify = false; this.isVerify = false;
this.cache = '';
this.addCache();
}; };
THREE.BuilderNode.prototype = { THREE.BuilderNode.prototype = {
constructor: THREE.BuilderNode, constructor: THREE.BuilderNode,
addCache : function( name, requires ) {
this.caches.push( {
name : name || '',
requires : requires || {}
} );
return this.updateCache();
},
removeCache : function() {
this.caches.pop();
return this.updateCache();
},
updateCache : function() {
var cache = this.caches[ this.caches.length - 1 ];
this.cache = cache.name;
this.requires = cache.requires;
return this;
},
require : function( name, node ) {
this.requires[ name ] = node;
return this;
},
include : function( func ) { include : function( func ) {
this.material.include( this.shader, func ); this.material.include( this.shader, func );
return this;
}, },
getFormatConstructor : function( len ) { getFormatConstructor : function( len ) {
...@@ -89,14 +130,6 @@ THREE.BuilderNode.prototype = { ...@@ -89,14 +130,6 @@ THREE.BuilderNode.prototype = {
}, },
setCache : function( name ) {
this.cache = name || '';
return this;
},
getElementByIndex : function( index ) { getElementByIndex : function( index ) {
return THREE.BuilderNode.elements[ index ]; return THREE.BuilderNode.elements[ index ];
......
...@@ -13,40 +13,41 @@ THREE.GLNode = function( type ) { ...@@ -13,40 +13,41 @@ THREE.GLNode = function( type ) {
}; };
THREE.GLNode.prototype.verify = function( builder ) { THREE.GLNode.prototype.verify = function( builder, cache, requires ) {
builder.isVerify = true; builder.isVerify = true;
var material = builder.material; var material = builder.material;
this.build( builder, 'v4' ); this.build( builder.addCache( cache, requires ), 'v4' );
material.clearVertexNode(); material.clearVertexNode();
material.clearFragmentNode(); material.clearFragmentNode();
builder.setCache(); // reset cache builder.removeCache();
builder.isVerify = false; builder.isVerify = false;
}; };
THREE.GLNode.prototype.verifyAndBuildCode = function( builder, output, cache ) { THREE.GLNode.prototype.verifyAndBuildCode = function( builder, output, cache, requires ) {
this.verify( builder.setCache( cache ) ); this.verify( builder, cache, requires );
return this.buildCode( builder.setCache( cache ), output ); return this.buildCode( builder, output, cache, requires );
}; };
THREE.GLNode.prototype.buildCode = function( builder, output, uuid ) { THREE.GLNode.prototype.buildCode = function( builder, output, cache, requires ) {
var material = builder.material; var material = builder.material;
var data = { result : this.build( builder, output, uuid ) };
var data = { result : this.build( builder.addCache( cache, requires ), output ) };
if ( builder.isShader( 'vertex' ) ) data.code = material.clearVertexNode(); if ( builder.isShader( 'vertex' ) ) data.code = material.clearVertexNode();
else data.code = material.clearFragmentNode(); else data.code = material.clearFragmentNode();
builder.setCache(); // reset cache builder.removeCache();
return data; return data;
......
...@@ -25,11 +25,11 @@ THREE.CubeTextureNode.prototype.generate = function( builder, output ) { ...@@ -25,11 +25,11 @@ THREE.CubeTextureNode.prototype.generate = function( builder, output ) {
var cubetex = this.getTexture( builder, output ); var cubetex = this.getTexture( builder, output );
var coord = this.coord.build( builder, 'v3' ); var coord = this.coord.build( builder, 'v3' );
var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined;; var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined;
if ( bias == undefined && builder.require.cubeTextureBias ) { if ( bias == undefined && builder.requires.bias ) {
bias = builder.require.cubeTextureBias.build( builder, 'fv1' ); bias = builder.requires.bias.build( builder, 'fv1' );
} }
......
...@@ -27,6 +27,12 @@ THREE.TextureNode.prototype.generate = function( builder, output ) { ...@@ -27,6 +27,12 @@ THREE.TextureNode.prototype.generate = function( builder, output ) {
var coord = this.coord.build( builder, 'v2' ); var coord = this.coord.build( builder, 'v2' );
var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined; var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined;
if ( bias == undefined && builder.requires.bias ) {
bias = builder.requires.bias.build( builder, 'fv1' );
}
var code; var code;
if ( bias ) code = 'texture2D(' + tex + ',' + coord + ',' + bias + ')'; if ( bias ) code = 'texture2D(' + tex + ',' + coord + ',' + bias + ')';
......
...@@ -96,9 +96,11 @@ THREE.StandardNode.prototype.build = function( builder ) { ...@@ -96,9 +96,11 @@ THREE.StandardNode.prototype.build = function( builder ) {
} }
else { else {
// CubeMap blur effect (PBR) // autoblur textures for PBR Material effect
builder.require.cubeTextureBias = builder.require.cubeTextureBias || new THREE.RoughnessToBlinnExponentNode(); var requires = {
bias : new THREE.RoughnessToBlinnExponentNode()
};
// verify all nodes to reuse generate codes // verify all nodes to reuse generate codes
...@@ -116,7 +118,7 @@ THREE.StandardNode.prototype.build = function( builder ) { ...@@ -116,7 +118,7 @@ THREE.StandardNode.prototype.build = function( builder ) {
if ( this.normal ) this.normal.verify( builder ); if ( this.normal ) this.normal.verify( builder );
if ( this.normalScale && this.normal ) this.normalScale.verify( builder ); if ( this.normalScale && this.normal ) this.normalScale.verify( builder );
if ( this.environment ) this.environment.verify( builder.setCache( 'env' ) ); // isolate environment from others inputs ( see TextureNode, CubeTextureNode ) if ( this.environment ) this.environment.verify( builder, 'env', requires ); // isolate environment from others inputs ( see TextureNode, CubeTextureNode )
if ( this.reflectivity && this.environment ) this.reflectivity.verify( builder ); if ( this.reflectivity && this.environment ) this.reflectivity.verify( builder );
// build code // build code
...@@ -135,7 +137,7 @@ THREE.StandardNode.prototype.build = function( builder ) { ...@@ -135,7 +137,7 @@ THREE.StandardNode.prototype.build = function( builder ) {
var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : undefined; var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : undefined;
var normalScale = this.normalScale && this.normal ? this.normalScale.buildCode( builder, 'fv1' ) : undefined; var normalScale = this.normalScale && this.normal ? this.normalScale.buildCode( builder, 'fv1' ) : undefined;
var environment = this.environment ? this.environment.buildCode( builder.setCache( 'env' ), 'c' ) : undefined; var environment = this.environment ? this.environment.buildCode( builder, 'c', 'env', requires ) : undefined;
var reflectivity = this.reflectivity && this.environment ? this.reflectivity.buildCode( builder, 'fv1' ) : undefined; var reflectivity = this.reflectivity && this.environment ? this.reflectivity.buildCode( builder, 'fv1' ) : undefined;
material.requestAttrib.transparent = alpha != undefined; material.requestAttrib.transparent = alpha != undefined;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册