Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renamed LibNode to NodeLib #7830

Merged
merged 4 commits into from
Dec 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions examples/js/nodes/BuilderNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,60 @@ THREE.BuilderNode = function( material ) {

this.material = material;

this.require = {};
this.caches = [];
this.isVerify = false;
this.cache = '';

this.addCache();

};

THREE.BuilderNode.prototype = {
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 ) {

this.material.include( this.shader, func );

return this;

},

getFormatConstructor : function( len ) {
Expand Down Expand Up @@ -89,14 +130,6 @@ THREE.BuilderNode.prototype = {

},

setCache : function( name ) {

this.cache = name || '';

return this;

},

getElementByIndex : function( index ) {

return THREE.BuilderNode.elements[ index ];
Expand Down
4 changes: 2 additions & 2 deletions examples/js/nodes/FunctionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ THREE.FunctionNode.prototype.parse = function( src, includes, extensions ) {

}

if ( this.getInclude( reference ) === undefined && THREE.LibNode.contains( reference ) ) {
if ( this.getInclude( reference ) === undefined && THREE.NodeLib.contains( reference ) ) {

this.includes.push( THREE.LibNode.get( reference ) );
this.includes.push( THREE.NodeLib.get( reference ) );

}

Expand Down
19 changes: 10 additions & 9 deletions examples/js/nodes/GLNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

var material = builder.material;

this.build( builder, 'v4' );
this.build( builder.addCache( cache, requires ), 'v4' );

material.clearVertexNode();
material.clearFragmentNode();

builder.setCache(); // reset cache
builder.removeCache();

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 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();
else data.code = material.clearFragmentNode();

builder.setCache(); // reset cache
builder.removeCache();

return data;

Expand Down
12 changes: 6 additions & 6 deletions examples/js/nodes/LibNode.js → examples/js/nodes/NodeLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author sunag / http://www.sunag.com.br/
*/

THREE.LibNode = {
THREE.NodeLib = {
nodes: {},
add: function( node ) {

Expand Down Expand Up @@ -30,13 +30,13 @@ THREE.LibNode = {
// Luma
//

THREE.LibNode.add( new THREE.ConstNode( "vec3 LUMA = vec3(0.2125, 0.7154, 0.0721);" ) );
THREE.NodeLib.add( new THREE.ConstNode( "vec3 LUMA = vec3(0.2125, 0.7154, 0.0721);" ) );

//
// DepthColor
//

THREE.LibNode.add( new THREE.FunctionNode( [
THREE.NodeLib.add( new THREE.FunctionNode( [
"float depthcolor( float mNear, float mFar ) {",

"#ifdef USE_LOGDEPTHBUF_EXT",
Expand All @@ -53,7 +53,7 @@ THREE.LibNode.add( new THREE.FunctionNode( [
// NormalMap
//

THREE.LibNode.add( new THREE.FunctionNode( [
THREE.NodeLib.add( new THREE.FunctionNode( [
// Per-Pixel Tangent Space Normal Mapping
// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
"vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 map, vec2 mUv, float scale ) {",
Expand All @@ -75,7 +75,7 @@ THREE.LibNode.add( new THREE.FunctionNode( [
// Saturation
//

THREE.LibNode.add( new THREE.FunctionNode( [
THREE.NodeLib.add( new THREE.FunctionNode( [
// Algorithm from Chapter 16 of OpenGL Shading Language
"vec3 saturation_rgb(vec3 rgb, float adjustment) {",
"vec3 intensity = vec3(dot(rgb, LUMA));",
Expand All @@ -87,7 +87,7 @@ THREE.LibNode.add( new THREE.FunctionNode( [
// Luminance
//

THREE.LibNode.add( new THREE.FunctionNode( [
THREE.NodeLib.add( new THREE.FunctionNode( [
// Algorithm from Chapter 10 of Graphics Shaders.
"float luminance_rgb(vec3 rgb) {",
"return dot(rgb, LUMA);",
Expand Down
2 changes: 1 addition & 1 deletion examples/js/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ THREE.NodeMaterial.prototype.include = function( shader, node ) {

var includes;

node = typeof node === 'string' ? THREE.LibNode.get( node ) : node;
node = typeof node === 'string' ? THREE.NodeLib.get( node ) : node;

if ( node instanceof THREE.FunctionNode ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/js/nodes/accessors/ReflectNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ THREE.ReflectNode.prototype.generate = function( builder, output ) {
}
else {

console.warn( "THREE.ReflectNode is not compatible with " + builder.shader + " shader" );
console.warn( "THREE.ReflectNode is not compatible with " + builder.shader + " shader." );

return builder.format( 'vec3( 0.0 )', this.type, output );

Expand Down
6 changes: 3 additions & 3 deletions examples/js/nodes/inputs/CubeTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ THREE.CubeTextureNode.prototype.generate = function( builder, output ) {

var cubetex = this.getTexture( builder, output );
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' );

}

Expand Down
6 changes: 6 additions & 0 deletions examples/js/nodes/inputs/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ THREE.TextureNode.prototype.generate = function( builder, output ) {
var coord = this.coord.build( builder, 'v2' );
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;

if ( bias ) code = 'texture2D(' + tex + ',' + coord + ',' + bias + ')';
Expand Down
2 changes: 1 addition & 1 deletion examples/js/nodes/materials/PhongNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ THREE.PhongNode.prototype.build = function( builder ) {
var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : undefined;
var normalScale = this.normalScale && this.normal ? this.normalScale.buildCode( builder, 'fv1' ) : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalScale should be a vec2, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sunag. Great work, BTW!

Sorry, I do not understand your reply... Maybe I am missing something, but what I was pointing out is bumpScale is univariate, but normalScale is bivariate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am missing something, but what I was pointing out is bumpScale is univariate, but normalScale is bivariate.

I had to run some tests. Really works but normalmap brings a scale value in .z which also affects the normal.

I did a vec2 refraction with manual scale here: sunag@157b93e

but looking better the textures I have to put a vec3 too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sunag. Great work, BTW!

Thanks, Great PBR Material too 👍 !

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunag Sorry, I do not think I am making myself clear. In your code:

"vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 map, vec2 mUv, float scale ) {",

scale should be a vec2, and so should NormalMapNode.scale, because MeshPhongMaterial.normalScale is a Vector2().

In the examples, normalScale often must be Vector2( 1, - 1 ) -- depending on how the normal map is encoded.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, normalScale to vec2 looks nice, so soon send a update.


var environment = this.environment ? this.environment.buildCode( builder.setCache( 'env' ), 'c' ) : undefined;
var environment = this.environment ? this.environment.buildCode( builder, 'c' ) : undefined;
var reflectivity = this.reflectivity && this.environment ? this.reflectivity.buildCode( builder, 'fv1' ) : undefined;

material.requestAttrib.transparent = alpha != undefined;
Expand Down
10 changes: 6 additions & 4 deletions examples/js/nodes/materials/StandardNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ THREE.StandardNode.prototype.build = function( builder ) {
}
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

Expand All @@ -116,7 +118,7 @@ THREE.StandardNode.prototype.build = function( builder ) {
if ( this.normal ) this.normal.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 );

// build code
Expand All @@ -135,7 +137,7 @@ THREE.StandardNode.prototype.build = function( builder ) {
var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MeshStandardMaterial no longer has a reflectivity property. Is the goal to keep MeshStandard and StandardNode in sync?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal to keep MeshStandard and StandardNode in sync?

Hmm, Yes! I'll update here so soon send another commit.


material.requestAttrib.transparent = alpha != undefined;
Expand Down
2 changes: 1 addition & 1 deletion examples/js/nodes/utils/NormalMapNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ THREE.NormalMapNode.prototype.generate = function( builder, output ) {
}
else {

console.warn( "THREE.NormalMap is not compatible with " + builder.shader + " shader" );
console.warn( "THREE.NormalMap is not compatible with " + builder.shader + " shader." );

return builder.format( 'vec3( 0.0 )', this.type, output );

Expand Down
4 changes: 2 additions & 2 deletions examples/js/nodes/utils/RoughnessToBlinnExponentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ THREE.RoughnessToBlinnExponentNode.prototype.generate = function( builder, outpu
}
else {

console.warn( "THREE.RoughnessToBlinnExponentNode is compatible with StandardMaterial only" );
console.warn( "THREE.RoughnessToBlinnExponentNode is compatible with StandardMaterial only." );

material.addFragmentNode( 'float specularMIPLevel = 0.0;' );

Expand All @@ -35,7 +35,7 @@ THREE.RoughnessToBlinnExponentNode.prototype.generate = function( builder, outpu
}
else {

console.warn( "THREE.RoughnessToBlinnExponentNode is not compatible with " + builder.shader + " shader" );
console.warn( "THREE.RoughnessToBlinnExponentNode is not compatible with " + builder.shader + " shader." );

return builder.format( '0.0', this.type, output );

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_materials_nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<script src="js/nodes/FunctionNode.js"></script>
<script src="js/nodes/FunctionCallNode.js"></script>
<script src="js/nodes/BuilderNode.js"></script>
<script src="js/nodes/LibNode.js"></script>
<script src="js/nodes/NodeLib.js"></script>
<script src="js/nodes/NodeMaterial.js"></script>

<!-- Accessors -->
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_postprocessing_nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<script src="js/nodes/FunctionNode.js"></script>
<script src="js/nodes/FunctionCallNode.js"></script>
<script src="js/nodes/BuilderNode.js"></script>
<script src="js/nodes/LibNode.js"></script>
<script src="js/nodes/NodeLib.js"></script>
<script src="js/nodes/NodeMaterial.js"></script>

<!-- Accessors -->
Expand Down