webvr js meetup initial commit

This commit is contained in:
Senad Uka
2017-03-11 15:22:17 +01:00
commit 3f640b55db
761 changed files with 264174 additions and 0 deletions

38
node_modules/three/examples/js/nodes/AttributeNode.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.AttributeNode = function( name, type ) {
THREE.GLNode.call( this, type );
this.name = name;
};
THREE.AttributeNode.prototype = Object.create( THREE.GLNode.prototype );
THREE.AttributeNode.prototype.constructor = THREE.AttributeNode;
THREE.AttributeNode.prototype.getAttributeType = function( builder ) {
return typeof this.type === 'number' ? builder.getConstructorFromLength( this.type ) : this.type;
};
THREE.AttributeNode.prototype.getType = function( builder ) {
var type = this.getAttributeType( builder );
return builder.getTypeByFormat( type );
};
THREE.AttributeNode.prototype.generate = function( builder, output ) {
var type = this.getAttributeType( builder );
var attribute = builder.material.getAttribute( this.name, type );
return builder.format( builder.isShader( 'vertex' ) ? this.name : attribute.varying.name, this.getType( builder ), output );
};

89
node_modules/three/examples/js/nodes/ConstNode.js generated vendored Normal file
View File

@@ -0,0 +1,89 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ConstNode = function( src, useDefine ) {
THREE.TempNode.call( this );
this.eval( src || THREE.ConstNode.PI, useDefine );
};
THREE.ConstNode.PI = 'PI';
THREE.ConstNode.PI2 = 'PI2';
THREE.ConstNode.RECIPROCAL_PI = 'RECIPROCAL_PI';
THREE.ConstNode.RECIPROCAL_PI2 = 'RECIPROCAL_PI2';
THREE.ConstNode.LOG2 = 'LOG2';
THREE.ConstNode.EPSILON = 'EPSILON';
THREE.ConstNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.ConstNode.prototype.constructor = THREE.ConstNode;
THREE.ConstNode.prototype.getType = function( builder ) {
return builder.getTypeByFormat( this.type );
};
THREE.ConstNode.prototype.eval = function( src, useDefine ) {
src = ( src || '' ).trim();
var name, type, value;
var rDeclaration = /^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=?\s?(.*?)(\;|$)/i;
var match = src.match( rDeclaration );
this.useDefine = useDefine;
if ( match && match.length > 1 ) {
type = match[ 1 ];
name = match[ 2 ];
value = match[ 3 ];
} else {
name = src;
type = 'fv1';
}
this.name = name;
this.type = type;
this.value = value;
};
THREE.ConstNode.prototype.build = function( builder, output ) {
if ( output === 'source' ) {
if ( this.value ) {
if ( this.useDefine ) {
return '#define ' + this.name + ' ' + this.value;
}
return 'const ' + this.type + ' ' + this.name + ' = ' + this.value + ';';
}
} else {
builder.include( this );
return builder.format( this.name, this.getType( builder ), output );
}
};
THREE.ConstNode.prototype.generate = function( builder, output ) {
return builder.format( this.name, this.getType( builder ), output );
};

View File

@@ -0,0 +1,58 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.FunctionCallNode = function( func, inputs ) {
THREE.TempNode.call( this );
this.setFunction( func, inputs );
};
THREE.FunctionCallNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.FunctionCallNode.prototype.constructor = THREE.FunctionCallNode;
THREE.FunctionCallNode.prototype.setFunction = function( func, inputs ) {
this.value = func;
this.inputs = inputs || [];
};
THREE.FunctionCallNode.prototype.getFunction = function() {
return this.value;
};
THREE.FunctionCallNode.prototype.getType = function( builder ) {
return this.value.getType( builder );
};
THREE.FunctionCallNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var type = this.getType( builder );
var func = this.value;
var code = func.build( builder, output ) + '(';
var params = [];
for ( var i = 0; i < func.inputs.length; i ++ ) {
var inpt = func.inputs[ i ];
var param = this.inputs[ i ] || this.inputs[ inpt.name ];
params.push( param.build( builder, builder.getTypeByFormat( inpt.type ) ) );
}
code += params.join( ',' ) + ')';
return builder.format( code, type, output );
};

203
node_modules/three/examples/js/nodes/FunctionNode.js generated vendored Normal file
View File

@@ -0,0 +1,203 @@
/**
* @author sunag / http://www.sunag.com.br/
* @thanks bhouston / https://clara.io/
*/
THREE.FunctionNode = function( src, includesOrType, extensionsOrIncludes, keywordsOrExtensions ) {
src = src || '';
this.isMethod = typeof includesOrType !== "string";
this.useKeywords = true;
THREE.TempNode.call( this, this.isMethod ? null : includesOrType );
if ( this.isMethod ) this.eval( src, includesOrType, extensionsOrIncludes, keywordsOrExtensions );
else this.eval( src, extensionsOrIncludes, keywordsOrExtensions );
};
THREE.FunctionNode.rDeclaration = /^([a-z_0-9]+)\s([a-z_0-9]+)\s?\((.*?)\)/i;
THREE.FunctionNode.rProperties = /[a-z_0-9]+/ig;
THREE.FunctionNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.FunctionNode.prototype.constructor = THREE.FunctionNode;
THREE.FunctionNode.prototype.isShared = function( builder, output ) {
return ! this.isMethod;
};
THREE.FunctionNode.prototype.getType = function( builder ) {
return builder.getTypeByFormat( this.type );
};
THREE.FunctionNode.prototype.getInputByName = function( name ) {
var i = this.inputs.length;
while ( i -- ) {
if ( this.inputs[ i ].name === name )
return this.inputs[ i ];
}
};
THREE.FunctionNode.prototype.getIncludeByName = function( name ) {
var i = this.includes.length;
while ( i -- ) {
if ( this.includes[ i ].name === name )
return this.includes[ i ];
}
};
THREE.FunctionNode.prototype.generate = function( builder, output ) {
var match, offset = 0, src = this.value;
for ( var i = 0; i < this.includes.length; i ++ ) {
builder.include( this.includes[ i ], this );
}
for ( var ext in this.extensions ) {
builder.material.extensions[ ext ] = true;
}
while ( match = THREE.FunctionNode.rProperties.exec( this.value ) ) {
var prop = match[ 0 ], isGlobal = this.isMethod ? ! this.getInputByName( prop ) : true;
var reference = prop;
if ( this.keywords[ prop ] || ( this.useKeywords && isGlobal && THREE.NodeLib.containsKeyword( prop ) ) ) {
var node = this.keywords[ prop ];
if ( ! node ) {
var keyword = THREE.NodeLib.getKeywordData( prop );
if ( keyword.cache ) node = builder.keywords[ prop ];
node = node || THREE.NodeLib.getKeyword( prop, builder );
if ( keyword.cache ) builder.keywords[ prop ] = node;
}
reference = node.build( builder );
}
if ( prop != reference ) {
src = src.substring( 0, match.index + offset ) + reference + src.substring( match.index + prop.length + offset );
offset += reference.length - prop.length;
}
if ( this.getIncludeByName( reference ) === undefined && THREE.NodeLib.contains( reference ) ) {
builder.include( THREE.NodeLib.get( reference ) );
}
}
if ( output === 'source' ) {
return src;
} else if ( this.isMethod ) {
builder.include( this, false, src );
return this.name;
} else {
return builder.format( "(" + src + ")", this.getType( builder ), output );
}
};
THREE.FunctionNode.prototype.eval = function( src, includes, extensions, keywords ) {
src = ( src || '' ).trim();
this.includes = includes || [];
this.extensions = extensions || {};
this.keywords = keywords || {};
if ( this.isMethod ) {
var match = src.match( THREE.FunctionNode.rDeclaration );
this.inputs = [];
if ( match && match.length == 4 ) {
this.type = match[ 1 ];
this.name = match[ 2 ];
var inputs = match[ 3 ].match( THREE.FunctionNode.rProperties );
if ( inputs ) {
var i = 0;
while ( i < inputs.length ) {
var qualifier = inputs[ i ++ ];
var type, name;
if ( qualifier == 'in' || qualifier == 'out' || qualifier == 'inout' ) {
type = inputs[ i ++ ];
} else {
type = qualifier;
qualifier = '';
}
name = inputs[ i ++ ];
this.inputs.push( {
name : name,
type : type,
qualifier : qualifier
} );
}
}
} else {
this.type = '';
this.name = '';
}
}
this.value = src;
};

105
node_modules/three/examples/js/nodes/GLNode.js generated vendored Normal file
View File

@@ -0,0 +1,105 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.GLNode = function( type ) {
this.uuid = THREE.Math.generateUUID();
this.allows = {};
this.requestUpdate = false;
this.type = type;
};
THREE.GLNode.prototype.parse = function( builder, context ) {
context = context || {};
builder.parsing = true;
var material = builder.material;
this.build( builder.addCache( context.cache, context.requires ).addSlot( context.slot ), 'v4' );
material.clearVertexNode();
material.clearFragmentNode();
builder.removeCache().removeSlot();
builder.parsing = false;
};
THREE.GLNode.prototype.parseAndBuildCode = function( builder, output, context ) {
context = context || {};
this.parse( builder, context );
return this.buildCode( builder, output, context );
};
THREE.GLNode.prototype.buildCode = function( builder, output, context ) {
context = context || {};
var material = builder.material;
var data = { result : this.build( builder.addCache( context.cache, context.requires ).addSlot( context.slot ), output ) };
if ( builder.isShader( 'vertex' ) ) data.code = material.clearVertexNode();
else data.code = material.clearFragmentNode();
builder.removeCache().removeSlot();
return data;
};
THREE.GLNode.prototype.build = function( builder, output, uuid ) {
output = output || this.getType( builder, output );
var material = builder.material, data = material.getDataNode( uuid || this.uuid );
if ( builder.parsing ) this.appendDepsNode( builder, data, output );
if ( this.allows[ builder.shader ] === false ) {
throw new Error( 'Shader ' + shader + ' is not compatible with this node.' );
}
if ( this.requestUpdate && material.requestUpdate.indexOf( this ) === - 1 ) {
material.requestUpdate.push( this );
}
return this.generate( builder, output, uuid );
};
THREE.GLNode.prototype.appendDepsNode = function( builder, data, output ) {
data.deps = ( data.deps || 0 ) + 1;
var outputLen = builder.getFormatLength( output );
if ( outputLen > ( data.outputMax || 0 ) || this.getType( builder, output ) ) {
data.outputMax = outputLen;
data.output = output;
}
};
THREE.GLNode.prototype.getType = function( builder, output ) {
return output === 'sampler2D' || output === 'samplerCube' ? output : this.type;
};

48
node_modules/three/examples/js/nodes/InputNode.js generated vendored Normal file
View File

@@ -0,0 +1,48 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.InputNode = function( type, params ) {
params = params || {};
params.shared = params.shared !== undefined ? params.shared : false;
THREE.TempNode.call( this, type, params );
};
THREE.InputNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.InputNode.prototype.constructor = THREE.InputNode;
THREE.InputNode.prototype.generate = function( builder, output, uuid, type, ns, needsUpdate ) {
var material = builder.material;
uuid = builder.getUuid( uuid || this.getUuid() );
type = type || this.getType( builder );
var data = material.getDataNode( uuid );
if ( builder.isShader( 'vertex' ) ) {
if ( ! data.vertex ) {
data.vertex = material.createVertexUniform( type, this.value, ns, needsUpdate );
}
return builder.format( data.vertex.name, type, output );
} else {
if ( ! data.fragment ) {
data.fragment = material.createFragmentUniform( type, this.value, ns, needsUpdate );
}
return builder.format( data.fragment.name, type, output );
}
};

258
node_modules/three/examples/js/nodes/NodeBuilder.js generated vendored Normal file
View File

@@ -0,0 +1,258 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.NodeBuilder = function( material ) {
this.material = material;
this.caches = [];
this.slots = [];
this.keywords = {};
this.parsing = false;
this.optimize = true;
this.update();
};
THREE.NodeBuilder.type = {
float : 'fv1',
vec2 : 'v2',
vec3 : 'v3',
vec4 : 'v4',
mat4 : 'v4',
int : 'iv1'
};
THREE.NodeBuilder.constructors = [
'float',
'vec2',
'vec3',
'vec4'
];
THREE.NodeBuilder.elements = [
'x',
'y',
'z',
'w'
];
THREE.NodeBuilder.prototype = {
constructor: THREE.NodeBuilder,
addCache : function( name, requires ) {
this.caches.push( {
name : name || '',
requires : requires || {}
} );
return this.update();
},
removeCache : function() {
this.caches.pop();
return this.update();
},
addSlot : function( name ) {
this.slots.push( {
name : name || ''
} );
return this.update();
},
removeSlot : function() {
this.slots.pop();
return this.update();
},
isCache : function( name ) {
var i = this.caches.length;
while ( i -- ) {
if ( this.caches[ i ].name == name ) return true;
}
return false;
},
isSlot : function( name ) {
var i = this.slots.length;
while ( i -- ) {
if ( this.slots[ i ].name == name ) return true;
}
return false;
},
update : function() {
var cache = this.caches[ this.caches.length - 1 ];
var slot = this.slots[ this.slots.length - 1 ];
this.slot = slot ? slot.name : '';
this.cache = cache ? cache.name : '';
this.requires = cache ? cache.requires : {};
return this;
},
require : function( name, node ) {
this.requires[ name ] = node;
return this;
},
include : function( node, parent, source ) {
this.material.include( this, node, parent, source );
return this;
},
colorToVector : function( color ) {
return color.replace( 'r', 'x' ).replace( 'g', 'y' ).replace( 'b', 'z' ).replace( 'a', 'w' );
},
getConstructorFromLength : function( len ) {
return THREE.NodeBuilder.constructors[ len - 1 ];
},
getFormatName : function( format ) {
return format.replace( /c/g, 'v3' ).replace( /fv1/g, 'v1' ).replace( /iv1/g, 'i' );
},
isFormatMatrix : function( format ) {
return /^m/.test( format );
},
getFormatLength : function( format ) {
return parseInt( this.getFormatName( format ).substr( 1 ) );
},
getFormatFromLength : function( len ) {
if ( len == 1 ) return 'fv1';
return 'v' + len;
},
format : function( code, from, to ) {
var format = this.getFormatName( to + '=' + from );
switch ( format ) {
case 'v1=v2': return code + '.x';
case 'v1=v3': return code + '.x';
case 'v1=v4': return code + '.x';
case 'v1=i': return 'float(' + code + ')';
case 'v2=v1': return 'vec2(' + code + ')';
case 'v2=v3': return code + '.xy';
case 'v2=v4': return code + '.xy';
case 'v2=i': return 'vec2(float(' + code + '))';
case 'v3=v1': return 'vec3(' + code + ')';
case 'v3=v2': return 'vec3(' + code + ',0.0)';
case 'v3=v4': return code + '.xyz';
case 'v3=i': return 'vec2(float(' + code + '))';
case 'v4=v1': return 'vec4(' + code + ')';
case 'v4=v2': return 'vec4(' + code + ',0.0,1.0)';
case 'v4=v3': return 'vec4(' + code + ',1.0)';
case 'v4=i': return 'vec4(float(' + code + '))';
case 'i=v1': return 'int(' + code + ')';
case 'i=v2': return 'int(' + code + '.x)';
case 'i=v3': return 'int(' + code + '.x)';
case 'i=v4': return 'int(' + code + '.x)';
}
return code;
},
getTypeByFormat : function( format ) {
return THREE.NodeBuilder.type[ format ] || format;
},
getUuid : function( uuid, useCache ) {
useCache = useCache !== undefined ? useCache : true;
if ( useCache && this.cache ) uuid = this.cache + '-' + uuid;
return uuid;
},
getElementByIndex : function( index ) {
return THREE.NodeBuilder.elements[ index ];
},
getIndexByElement : function( elm ) {
return THREE.NodeBuilder.elements.indexOf( elm );
},
isShader : function( shader ) {
return this.shader == shader;
},
setShader : function( shader ) {
this.shader = shader;
return this;
}
};

214
node_modules/three/examples/js/nodes/NodeLib.js generated vendored Normal file
View File

@@ -0,0 +1,214 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.NodeLib = {
nodes: {},
keywords: {},
add: function( node ) {
this.nodes[ node.name ] = node;
},
addKeyword: function( name, callback, cache ) {
cache = cache !== undefined ? cache : true;
this.keywords[ name ] = { callback : callback, cache : cache };
},
remove: function( node ) {
delete this.nodes[ node.name ];
},
removeKeyword: function( name ) {
delete this.keywords[ node ];
},
get: function( name ) {
return this.nodes[ name ];
},
getKeyword: function( name, material ) {
return this.keywords[ name ].callback.call( this, material );
},
getKeywordData: function( name ) {
return this.keywords[ name ];
},
contains: function( name ) {
return this.nodes[ name ] != undefined;
},
containsKeyword: function( name ) {
return this.keywords[ name ] != undefined;
}
};
//
// Keywords
//
THREE.NodeLib.addKeyword( 'uv', function() {
return new THREE.UVNode();
} );
THREE.NodeLib.addKeyword( 'uv2', function() {
return new THREE.UVNode( 1 );
} );
THREE.NodeLib.addKeyword( 'position', function() {
return new THREE.PositionNode();
} );
THREE.NodeLib.addKeyword( 'worldPosition', function() {
return new THREE.PositionNode( THREE.PositionNode.WORLD );
} );
THREE.NodeLib.addKeyword( 'normal', function() {
return new THREE.NormalNode();
} );
THREE.NodeLib.addKeyword( 'worldNormal', function() {
return new THREE.NormalNode( THREE.NormalNode.WORLD );
} );
THREE.NodeLib.addKeyword( 'viewPosition', function() {
return new THREE.PositionNode( THREE.NormalNode.VIEW );
} );
THREE.NodeLib.addKeyword( 'viewNormal', function() {
return new THREE.NormalNode( THREE.NormalNode.VIEW );
} );
THREE.NodeLib.addKeyword( 'time', function() {
return new THREE.TimerNode();
} );
//
// Luma
//
THREE.NodeLib.add( new THREE.ConstNode( "vec3 LUMA vec3(0.2125, 0.7154, 0.0721)" ) );
//
// NormalMap
//
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, vec2 scale ) {",
" vec3 q0 = dFdx( eye_pos );",
" vec3 q1 = dFdy( eye_pos );",
" vec2 st0 = dFdx( mUv.st );",
" vec2 st1 = dFdy( mUv.st );",
" vec3 S = normalize( q0 * st1.t - q1 * st0.t );",
" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );",
" vec3 N = normalize( surf_norm );",
" vec3 mapN = map * 2.0 - 1.0;",
" mapN.xy = scale * mapN.xy;",
" mat3 tsn = mat3( S, T, N );",
" return normalize( tsn * mapN );",
"}"
].join( "\n" ), null, { derivatives: true } ) );
//
// Noise
//
THREE.NodeLib.add( new THREE.FunctionNode( [
"float snoise(vec2 co) {",
" return fract( sin( dot(co.xy, vec2(12.9898,78.233) ) ) * 43758.5453 );",
"}"
].join( "\n" ) ) );
//
// Hue
//
THREE.NodeLib.add( new THREE.FunctionNode( [
"vec3 hue_rgb(vec3 rgb, float adjustment) {",
" const mat3 RGBtoYIQ = mat3(0.299, 0.587, 0.114, 0.595716, -0.274453, -0.321263, 0.211456, -0.522591, 0.311135);",
" const mat3 YIQtoRGB = mat3(1.0, 0.9563, 0.6210, 1.0, -0.2721, -0.6474, 1.0, -1.107, 1.7046);",
" vec3 yiq = RGBtoYIQ * rgb;",
" float hue = atan(yiq.z, yiq.y) + adjustment;",
" float chroma = sqrt(yiq.z * yiq.z + yiq.y * yiq.y);",
" return YIQtoRGB * vec3(yiq.x, chroma * cos(hue), chroma * sin(hue));",
"}"
].join( "\n" ) ) );
//
// Saturation
//
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));",
" return mix(intensity, rgb, adjustment);",
"}"
].join( "\n" ) ) );
//
// Luminance
//
THREE.NodeLib.add( new THREE.FunctionNode( [
// Algorithm from Chapter 10 of Graphics Shaders
"float luminance_rgb(vec3 rgb) {",
" return dot(rgb, LUMA);",
"}"
].join( "\n" ) ) );
//
// Vibrance
//
THREE.NodeLib.add( new THREE.FunctionNode( [
// Shader by Evan Wallace adapted by @lo-th
"vec3 vibrance_rgb(vec3 rgb, float adjustment) {",
" float average = (rgb.r + rgb.g + rgb.b) / 3.0;",
" float mx = max(rgb.r, max(rgb.g, rgb.b));",
" float amt = (mx - average) * (-3.0 * adjustment);",
" return mix(rgb.rgb, vec3(mx), amt);",
"}"
].join( "\n" ) ) );

569
node_modules/three/examples/js/nodes/NodeMaterial.js generated vendored Normal file
View File

@@ -0,0 +1,569 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.NodeMaterial = function( vertex, fragment ) {
THREE.ShaderMaterial.call( this );
this.vertex = vertex || new THREE.RawNode( new THREE.PositionNode( THREE.PositionNode.PROJECTION ) );
this.fragment = fragment || new THREE.RawNode( new THREE.ColorNode( 0xFF0000 ) );
};
THREE.NodeMaterial.types = {
t : 'sampler2D',
tc : 'samplerCube',
bv1 : 'bool',
iv1 : 'int',
fv1 : 'float',
c : 'vec3',
v2 : 'vec2',
v3 : 'vec3',
v4 : 'vec4',
m4 : 'mat4'
};
THREE.NodeMaterial.addShortcuts = function( proto, prop, list ) {
function applyShortcut( prop, name ) {
return {
get: function() {
return this[ prop ][ name ];
},
set: function( val ) {
this[ prop ][ name ] = val;
}
};
}
return ( function() {
var shortcuts = {};
for ( var i = 0; i < list.length; ++ i ) {
var name = list[ i ];
shortcuts[ name ] = applyShortcut( prop, name );
}
Object.defineProperties( proto, shortcuts );
} )();
};
THREE.NodeMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
THREE.NodeMaterial.prototype.constructor = THREE.NodeMaterial;
THREE.NodeMaterial.prototype.updateFrame = function( delta ) {
for ( var i = 0; i < this.requestUpdate.length; ++ i ) {
this.requestUpdate[ i ].updateFrame( delta );
}
};
THREE.NodeMaterial.prototype.build = function() {
var vertex, fragment;
this.defines = {};
this.uniforms = {};
this.attributes = {};
this.extensions = {};
this.nodeData = {};
this.vertexUniform = [];
this.fragmentUniform = [];
this.vars = [];
this.vertexTemps = [];
this.fragmentTemps = [];
this.uniformList = [];
this.consts = [];
this.functions = [];
this.requestUpdate = [];
this.requestAttribs = {
uv: [],
color: []
};
this.vertexPars = '';
this.fragmentPars = '';
this.vertexCode = '';
this.fragmentCode = '';
this.vertexNode = '';
this.fragmentNode = '';
this.prefixCode = [
"#ifdef GL_EXT_shader_texture_lod",
" #define texCube(a, b) textureCube(a, b)",
" #define texCubeBias(a, b, c) textureCubeLodEXT(a, b, c)",
" #define tex2D(a, b) texture2D(a, b)",
" #define tex2DBias(a, b, c) texture2DLodEXT(a, b, c)",
"#else",
" #define texCube(a, b) textureCube(a, b)",
" #define texCubeBias(a, b, c) textureCube(a, b, c)",
" #define tex2D(a, b) texture2D(a, b)",
" #define tex2DBias(a, b, c) texture2D(a, b, c)",
"#endif",
"#include <packing>"
].join( "\n" );
var builder = new THREE.NodeBuilder( this );
vertex = this.vertex.build( builder.setShader( 'vertex' ), 'v4' );
fragment = this.fragment.build( builder.setShader( 'fragment' ), 'v4' );
if ( this.requestAttribs.uv[ 0 ] ) {
this.addVertexPars( 'varying vec2 vUv;' );
this.addFragmentPars( 'varying vec2 vUv;' );
this.addVertexCode( 'vUv = uv;' );
}
if ( this.requestAttribs.uv[ 1 ] ) {
this.addVertexPars( 'varying vec2 vUv2; attribute vec2 uv2;' );
this.addFragmentPars( 'varying vec2 vUv2;' );
this.addVertexCode( 'vUv2 = uv2;' );
}
if ( this.requestAttribs.color[ 0 ] ) {
this.addVertexPars( 'varying vec4 vColor; attribute vec4 color;' );
this.addFragmentPars( 'varying vec4 vColor;' );
this.addVertexCode( 'vColor = color;' );
}
if ( this.requestAttribs.color[ 1 ] ) {
this.addVertexPars( 'varying vec4 vColor2; attribute vec4 color2;' );
this.addFragmentPars( 'varying vec4 vColor2;' );
this.addVertexCode( 'vColor2 = color2;' );
}
if ( this.requestAttribs.position ) {
this.addVertexPars( 'varying vec3 vPosition;' );
this.addFragmentPars( 'varying vec3 vPosition;' );
this.addVertexCode( 'vPosition = transformed;' );
}
if ( this.requestAttribs.worldPosition ) {
// for future update replace from the native "varying vec3 vWorldPosition" for optimization
this.addVertexPars( 'varying vec3 vWPosition;' );
this.addFragmentPars( 'varying vec3 vWPosition;' );
this.addVertexCode( 'vWPosition = worldPosition.xyz;' );
}
if ( this.requestAttribs.normal ) {
this.addVertexPars( 'varying vec3 vObjectNormal;' );
this.addFragmentPars( 'varying vec3 vObjectNormal;' );
this.addVertexCode( 'vObjectNormal = normal;' );
}
if ( this.requestAttribs.worldNormal ) {
this.addVertexPars( 'varying vec3 vWNormal;' );
this.addFragmentPars( 'varying vec3 vWNormal;' );
this.addVertexCode( 'vWNormal = ( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz;' );
}
this.lights = this.requestAttribs.light;
this.transparent = this.requestAttribs.transparent || this.blending > THREE.NormalBlending;
this.vertexShader = [
this.prefixCode,
this.vertexPars,
this.getCodePars( this.vertexUniform, 'uniform' ),
this.getIncludes( this.consts[ 'vertex' ] ),
this.getIncludes( this.functions[ 'vertex' ] ),
'void main(){',
this.getCodePars( this.vertexTemps ),
vertex,
this.vertexCode,
'}'
].join( "\n" );
this.fragmentShader = [
this.prefixCode,
this.fragmentPars,
this.getCodePars( this.fragmentUniform, 'uniform' ),
this.getIncludes( this.consts[ 'fragment' ] ),
this.getIncludes( this.functions[ 'fragment' ] ),
'void main(){',
this.getCodePars( this.fragmentTemps ),
this.fragmentCode,
fragment,
'}'
].join( "\n" );
this.needsUpdate = true;
this.dispose(); // force update
return this;
};
THREE.NodeMaterial.prototype.define = function( name, value ) {
this.defines[ name ] = value == undefined ? 1 : value;
};
THREE.NodeMaterial.prototype.isDefined = function( name ) {
return this.defines[ name ] != undefined;
};
THREE.NodeMaterial.prototype.mergeUniform = function( uniforms ) {
for ( var name in uniforms ) {
this.uniforms[ name ] = uniforms[ name ];
}
};
THREE.NodeMaterial.prototype.createUniform = function( type, value, ns, needsUpdate ) {
var index = this.uniformList.length;
var uniform = {
type : type,
value : value,
name : ns ? ns : 'nVu' + index,
needsUpdate : needsUpdate
};
this.uniformList.push( uniform );
return uniform;
};
THREE.NodeMaterial.prototype.getVertexTemp = function( uuid, type, ns ) {
var data = this.vertexTemps[ uuid ];
if ( ! data ) {
var index = this.vertexTemps.length,
name = ns ? ns : 'nVt' + index;
data = { name : name, type : type };
this.vertexTemps.push( data );
this.vertexTemps[ uuid ] = data;
}
return data;
};
THREE.NodeMaterial.prototype.getFragmentTemp = function( uuid, type, ns ) {
var data = this.fragmentTemps[ uuid ];
if ( ! data ) {
var index = this.fragmentTemps.length,
name = ns ? ns : 'nVt' + index;
data = { name : name, type : type };
this.fragmentTemps.push( data );
this.fragmentTemps[ uuid ] = data;
}
return data;
};
THREE.NodeMaterial.prototype.getVar = function( uuid, type, ns ) {
var data = this.vars[ uuid ];
if ( ! data ) {
var index = this.vars.length,
name = ns ? ns : 'nVv' + index;
data = { name : name, type : type };
this.vars.push( data );
this.vars[ uuid ] = data;
this.addVertexPars( 'varying ' + type + ' ' + name + ';' );
this.addFragmentPars( 'varying ' + type + ' ' + name + ';' );
}
return data;
};
THREE.NodeMaterial.prototype.getAttribute = function( name, type ) {
if ( ! this.attributes[ name ] ) {
var varying = this.getVar( name, type );
this.addVertexPars( 'attribute ' + type + ' ' + name + ';' );
this.addVertexCode( varying.name + ' = ' + name + ';' );
this.attributes[ name ] = { varying : varying, name : name, type : type };
}
return this.attributes[ name ];
};
THREE.NodeMaterial.prototype.getIncludes = function() {
function sortByPosition( a, b ) {
return a.deps.length - b.deps.length;
}
return function( incs ) {
if ( ! incs ) return '';
var code = '', incs = incs.sort( sortByPosition );
for ( var i = 0; i < incs.length; i ++ ) {
if ( incs[ i ].src ) code += incs[ i ].src + '\n';
}
return code;
}
}();
THREE.NodeMaterial.prototype.addVertexPars = function( code ) {
this.vertexPars += code + '\n';
};
THREE.NodeMaterial.prototype.addFragmentPars = function( code ) {
this.fragmentPars += code + '\n';
};
THREE.NodeMaterial.prototype.addVertexCode = function( code ) {
this.vertexCode += code + '\n';
};
THREE.NodeMaterial.prototype.addFragmentCode = function( code ) {
this.fragmentCode += code + '\n';
};
THREE.NodeMaterial.prototype.addVertexNode = function( code ) {
this.vertexNode += code + '\n';
};
THREE.NodeMaterial.prototype.clearVertexNode = function() {
var code = this.vertexNode;
this.vertexNode = '';
return code;
};
THREE.NodeMaterial.prototype.addFragmentNode = function( code ) {
this.fragmentNode += code + '\n';
};
THREE.NodeMaterial.prototype.clearFragmentNode = function() {
var code = this.fragmentNode;
this.fragmentNode = '';
return code;
};
THREE.NodeMaterial.prototype.getCodePars = function( pars, prefix ) {
prefix = prefix || '';
var code = '';
for ( var i = 0, l = pars.length; i < l; ++ i ) {
var parsType = pars[ i ].type;
var parsName = pars[ i ].name;
var parsValue = pars[ i ].value;
if ( parsType == 't' && parsValue instanceof THREE.CubeTexture ) parsType = 'tc';
var type = THREE.NodeMaterial.types[ parsType ];
if ( type == undefined ) throw new Error( "Node pars " + parsType + " not found." );
code += prefix + ' ' + type + ' ' + parsName + ';\n';
}
return code;
};
THREE.NodeMaterial.prototype.createVertexUniform = function( type, value, ns, needsUpdate ) {
var uniform = this.createUniform( type, value, ns, needsUpdate );
this.vertexUniform.push( uniform );
this.vertexUniform[ uniform.name ] = uniform;
this.uniforms[ uniform.name ] = uniform;
return uniform;
};
THREE.NodeMaterial.prototype.createFragmentUniform = function( type, value, ns, needsUpdate ) {
var uniform = this.createUniform( type, value, ns, needsUpdate );
this.fragmentUniform.push( uniform );
this.fragmentUniform[ uniform.name ] = uniform;
this.uniforms[ uniform.name ] = uniform;
return uniform;
};
THREE.NodeMaterial.prototype.getDataNode = function( uuid ) {
return this.nodeData[ uuid ] = this.nodeData[ uuid ] || {};
};
THREE.NodeMaterial.prototype.include = function( builder, node, parent, source ) {
var includes;
node = typeof node === 'string' ? THREE.NodeLib.get( node ) : node;
if ( node instanceof THREE.FunctionNode ) {
includes = this.functions[ builder.shader ] = this.functions[ builder.shader ] || [];
} else if ( node instanceof THREE.ConstNode ) {
includes = this.consts[ builder.shader ] = this.consts[ builder.shader ] || [];
}
var included = includes[ node.name ];
if ( ! included ) {
included = includes[ node.name ] = {
node : node,
deps : []
};
includes.push( included );
included.src = node.build( builder, 'source' );
}
if ( node instanceof THREE.FunctionNode && parent && includes[ parent.name ] && includes[ parent.name ].deps.indexOf( node ) == - 1 ) {
includes[ parent.name ].deps.push( node );
if ( node.includes && node.includes.length ) {
var i = 0;
do {
this.include( builder, node.includes[ i ++ ], parent );
} while ( i < node.includes.length );
}
}
if ( source ) {
included.src = source;
}
};

36
node_modules/three/examples/js/nodes/RawNode.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.RawNode = function( value ) {
THREE.GLNode.call( this, 'v4' );
this.value = value;
};
THREE.RawNode.prototype = Object.create( THREE.GLNode.prototype );
THREE.RawNode.prototype.constructor = THREE.RawNode;
THREE.GLNode.prototype.generate = function( builder ) {
var material = builder.material;
var data = this.value.parseAndBuildCode( builder, this.type );
var code = data.code + '\n';
if ( builder.shader == 'vertex' ) {
code += 'gl_Position = ' + data.result + ';';
} else {
code += 'gl_FragColor = ' + data.result + ';';
}
return code;
};

134
node_modules/three/examples/js/nodes/TempNode.js generated vendored Normal file
View File

@@ -0,0 +1,134 @@
/**
* Automatic node cache
* @author sunag / http://www.sunag.com.br/
*/
THREE.TempNode = function( type, params ) {
THREE.GLNode.call( this, type );
params = params || {};
this.shared = params.shared !== undefined ? params.shared : true;
this.unique = params.unique !== undefined ? params.unique : false;
};
THREE.TempNode.prototype = Object.create( THREE.GLNode.prototype );
THREE.TempNode.prototype.constructor = THREE.TempNode;
THREE.TempNode.prototype.build = function( builder, output, uuid, ns ) {
output = output || this.getType( builder );
var material = builder.material;
if ( this.isShared( builder, output ) ) {
var isUnique = this.isUnique( builder, output );
if ( isUnique && this.constructor.uuid === undefined ) {
this.constructor.uuid = THREE.Math.generateUUID();
}
uuid = builder.getUuid( uuid || this.getUuid(), ! isUnique );
var data = material.getDataNode( uuid );
if ( builder.parsing ) {
if ( data.deps || 0 > 0 ) {
this.appendDepsNode( builder, data, output );
return this.generate( builder, type, uuid );
}
return THREE.GLNode.prototype.build.call( this, builder, output, uuid );
} else if ( isUnique ) {
data.name = data.name || THREE.GLNode.prototype.build.call( this, builder, output, uuid );
return data.name;
} else if ( ! builder.optimize || data.deps == 1 ) {
return THREE.GLNode.prototype.build.call( this, builder, output, uuid );
}
uuid = this.getUuid( false );
var name = this.getTemp( builder, uuid );
var type = data.output || this.getType( builder );
if ( name ) {
return builder.format( name, type, output );
} else {
name = THREE.TempNode.prototype.generate.call( this, builder, output, uuid, data.output, ns );
var code = this.generate( builder, type, uuid );
if ( builder.isShader( 'vertex' ) ) material.addVertexNode( name + '=' + code + ';' );
else material.addFragmentNode( name + '=' + code + ';' );
return builder.format( name, type, output );
}
}
return THREE.GLNode.prototype.build.call( this, builder, output, uuid );
};
THREE.TempNode.prototype.isShared = function( builder, output ) {
return output !== 'sampler2D' && output !== 'samplerCube' && this.shared;
};
THREE.TempNode.prototype.isUnique = function( builder, output ) {
return this.unique;
};
THREE.TempNode.prototype.getUuid = function( unique ) {
var uuid = unique || unique == undefined ? this.constructor.uuid || this.uuid : this.uuid;
if ( typeof this.scope == "string" ) uuid = this.scope + '-' + uuid;
return uuid;
};
THREE.TempNode.prototype.getTemp = function( builder, uuid ) {
uuid = uuid || this.uuid;
var material = builder.material;
if ( builder.isShader( 'vertex' ) && material.vertexTemps[ uuid ] ) return material.vertexTemps[ uuid ].name;
else if ( material.fragmentTemps[ uuid ] ) return material.fragmentTemps[ uuid ].name;
};
THREE.TempNode.prototype.generate = function( builder, output, uuid, type, ns ) {
if ( ! this.isShared( builder, output ) ) console.error( "THREE.TempNode is not shared!" );
uuid = uuid || this.uuid;
if ( builder.isShader( 'vertex' ) ) return builder.material.getVertexTemp( uuid, type || this.getType( builder ), ns ).name;
else return builder.material.getFragmentTemp( uuid, type || this.getType( builder ), ns ).name;
};

26
node_modules/three/examples/js/nodes/VarNode.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.VarNode = function( type ) {
THREE.GLNode.call( this, type );
};
THREE.VarNode.prototype = Object.create( THREE.GLNode.prototype );
THREE.VarNode.prototype.constructor = THREE.VarNode;
THREE.VarNode.prototype.getType = function( builder ) {
return builder.getTypeByFormat( this.type );
};
THREE.VarNode.prototype.generate = function( builder, output ) {
var varying = builder.material.getVar( this.uuid, this.type );
return builder.format( varying.name, this.getType( builder ), output );
};

View File

@@ -0,0 +1,149 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.CameraNode = function( scope, camera ) {
THREE.TempNode.call( this, 'v3' );
this.setScope( scope || THREE.CameraNode.POSITION );
this.setCamera( camera );
};
THREE.CameraNode.fDepthColor = new THREE.FunctionNode( [
"float depthColor( float mNear, float mFar ) {",
" #ifdef USE_LOGDEPTHBUF_EXT",
" float depth = gl_FragDepthEXT / gl_FragCoord.w;",
" #else",
" float depth = gl_FragCoord.z / gl_FragCoord.w;",
" #endif",
" return 1.0 - smoothstep( mNear, mFar, depth );",
"}"
].join( "\n" ) );
THREE.CameraNode.POSITION = 'position';
THREE.CameraNode.DEPTH = 'depth';
THREE.CameraNode.TO_VERTEX = 'toVertex';
THREE.CameraNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.CameraNode.prototype.constructor = THREE.CameraNode;
THREE.CameraNode.prototype.setCamera = function( camera ) {
this.camera = camera;
this.requestUpdate = camera !== undefined;
};
THREE.CameraNode.prototype.setScope = function( scope ) {
switch ( this.scope ) {
case THREE.CameraNode.DEPTH:
delete this.near;
delete this.far;
break;
}
this.scope = scope;
switch ( scope ) {
case THREE.CameraNode.DEPTH:
this.near = new THREE.FloatNode( camera ? camera.near : 1 );
this.far = new THREE.FloatNode( camera ? camera.far : 1200 );
break;
}
};
THREE.CameraNode.prototype.getType = function( builder ) {
switch ( this.scope ) {
case THREE.CameraNode.DEPTH:
return 'fv1';
}
return this.type;
};
THREE.CameraNode.prototype.isUnique = function( builder ) {
switch ( this.scope ) {
case THREE.CameraNode.DEPTH:
case THREE.CameraNode.TO_VERTEX:
return true;
}
return false;
};
THREE.CameraNode.prototype.isShared = function( builder ) {
switch ( this.scope ) {
case THREE.CameraNode.POSITION:
return false;
}
return true;
};
THREE.CameraNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var result;
switch ( this.scope ) {
case THREE.CameraNode.POSITION:
result = 'cameraPosition';
break;
case THREE.CameraNode.DEPTH:
var func = THREE.CameraNode.fDepthColor;
builder.include( func );
result = func.name + '(' + this.near.build( builder, 'fv1' ) + ',' + this.far.build( builder, 'fv1' ) + ')';
break;
case THREE.CameraNode.TO_VERTEX:
result = 'normalize( ' + new THREE.PositionNode( THREE.PositionNode.WORLD ).build( builder, 'v3' ) + ' - cameraPosition )';
break;
}
return builder.format( result, this.getType( builder ), output );
};
THREE.CameraNode.prototype.updateFrame = function( delta ) {
switch ( this.scope ) {
case THREE.CameraNode.DEPTH:
this.near.number = camera.near;
this.far.number = camera.far;
break;
}
};

View File

@@ -0,0 +1,31 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ColorsNode = function( index ) {
THREE.TempNode.call( this, 'v4', { shared: false } );
this.index = index || 0;
};
THREE.ColorsNode.vertexDict = [ 'color', 'color2' ];
THREE.ColorsNode.fragmentDict = [ 'vColor', 'vColor2' ];
THREE.ColorsNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.ColorsNode.prototype.constructor = THREE.ColorsNode;
THREE.ColorsNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var result;
material.requestAttribs.color[ this.index ] = true;
if ( builder.isShader( 'vertex' ) ) result = THREE.ColorsNode.vertexDict[ this.index ];
else result = THREE.ColorsNode.fragmentDict[ this.index ];
return builder.format( result, this.getType( builder ), output );
};

View File

@@ -0,0 +1,28 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.LightNode = function() {
THREE.TempNode.call( this, 'v3', { shared: false } );
};
THREE.LightNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.LightNode.prototype.constructor = THREE.LightNode;
THREE.LightNode.prototype.generate = function( builder, output ) {
if ( builder.isCache( 'light' ) ) {
return builder.format( 'reflectedLight.directDiffuse', this.getType( builder ), output )
} else {
console.warn( "THREE.LightNode is only compatible in \"light\" channel." );
return builder.format( 'vec3( 0.0 )', this.getType( builder ), output );
}
};

View File

@@ -0,0 +1,66 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.NormalNode = function( scope ) {
THREE.TempNode.call( this, 'v3' );
this.scope = scope || THREE.NormalNode.LOCAL;
};
THREE.NormalNode.LOCAL = 'local';
THREE.NormalNode.WORLD = 'world';
THREE.NormalNode.VIEW = 'view';
THREE.NormalNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.NormalNode.prototype.constructor = THREE.NormalNode;
THREE.NormalNode.prototype.isShared = function( builder ) {
switch ( this.scope ) {
case THREE.NormalNode.WORLD:
return true;
}
return false;
};
THREE.NormalNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var result;
switch ( this.scope ) {
case THREE.NormalNode.LOCAL:
material.requestAttribs.normal = true;
if ( builder.isShader( 'vertex' ) ) result = 'normal';
else result = 'vObjectNormal';
break;
case THREE.NormalNode.WORLD:
material.requestAttribs.worldNormal = true;
if ( builder.isShader( 'vertex' ) ) result = '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';
else result = 'vWNormal';
break;
case THREE.NormalNode.VIEW:
result = 'vNormal';
break;
}
return builder.format( result, this.getType( builder ), output );
};

View File

@@ -0,0 +1,87 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.PositionNode = function( scope ) {
THREE.TempNode.call( this, 'v3' );
this.scope = scope || THREE.PositionNode.LOCAL;
};
THREE.PositionNode.LOCAL = 'local';
THREE.PositionNode.WORLD = 'world';
THREE.PositionNode.VIEW = 'view';
THREE.PositionNode.PROJECTION = 'projection';
THREE.PositionNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.PositionNode.prototype.constructor = THREE.PositionNode;
THREE.PositionNode.prototype.getType = function( builder ) {
switch ( this.scope ) {
case THREE.PositionNode.PROJECTION:
return 'v4';
}
return this.type;
};
THREE.PositionNode.prototype.isShared = function( builder ) {
switch ( this.scope ) {
case THREE.PositionNode.LOCAL:
case THREE.PositionNode.WORLD:
return false;
}
return true;
};
THREE.PositionNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var result;
switch ( this.scope ) {
case THREE.PositionNode.LOCAL:
material.requestAttribs.position = true;
if ( builder.isShader( 'vertex' ) ) result = 'transformed';
else result = 'vPosition';
break;
case THREE.PositionNode.WORLD:
material.requestAttribs.worldPosition = true;
if ( builder.isShader( 'vertex' ) ) result = 'vWPosition';
else result = 'vWPosition';
break;
case THREE.PositionNode.VIEW:
if ( builder.isShader( 'vertex' ) ) result = '-mvPosition.xyz';
else result = 'vViewPosition';
break;
case THREE.PositionNode.PROJECTION:
if ( builder.isShader( 'vertex' ) ) result = '(projectionMatrix * modelViewMatrix * vec4( position, 1.0 ))';
else result = 'vec4( 0.0 )';
break;
}
return builder.format( result, this.getType( builder ), output );
};

View File

@@ -0,0 +1,68 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ReflectNode = function( scope ) {
THREE.TempNode.call( this, 'v3', { unique: true } );
this.scope = scope || THREE.ReflectNode.CUBE;
};
THREE.ReflectNode.CUBE = 'cube';
THREE.ReflectNode.SPHERE = 'sphere';
THREE.ReflectNode.VECTOR = 'vector';
THREE.ReflectNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.ReflectNode.prototype.constructor = THREE.ReflectNode;
THREE.ReflectNode.prototype.getType = function( builder ) {
switch ( this.scope ) {
case THREE.ReflectNode.SPHERE:
return 'v2';
}
return this.type;
};
THREE.ReflectNode.prototype.generate = function( builder, output ) {
var result;
switch ( this.scope ) {
case THREE.ReflectNode.VECTOR:
builder.material.addFragmentNode( 'vec3 reflectVec = inverseTransformDirection( reflect( -normalize( vViewPosition ), normal ), viewMatrix );' );
result = 'reflectVec';
break;
case THREE.ReflectNode.CUBE:
var reflectVec = new THREE.ReflectNode( THREE.ReflectNode.VECTOR ).build( builder, 'v3' );
builder.material.addFragmentNode( 'vec3 reflectCubeVec = vec3( -1.0 * ' + reflectVec + '.x, ' + reflectVec + '.yz );' );
result = 'reflectCubeVec';
break;
case THREE.ReflectNode.SPHERE:
var reflectVec = new THREE.ReflectNode( THREE.ReflectNode.VECTOR ).build( builder, 'v3' );
builder.material.addFragmentNode( 'vec2 reflectSphereVec = normalize((viewMatrix * vec4(' + reflectVec + ', 0.0 )).xyz + vec3(0.0,0.0,1.0)).xy * 0.5 + 0.5;' );
result = 'reflectSphereVec';
break;
}
return builder.format( result, this.getType( this.type ), output );
};

View File

@@ -0,0 +1,35 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ScreenUVNode = function( resolution ) {
THREE.TempNode.call( this, 'v2' );
this.resolution = resolution;
};
THREE.ScreenUVNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.ScreenUVNode.prototype.constructor = THREE.ScreenUVNode;
THREE.ScreenUVNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var result;
if ( builder.isShader( 'fragment' ) ) {
result = '(gl_FragCoord.xy/' + this.resolution.build( builder, 'v2' ) + ')';
} else {
console.warn( "THREE.ScreenUVNode is not compatible with " + builder.shader + " shader." );
result = 'vec2( 0.0 )';
}
return builder.format( result, this.getType( builder ), output );
};

View File

@@ -0,0 +1,31 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.UVNode = function( index ) {
THREE.TempNode.call( this, 'v2', { shared: false } );
this.index = index || 0;
};
THREE.UVNode.vertexDict = [ 'uv', 'uv2' ];
THREE.UVNode.fragmentDict = [ 'vUv', 'vUv2' ];
THREE.UVNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.UVNode.prototype.constructor = THREE.UVNode;
THREE.UVNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var result;
material.requestAttribs.uv[ this.index ] = true;
if ( builder.isShader( 'vertex' ) ) result = THREE.UVNode.vertexDict[ this.index ];
else result = THREE.UVNode.fragmentDict[ this.index ];
return builder.format( result, this.getType( builder ), output );
};

View File

@@ -0,0 +1,16 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ColorNode = function( color ) {
THREE.InputNode.call( this, 'c' );
this.value = new THREE.Color( color || 0 );
};
THREE.ColorNode.prototype = Object.create( THREE.InputNode.prototype );
THREE.ColorNode.prototype.constructor = THREE.ColorNode;
THREE.NodeMaterial.addShortcuts( THREE.ColorNode.prototype, 'value', [ 'r', 'g', 'b' ] );

View File

@@ -0,0 +1,63 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.CubeTextureNode = function( value, coord, bias ) {
THREE.InputNode.call( this, 'v4', { shared : true } );
this.value = value;
this.coord = coord || new THREE.ReflectNode();
this.bias = bias;
};
THREE.CubeTextureNode.prototype = Object.create( THREE.InputNode.prototype );
THREE.CubeTextureNode.prototype.constructor = THREE.CubeTextureNode;
THREE.CubeTextureNode.prototype.getTexture = function( builder, output ) {
return THREE.InputNode.prototype.generate.call( this, builder, output, this.value.uuid, 't' );
};
THREE.CubeTextureNode.prototype.generate = function( builder, output ) {
if ( output === 'samplerCube' ) {
return this.getTexture( 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;
if ( bias == undefined && builder.requires.bias ) {
bias = builder.requires.bias.build( builder, 'fv1' );
}
var code;
if ( bias ) code = 'texCubeBias(' + cubetex + ',' + coord + ',' + bias + ')';
else code = 'texCube(' + cubetex + ',' + coord + ')';
if ( builder.isSlot( 'color' ) ) {
code = 'mapTexelToLinear(' + code + ')';
} else if ( builder.isSlot( 'emissive' ) ) {
code = 'emissiveMapTexelToLinear(' + code + ')';
} else if ( builder.isSlot( 'environment' ) ) {
code = 'envMapTexelToLinear(' + code + ')';
}
return builder.format( code, this.type, output );
};

View File

@@ -0,0 +1,29 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.FloatNode = function( value ) {
THREE.InputNode.call( this, 'fv1' );
this.value = [ value || 0 ];
};
THREE.FloatNode.prototype = Object.create( THREE.InputNode.prototype );
THREE.FloatNode.prototype.constructor = THREE.FloatNode;
Object.defineProperties( THREE.FloatNode.prototype, {
number: {
get: function() {
return this.value[ 0 ];
},
set: function( val ) {
this.value[ 0 ] = val;
}
}
} );

29
node_modules/three/examples/js/nodes/inputs/IntNode.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.IntNode = function( value ) {
THREE.InputNode.call( this, 'iv1' );
this.value = [ Math.floor( value || 0 ) ];
};
THREE.IntNode.prototype = Object.create( THREE.InputNode.prototype );
THREE.IntNode.prototype.constructor = THREE.IntNode;
Object.defineProperties( THREE.IntNode.prototype, {
number: {
get: function() {
return this.value[ 0 ];
},
set: function( val ) {
this.value[ 0 ] = Math.floor( val );
}
}
} );

View File

@@ -0,0 +1,14 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.Matrix4Node = function( matrix ) {
THREE.InputNode.call( this, 'm4' );
this.value = matrix || new THREE.Matrix4();
};
THREE.Matrix4Node.prototype = Object.create( THREE.InputNode.prototype );
THREE.Matrix4Node.prototype.constructor = THREE.Matrix4Node;

View File

@@ -0,0 +1,46 @@
THREE.MirrorNode = function( renderer, camera, options ) {
THREE.TempNode.call( this, 'v4' );
this.mirror = renderer instanceof THREE.Mirror ? renderer : new THREE.Mirror( renderer, camera, options );
this.textureMatrix = new THREE.Matrix4Node( this.mirror.textureMatrix );
this.worldPosition = new THREE.PositionNode( THREE.PositionNode.WORLD );
this.coord = new THREE.OperatorNode( this.textureMatrix, this.worldPosition, THREE.OperatorNode.MUL );
this.coordResult = new THREE.OperatorNode( null, this.coord, THREE.OperatorNode.ADD );
this.texture = new THREE.TextureNode( this.mirror.renderTarget.texture, this.coord, null, true );
};
THREE.MirrorNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.MirrorNode.prototype.constructor = THREE.MirrorNode;
THREE.MirrorNode.prototype.generate = function( builder, output ) {
var material = builder.material;
if ( builder.isShader( 'fragment' ) ) {
this.coordResult.a = this.offset;
this.texture.coord = this.offset ? this.coordResult : this.coord;
if ( output === 'sampler2D' ) {
return this.texture.build( builder, output );
}
return builder.format( this.texture.build( builder, this.type ), this.type, output );
} else {
console.warn( "THREE.MirrorNode is not compatible with " + builder.shader + " shader." );
return builder.format( 'vec4(0.0)', this.type, output );
}
};

View File

@@ -0,0 +1,24 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ScreenNode = function( coord ) {
THREE.TextureNode.call( this, undefined, coord );
};
THREE.ScreenNode.prototype = Object.create( THREE.TextureNode.prototype );
THREE.ScreenNode.prototype.constructor = THREE.ScreenNode;
THREE.ScreenNode.prototype.isUnique = function() {
return true;
};
THREE.ScreenNode.prototype.getTexture = function( builder, output ) {
return THREE.InputNode.prototype.generate.call( this, builder, output, this.getUuid(), 't', 'renderTexture' );
};

View File

@@ -0,0 +1,67 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.TextureNode = function( value, coord, bias, project ) {
THREE.InputNode.call( this, 'v4', { shared : true } );
this.value = value;
this.coord = coord || new THREE.UVNode();
this.bias = bias;
this.project = project !== undefined ? project : false;
};
THREE.TextureNode.prototype = Object.create( THREE.InputNode.prototype );
THREE.TextureNode.prototype.constructor = THREE.TextureNode;
THREE.TextureNode.prototype.getTexture = function( builder, output ) {
return THREE.InputNode.prototype.generate.call( this, builder, output, this.value.uuid, 't' );
};
THREE.TextureNode.prototype.generate = function( builder, output ) {
if ( output === 'sampler2D' ) {
return this.getTexture( builder, output );
}
var tex = this.getTexture( builder, output );
var coord = this.coord.build( builder, this.project ? 'v4' : '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 method, code;
if ( this.project ) method = 'texture2DProj';
else method = bias ? 'tex2DBias' : 'tex2D';
if ( bias ) code = method + '(' + tex + ',' + coord + ',' + bias + ')';
else code = method + '(' + tex + ',' + coord + ')';
if ( builder.isSlot( 'color' ) ) {
code = 'mapTexelToLinear(' + code + ')';
} else if ( builder.isSlot( 'emissive' ) ) {
code = 'emissiveMapTexelToLinear(' + code + ')';
} else if ( builder.isSlot( 'environment' ) ) {
code = 'envMapTexelToLinear(' + code + ')';
}
return builder.format( code, this.type, output );
};

View File

@@ -0,0 +1,16 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.Vector2Node = function( x, y ) {
THREE.InputNode.call( this, 'v2' );
this.value = new THREE.Vector2( x, y );
};
THREE.Vector2Node.prototype = Object.create( THREE.InputNode.prototype );
THREE.Vector2Node.prototype.constructor = THREE.Vector2Node;
THREE.NodeMaterial.addShortcuts( THREE.Vector2Node.prototype, 'value', [ 'x', 'y' ] );

View File

@@ -0,0 +1,17 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.Vector3Node = function( x, y, z ) {
THREE.InputNode.call( this, 'v3' );
this.type = 'v3';
this.value = new THREE.Vector3( x, y, z );
};
THREE.Vector3Node.prototype = Object.create( THREE.InputNode.prototype );
THREE.Vector3Node.prototype.constructor = THREE.Vector3Node;
THREE.NodeMaterial.addShortcuts( THREE.Vector3Node.prototype, 'value', [ 'x', 'y', 'z' ] );

View File

@@ -0,0 +1,16 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.Vector4Node = function( x, y, z, w ) {
THREE.InputNode.call( this, 'v4' );
this.value = new THREE.Vector4( x, y, z, w );
};
THREE.Vector4Node.prototype = Object.create( THREE.InputNode.prototype );
THREE.Vector4Node.prototype.constructor = THREE.Vector4Node;
THREE.NodeMaterial.addShortcuts( THREE.Vector4Node.prototype, 'value', [ 'x', 'y', 'z', 'w' ] );

View File

@@ -0,0 +1,312 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.PhongNode = function() {
THREE.GLNode.call( this );
this.color = new THREE.ColorNode( 0xEEEEEE );
this.specular = new THREE.ColorNode( 0x111111 );
this.shininess = new THREE.FloatNode( 30 );
};
THREE.PhongNode.prototype = Object.create( THREE.GLNode.prototype );
THREE.PhongNode.prototype.constructor = THREE.PhongNode;
THREE.PhongNode.prototype.build = function( builder ) {
var material = builder.material;
var code;
material.define( 'PHONG' );
material.define( 'ALPHATEST', '0.0' );
material.requestAttribs.light = true;
if ( builder.isShader( 'vertex' ) ) {
var transform = this.transform ? this.transform.parseAndBuildCode( builder, 'v3', { cache : 'transform' } ) : undefined;
material.mergeUniform( THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "fog" ],
THREE.UniformsLib[ "lights" ]
] ) );
material.addVertexPars( [
"varying vec3 vViewPosition;",
"#ifndef FLAT_SHADED",
" varying vec3 vNormal;",
"#endif",
THREE.ShaderChunk[ "common" ],
THREE.ShaderChunk[ "fog_parse_vertex" ],
THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
THREE.ShaderChunk[ "skinning_pars_vertex" ],
THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ]
].join( "\n" ) );
var output = [
THREE.ShaderChunk[ "beginnormal_vertex" ],
THREE.ShaderChunk[ "morphnormal_vertex" ],
THREE.ShaderChunk[ "skinbase_vertex" ],
THREE.ShaderChunk[ "skinnormal_vertex" ],
THREE.ShaderChunk[ "defaultnormal_vertex" ],
"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
" vNormal = normalize( transformedNormal );",
"#endif",
THREE.ShaderChunk[ "begin_vertex" ],
THREE.ShaderChunk[ "fog_vertex" ]
];
if ( transform ) {
output.push(
transform.code,
"transformed = " + transform.result + ";"
);
}
output.push(
THREE.ShaderChunk[ "morphtarget_vertex" ],
THREE.ShaderChunk[ "skinning_vertex" ],
THREE.ShaderChunk[ "project_vertex" ],
THREE.ShaderChunk[ "logdepthbuf_vertex" ],
" vViewPosition = - mvPosition.xyz;",
THREE.ShaderChunk[ "worldpos_vertex" ],
THREE.ShaderChunk[ "shadowmap_vertex" ]
);
code = output.join( "\n" );
} else {
// parse all nodes to reuse generate codes
this.color.parse( builder, { slot : 'color' } );
this.specular.parse( builder );
this.shininess.parse( builder );
if ( this.alpha ) this.alpha.parse( builder );
if ( this.normal ) this.normal.parse( builder );
if ( this.normalScale && this.normal ) this.normalScale.parse( builder );
if ( this.light ) this.light.parse( builder, { cache : 'light' } );
if ( this.ao ) this.ao.parse( builder );
if ( this.ambient ) this.ambient.parse( builder );
if ( this.shadow ) this.shadow.parse( builder );
if ( this.emissive ) this.emissive.parse( builder, { slot : 'emissive' } );
if ( this.environment ) this.environment.parse( builder, { slot : 'environment' } );
if ( this.environmentAlpha && this.environment ) this.environmentAlpha.parse( builder );
// build code
var color = this.color.buildCode( builder, 'c', { slot : 'color' } );
var specular = this.specular.buildCode( builder, 'c' );
var shininess = this.shininess.buildCode( builder, 'fv1' );
var alpha = this.alpha ? this.alpha.buildCode( builder, 'fv1' ) : undefined;
var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : undefined;
var normalScale = this.normalScale && this.normal ? this.normalScale.buildCode( builder, 'v2' ) : undefined;
var light = this.light ? this.light.buildCode( builder, 'v3', { cache : 'light' } ) : undefined;
var ao = this.ao ? this.ao.buildCode( builder, 'fv1' ) : undefined;
var ambient = this.ambient ? this.ambient.buildCode( builder, 'c' ) : undefined;
var shadow = this.shadow ? this.shadow.buildCode( builder, 'c' ) : undefined;
var emissive = this.emissive ? this.emissive.buildCode( builder, 'c', { slot : 'emissive' } ) : undefined;
var environment = this.environment ? this.environment.buildCode( builder, 'c', { slot : 'environment' } ) : undefined;
var environmentAlpha = this.environmentAlpha && this.environment ? this.environmentAlpha.buildCode( builder, 'fv1' ) : undefined;
material.requestAttribs.transparent = alpha != undefined;
material.addFragmentPars( [
THREE.ShaderChunk[ "common" ],
THREE.ShaderChunk[ "fog_pars_fragment" ],
THREE.ShaderChunk[ "bsdfs" ],
THREE.ShaderChunk[ "lights_pars" ],
THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ]
].join( "\n" ) );
var output = [
// prevent undeclared normal
THREE.ShaderChunk[ "normal_flip" ],
THREE.ShaderChunk[ "normal_fragment" ],
// prevent undeclared material
" BlinnPhongMaterial material;",
color.code,
" vec3 diffuseColor = " + color.result + ";",
" ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
THREE.ShaderChunk[ "logdepthbuf_fragment" ],
specular.code,
" vec3 specular = " + specular.result + ";",
shininess.code,
" float shininess = max(0.0001," + shininess.result + ");",
" float specularStrength = 1.0;" // Ignored in MaterialNode ( replace to specular )
];
if ( alpha ) {
output.push(
alpha.code,
'if ( ' + alpha.result + ' <= ALPHATEST ) discard;'
);
}
if ( normal ) {
builder.include( 'perturbNormal2Arb' );
output.push( normal.code );
if ( normalScale ) output.push( normalScale.code );
output.push(
'normal = perturbNormal2Arb(-vViewPosition,normal,' +
normal.result + ',' +
new THREE.UVNode().build( builder, 'v2' ) + ',' +
( normalScale ? normalScale.result : 'vec2( 1.0 )' ) + ');'
);
}
// optimization for now
output.push( 'material.diffuseColor = ' + ( light ? 'vec3( 1.0 )' : 'diffuseColor' ) + ';' );
output.push(
// accumulation
'material.specularColor = specular;',
'material.specularShininess = shininess;',
'material.specularStrength = specularStrength;',
THREE.ShaderChunk[ "lights_template" ]
);
if ( light ) {
output.push(
light.code,
"reflectedLight.directDiffuse = " + light.result + ";"
);
// apply color
output.push(
"reflectedLight.directDiffuse *= diffuseColor;",
"reflectedLight.indirectDiffuse *= diffuseColor;"
);
}
if ( ao ) {
output.push(
ao.code,
"reflectedLight.indirectDiffuse *= " + ao.result + ";"
);
}
if ( ambient ) {
output.push(
ambient.code,
"reflectedLight.indirectDiffuse += " + ambient.result + ";"
);
}
if ( shadow ) {
output.push(
shadow.code,
"reflectedLight.directDiffuse *= " + shadow.result + ";",
"reflectedLight.directSpecular *= " + shadow.result + ";"
);
}
if ( emissive ) {
output.push(
emissive.code,
"reflectedLight.directDiffuse += " + emissive.result + ";"
);
}
output.push( "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular;" );
if ( environment ) {
output.push( environment.code );
if ( environmentAlpha ) {
output.push(
environmentAlpha.code,
"outgoingLight = mix( outgoingLight, " + environment.result + ", " + environmentAlpha.result + " );"
);
} else {
output.push( "outgoingLight = " + environment.result + ";" );
}
}
if ( alpha ) {
output.push( "gl_FragColor = vec4( outgoingLight, " + alpha.result + " );" );
} else {
output.push( "gl_FragColor = vec4( outgoingLight, 1.0 );" );
}
output.push(
THREE.ShaderChunk[ "premultiplied_alpha_fragment" ],
THREE.ShaderChunk[ "tonemapping_fragment" ],
THREE.ShaderChunk[ "encodings_fragment" ],
THREE.ShaderChunk[ "fog_fragment" ]
);
code = output.join( "\n" );
}
return code;
};

View File

@@ -0,0 +1,17 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.PhongNodeMaterial = function() {
this.node = new THREE.PhongNode();
THREE.NodeMaterial.call( this, this.node, this.node );
};
THREE.PhongNodeMaterial.prototype = Object.create( THREE.NodeMaterial.prototype );
THREE.PhongNodeMaterial.prototype.constructor = THREE.PhongNodeMaterial;
THREE.NodeMaterial.addShortcuts( THREE.PhongNodeMaterial.prototype, 'node',
[ 'color', 'alpha', 'specular', 'shininess', 'normal', 'normalScale', 'emissive', 'ambient', 'light', 'shadow', 'ao', 'environment', 'environmentAlpha', 'transform' ] );

View File

@@ -0,0 +1,392 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.StandardNode = function() {
THREE.GLNode.call( this );
this.color = new THREE.ColorNode( 0xEEEEEE );
this.roughness = new THREE.FloatNode( 0.5 );
this.metalness = new THREE.FloatNode( 0.5 );
};
THREE.StandardNode.prototype = Object.create( THREE.GLNode.prototype );
THREE.StandardNode.prototype.constructor = THREE.StandardNode;
THREE.StandardNode.prototype.build = function( builder ) {
var material = builder.material;
var code;
material.define( 'PHYSICAL' );
if ( !this.clearCoat && !this.clearCoatRoughness ) material.define( 'STANDARD' );
material.define( 'ALPHATEST', '0.0' );
material.requestAttribs.light = true;
material.extensions.shaderTextureLOD = true;
if ( builder.isShader( 'vertex' ) ) {
var transform = this.transform ? this.transform.parseAndBuildCode( builder, 'v3', { cache : 'transform' } ) : undefined;
material.mergeUniform( THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "fog" ],
THREE.UniformsLib[ "lights" ]
] ) );
material.addVertexPars( [
"varying vec3 vViewPosition;",
"#ifndef FLAT_SHADED",
" varying vec3 vNormal;",
"#endif",
THREE.ShaderChunk[ "common" ],
THREE.ShaderChunk[ "fog_pars_vertex" ],
THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
THREE.ShaderChunk[ "skinning_pars_vertex" ],
THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ]
].join( "\n" ) );
var output = [
THREE.ShaderChunk[ "beginnormal_vertex" ],
THREE.ShaderChunk[ "morphnormal_vertex" ],
THREE.ShaderChunk[ "skinbase_vertex" ],
THREE.ShaderChunk[ "skinnormal_vertex" ],
THREE.ShaderChunk[ "defaultnormal_vertex" ],
"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
" vNormal = normalize( transformedNormal );",
"#endif",
THREE.ShaderChunk[ "begin_vertex" ],
THREE.ShaderChunk[ "fog_vertex" ]
];
if ( transform ) {
output.push(
transform.code,
"transformed = " + transform.result + ";"
);
}
output.push(
THREE.ShaderChunk[ "morphtarget_vertex" ],
THREE.ShaderChunk[ "skinning_vertex" ],
THREE.ShaderChunk[ "project_vertex" ],
THREE.ShaderChunk[ "logdepthbuf_vertex" ],
" vViewPosition = - mvPosition.xyz;",
THREE.ShaderChunk[ "worldpos_vertex" ],
THREE.ShaderChunk[ "shadowmap_vertex" ]
);
code = output.join( "\n" );
} else {
// blur textures for PBR effect
var requires = {
bias : new THREE.RoughnessToBlinnExponentNode(),
offsetU : 0,
offsetV : 0
};
var useClearCoat = !material.isDefined( 'STANDARD' );
// parse all nodes to reuse generate codes
this.color.parse( builder, { slot : 'color' } );
this.roughness.parse( builder );
this.metalness.parse( builder );
if ( this.alpha ) this.alpha.parse( builder );
if ( this.normal ) this.normal.parse( builder );
if ( this.normalScale && this.normal ) this.normalScale.parse( builder );
if (this.clearCoat) this.clearCoat.parse( builder );
if (this.clearCoatRoughness) this.clearCoatRoughness.parse( builder );
if ( this.reflectivity ) this.reflectivity.parse( builder );
if ( this.light ) this.light.parse( builder, { cache : 'light' } );
if ( this.ao ) this.ao.parse( builder );
if ( this.ambient ) this.ambient.parse( builder );
if ( this.shadow ) this.shadow.parse( builder );
if ( this.emissive ) this.emissive.parse( builder, { slot : 'emissive' } );
if ( this.environment ) this.environment.parse( builder, { cache : 'env', requires : requires, slot : 'environment' } ); // isolate environment from others inputs ( see TextureNode, CubeTextureNode )
// build code
var color = this.color.buildCode( builder, 'c', { slot : 'color' } );
var roughness = this.roughness.buildCode( builder, 'fv1' );
var metalness = this.metalness.buildCode( builder, 'fv1' );
var alpha = this.alpha ? this.alpha.buildCode( builder, 'fv1' ) : undefined;
var normal = this.normal ? this.normal.buildCode( builder, 'v3' ) : undefined;
var normalScale = this.normalScale && this.normal ? this.normalScale.buildCode( builder, 'v2' ) : undefined;
var clearCoat = this.clearCoat ? this.clearCoat.buildCode( builder, 'fv1' ) : undefined;
var clearCoatRoughness = this.clearCoatRoughness ? this.clearCoatRoughness.buildCode( builder, 'fv1' ) : undefined;
var reflectivity = this.reflectivity ? this.reflectivity.buildCode( builder, 'fv1' ) : undefined;
var light = this.light ? this.light.buildCode( builder, 'v3', { cache : 'light' } ) : undefined;
var ao = this.ao ? this.ao.buildCode( builder, 'fv1' ) : undefined;
var ambient = this.ambient ? this.ambient.buildCode( builder, 'c' ) : undefined;
var shadow = this.shadow ? this.shadow.buildCode( builder, 'c' ) : undefined;
var emissive = this.emissive ? this.emissive.buildCode( builder, 'c', { slot : 'emissive' } ) : undefined;
var environment = this.environment ? this.environment.buildCode( builder, 'c', { cache : 'env', requires : requires, slot : 'environment' } ) : undefined;
var clearCoatEnv = useClearCoat && environment ? this.environment.buildCode( builder, 'c', { cache : 'clearCoat', requires : requires, slot : 'environment' } ) : undefined;
material.requestAttribs.transparent = alpha != undefined;
material.addFragmentPars( [
"varying vec3 vViewPosition;",
"#ifndef FLAT_SHADED",
" varying vec3 vNormal;",
"#endif",
THREE.ShaderChunk[ "common" ],
THREE.ShaderChunk[ "fog_pars_fragment" ],
THREE.ShaderChunk[ "bsdfs" ],
THREE.ShaderChunk[ "lights_pars" ],
THREE.ShaderChunk[ "lights_physical_pars_fragment" ],
THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ]
].join( "\n" ) );
var output = [
// prevent undeclared normal
THREE.ShaderChunk[ "normal_flip" ],
THREE.ShaderChunk[ "normal_fragment" ],
// prevent undeclared material
" PhysicalMaterial material;",
" material.diffuseColor = vec3( 1.0 );",
color.code,
" vec3 diffuseColor = " + color.result + ";",
" ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
THREE.ShaderChunk[ "logdepthbuf_fragment" ],
roughness.code,
" float roughnessFactor = " + roughness.result + ";",
metalness.code,
" float metalnessFactor = " + metalness.result + ";"
];
if ( alpha ) {
output.push(
alpha.code,
'if ( ' + alpha.result + ' <= ALPHATEST ) discard;'
);
}
if ( normal ) {
builder.include( 'perturbNormal2Arb' );
output.push( normal.code );
if ( normalScale ) output.push( normalScale.code );
output.push(
'normal = perturbNormal2Arb(-vViewPosition,normal,' +
normal.result + ',' +
new THREE.UVNode().build( builder, 'v2' ) + ',' +
( normalScale ? normalScale.result : 'vec2( 1.0 )' ) + ');'
);
}
// optimization for now
output.push( 'material.diffuseColor = ' + ( light ? 'vec3( 1.0 )' : 'diffuseColor * (1.0 - metalnessFactor)' ) + ';' );
output.push(
// accumulation
'material.specularRoughness = clamp( roughnessFactor, DEFAULT_SPECULAR_COEFFICIENT, 1.0 );' // disney's remapping of [ 0, 1 ] roughness to [ 0.001, 1 ]
);
if (clearCoat) {
output.push(
clearCoat.code,
'material.clearCoat = saturate( ' + clearCoat.result + ' );'
);
} else if (useClearCoat) {
output.push( 'material.clearCoat = 0.0;' );
}
if (clearCoatRoughness) {
output.push(
clearCoatRoughness.code,
'material.clearCoatRoughness = clamp( ' + clearCoatRoughness.result + ', DEFAULT_SPECULAR_COEFFICIENT, 1.0 );'
);
} else if (useClearCoat) {
output.push( 'material.clearCoatRoughness = 0.0;' );
}
if ( reflectivity ) {
output.push(
reflectivity.code,
'material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( ' + reflectivity.result + ' ) ), diffuseColor, metalnessFactor );'
);
} else {
output.push(
'material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor, metalnessFactor );'
);
}
output.push(
THREE.ShaderChunk[ "lights_template" ]
);
if ( light ) {
output.push(
light.code,
"reflectedLight.directDiffuse = " + light.result + ";"
);
// apply color
output.push(
"diffuseColor *= 1.0 - metalnessFactor;",
"reflectedLight.directDiffuse *= diffuseColor;",
"reflectedLight.indirectDiffuse *= diffuseColor;"
);
}
if ( ao ) {
output.push(
ao.code,
"reflectedLight.indirectDiffuse *= " + ao.result + ";",
"float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );",
"reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, " + ao.result + ", material.specularRoughness );"
);
}
if ( ambient ) {
output.push(
ambient.code,
"reflectedLight.indirectDiffuse += " + ambient.result + ";"
);
}
if ( shadow ) {
output.push(
shadow.code,
"reflectedLight.directDiffuse *= " + shadow.result + ";",
"reflectedLight.directSpecular *= " + shadow.result + ";"
);
}
if ( emissive ) {
output.push(
emissive.code,
"reflectedLight.directDiffuse += " + emissive.result + ";"
);
}
if ( environment ) {
output.push( environment.code );
if (clearCoatEnv) {
output.push(
clearCoatEnv.code,
"vec3 clearCoatRadiance = " + clearCoatEnv.result + ";"
);
} else {
output.push("vec3 clearCoatRadiance = vec3( 0.0 );");
}
output.push( "RE_IndirectSpecular(" + environment.result + ", clearCoatRadiance, geometry, material, reflectedLight );" );
}
output.push( "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular;" );
if ( alpha ) {
output.push( "gl_FragColor = vec4( outgoingLight, " + alpha.result + " );" );
} else {
output.push( "gl_FragColor = vec4( outgoingLight, 1.0 );" );
}
output.push(
THREE.ShaderChunk[ "premultiplied_alpha_fragment" ],
THREE.ShaderChunk[ "tonemapping_fragment" ],
THREE.ShaderChunk[ "encodings_fragment" ],
THREE.ShaderChunk[ "fog_fragment" ]
);
code = output.join( "\n" );
}
return code;
};

View File

@@ -0,0 +1,17 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.StandardNodeMaterial = function() {
this.node = new THREE.StandardNode();
THREE.NodeMaterial.call( this, this.node, this.node );
};
THREE.StandardNodeMaterial.prototype = Object.create( THREE.NodeMaterial.prototype );
THREE.StandardNodeMaterial.prototype.constructor = THREE.StandardNodeMaterial;
THREE.NodeMaterial.addShortcuts( THREE.StandardNodeMaterial.prototype, 'node',
[ 'color', 'alpha', 'roughness', 'metalness', 'reflectivity', 'clearCoat', 'clearCoatRoughness', 'normal', 'normalScale', 'emissive', 'ambient', 'light', 'shadow', 'ao', 'environment', 'transform' ] );

79
node_modules/three/examples/js/nodes/math/Math1Node.js generated vendored Normal file
View File

@@ -0,0 +1,79 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.Math1Node = function( a, method ) {
THREE.TempNode.call( this );
this.a = a;
this.method = method || THREE.Math1Node.SIN;
};
THREE.Math1Node.RAD = 'radians';
THREE.Math1Node.DEG = 'degrees';
THREE.Math1Node.EXP = 'exp';
THREE.Math1Node.EXP2 = 'exp2';
THREE.Math1Node.LOG = 'log';
THREE.Math1Node.LOG2 = 'log2';
THREE.Math1Node.SQRT = 'sqrt';
THREE.Math1Node.INV_SQRT = 'inversesqrt';
THREE.Math1Node.FLOOR = 'floor';
THREE.Math1Node.CEIL = 'ceil';
THREE.Math1Node.NORMALIZE = 'normalize';
THREE.Math1Node.FRACT = 'fract';
THREE.Math1Node.SAT = 'saturate';
THREE.Math1Node.SIN = 'sin';
THREE.Math1Node.COS = 'cos';
THREE.Math1Node.TAN = 'tan';
THREE.Math1Node.ASIN = 'asin';
THREE.Math1Node.ACOS = 'acos';
THREE.Math1Node.ARCTAN = 'atan';
THREE.Math1Node.ABS = 'abs';
THREE.Math1Node.SIGN = 'sign';
THREE.Math1Node.LENGTH = 'length';
THREE.Math1Node.NEGATE = 'negate';
THREE.Math1Node.INVERT = 'invert';
THREE.Math1Node.prototype = Object.create( THREE.TempNode.prototype );
THREE.Math1Node.prototype.constructor = THREE.Math1Node;
THREE.Math1Node.prototype.getType = function( builder ) {
switch ( this.method ) {
case THREE.Math1Node.LENGTH:
return 'fv1';
}
return this.a.getType( builder );
};
THREE.Math1Node.prototype.generate = function( builder, output ) {
var material = builder.material;
var type = this.getType( builder );
var result = this.a.build( builder, type );
switch ( this.method ) {
case THREE.Math1Node.NEGATE:
result = '(-' + result + ')';
break;
case THREE.Math1Node.INVERT:
result = '(1.0-' + result + ')';
break;
default:
result = this.method + '(' + result + ')';
break;
}
return builder.format( result, type, output );
};

96
node_modules/three/examples/js/nodes/math/Math2Node.js generated vendored Normal file
View File

@@ -0,0 +1,96 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.Math2Node = function( a, b, method ) {
THREE.TempNode.call( this );
this.a = a;
this.b = b;
this.method = method || THREE.Math2Node.DISTANCE;
};
THREE.Math2Node.MIN = 'min';
THREE.Math2Node.MAX = 'max';
THREE.Math2Node.MOD = 'mod';
THREE.Math2Node.STEP = 'step';
THREE.Math2Node.REFLECT = 'reflect';
THREE.Math2Node.DISTANCE = 'distance';
THREE.Math2Node.DOT = 'dot';
THREE.Math2Node.CROSS = 'cross';
THREE.Math2Node.POW = 'pow';
THREE.Math2Node.prototype = Object.create( THREE.TempNode.prototype );
THREE.Math2Node.prototype.constructor = THREE.Math2Node;
THREE.Math2Node.prototype.getInputType = function( builder ) {
// use the greater length vector
if ( builder.getFormatLength( this.b.getType( builder ) ) > builder.getFormatLength( this.a.getType( builder ) ) ) {
return this.b.getType( builder );
}
return this.a.getType( builder );
};
THREE.Math2Node.prototype.getType = function( builder ) {
switch ( this.method ) {
case THREE.Math2Node.DISTANCE:
case THREE.Math2Node.DOT:
return 'fv1';
case THREE.Math2Node.CROSS:
return 'v3';
}
return this.getInputType( builder );
};
THREE.Math2Node.prototype.generate = function( builder, output ) {
var material = builder.material;
var type = this.getInputType( builder );
var a, b,
al = builder.getFormatLength( this.a.getType( builder ) ),
bl = builder.getFormatLength( this.b.getType( builder ) );
// optimzer
switch ( this.method ) {
case THREE.Math2Node.CROSS:
a = this.a.build( builder, 'v3' );
b = this.b.build( builder, 'v3' );
break;
case THREE.Math2Node.STEP:
a = this.a.build( builder, al == 1 ? 'fv1' : type );
b = this.b.build( builder, type );
break;
case THREE.Math2Node.MIN:
case THREE.Math2Node.MAX:
case THREE.Math2Node.MOD:
a = this.a.build( builder, type );
b = this.b.build( builder, bl == 1 ? 'fv1' : type );
break;
default:
a = this.a.build( builder, type );
b = this.b.build( builder, type );
break;
}
return builder.format( this.method + '(' + a + ',' + b + ')', this.getType( builder ), output );
};

74
node_modules/three/examples/js/nodes/math/Math3Node.js generated vendored Normal file
View File

@@ -0,0 +1,74 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.Math3Node = function( a, b, c, method ) {
THREE.TempNode.call( this );
this.a = a;
this.b = b;
this.c = c;
this.method = method || THREE.Math3Node.MIX;
};
THREE.Math3Node.MIX = 'mix';
THREE.Math3Node.REFRACT = 'refract';
THREE.Math3Node.SMOOTHSTEP = 'smoothstep';
THREE.Math3Node.FACEFORWARD = 'faceforward';
THREE.Math3Node.prototype = Object.create( THREE.TempNode.prototype );
THREE.Math3Node.prototype.constructor = THREE.Math3Node;
THREE.Math3Node.prototype.getType = function( builder ) {
var a = builder.getFormatLength( this.a.getType( builder ) );
var b = builder.getFormatLength( this.b.getType( builder ) );
var c = builder.getFormatLength( this.c.getType( builder ) );
if ( a > b && a > c ) return this.a.getType( builder );
else if ( b > c ) return this.b.getType( builder );
return this.c.getType( builder );
};
THREE.Math3Node.prototype.generate = function( builder, output ) {
var material = builder.material;
var type = this.getType( builder );
var a, b, c,
al = builder.getFormatLength( this.a.getType( builder ) ),
bl = builder.getFormatLength( this.b.getType( builder ) ),
cl = builder.getFormatLength( this.c.getType( builder ) );
// optimzer
switch ( this.method ) {
case THREE.Math3Node.REFRACT:
a = this.a.build( builder, type );
b = this.b.build( builder, type );
c = this.c.build( builder, 'fv1' );
break;
case THREE.Math3Node.MIX:
a = this.a.build( builder, type );
b = this.b.build( builder, type );
c = this.c.build( builder, cl == 1 ? 'fv1' : type );
break;
default:
a = this.a.build( builder, type );
b = this.b.build( builder, type );
c = this.c.build( builder, type );
break;
}
return builder.format( this.method + '(' + a + ',' + b + ',' + c + ')', type, output );
};

View File

@@ -0,0 +1,56 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.OperatorNode = function( a, b, op ) {
THREE.TempNode.call( this );
this.a = a;
this.b = b;
this.op = op || THREE.OperatorNode.ADD;
};
THREE.OperatorNode.ADD = '+';
THREE.OperatorNode.SUB = '-';
THREE.OperatorNode.MUL = '*';
THREE.OperatorNode.DIV = '/';
THREE.OperatorNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.OperatorNode.prototype.constructor = THREE.OperatorNode;
THREE.OperatorNode.prototype.getType = function( builder ) {
var a = this.a.getType( builder );
var b = this.b.getType( builder );
if ( builder.isFormatMatrix( a ) ) {
return 'v4';
} else if ( builder.getFormatLength( b ) > builder.getFormatLength( a ) ) {
// use the greater length vector
return b;
}
return a;
};
THREE.OperatorNode.prototype.generate = function( builder, output ) {
var material = builder.material,
data = material.getDataNode( this.uuid );
var type = this.getType( builder );
var a = this.a.build( builder, type );
var b = this.b.build( builder, type );
return builder.format( '(' + a + this.op + b + ')', type, output );
};

View File

@@ -0,0 +1,32 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.NodePass = function() {
THREE.ShaderPass.call( this );
this.textureID = 'renderTexture';
this.fragment = new THREE.RawNode( new THREE.ScreenNode() );
this.node = new THREE.NodeMaterial();
this.node.fragment = this.fragment;
this.build();
};
THREE.NodePass.prototype = Object.create( THREE.ShaderPass.prototype );
THREE.NodePass.prototype.constructor = THREE.NodePass;
THREE.NodeMaterial.addShortcuts( THREE.NodePass.prototype, 'fragment', [ 'value' ] );
THREE.NodePass.prototype.build = function() {
this.node.build();
this.uniforms = this.node.uniforms;
this.material = this.node;
};

114
node_modules/three/examples/js/nodes/utils/BlurNode.js generated vendored Normal file
View File

@@ -0,0 +1,114 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.BlurNode = function( value, coord, radius, size ) {
THREE.TempNode.call( this, 'v4' );
this.requestUpdate = true;
this.value = value;
this.coord = coord || new THREE.UVNode();
this.radius = new THREE.Vector2Node( 1, 1 );
this.size = size;
this.blurX = true;
this.blurY = true;
this.horizontal = new THREE.FloatNode( 1 / 64 );
this.vertical = new THREE.FloatNode( 1 / 64 );
};
THREE.BlurNode.fBlurX = new THREE.FunctionNode( [
"vec4 blurX( sampler2D texture, vec2 uv, float s ) {",
" vec4 sum = vec4( 0.0 );",
" sum += texture2D( texture, vec2( uv.x - 4.0 * s, uv.y ) ) * 0.051;",
" sum += texture2D( texture, vec2( uv.x - 3.0 * s, uv.y ) ) * 0.0918;",
" sum += texture2D( texture, vec2( uv.x - 2.0 * s, uv.y ) ) * 0.12245;",
" sum += texture2D( texture, vec2( uv.x - 1.0 * s, uv.y ) ) * 0.1531;",
" sum += texture2D( texture, vec2( uv.x, uv.y ) ) * 0.1633;",
" sum += texture2D( texture, vec2( uv.x + 1.0 * s, uv.y ) ) * 0.1531;",
" sum += texture2D( texture, vec2( uv.x + 2.0 * s, uv.y ) ) * 0.12245;",
" sum += texture2D( texture, vec2( uv.x + 3.0 * s, uv.y ) ) * 0.0918;",
" sum += texture2D( texture, vec2( uv.x + 4.0 * s, uv.y ) ) * 0.051;",
" return sum;",
"}"
].join( "\n" ) );
THREE.BlurNode.fBlurY = new THREE.FunctionNode( [
"vec4 blurY( sampler2D texture, vec2 uv, float s ) {",
" vec4 sum = vec4( 0.0 );",
" sum += texture2D( texture, vec2( uv.x, uv.y - 4.0 * s ) ) * 0.051;",
" sum += texture2D( texture, vec2( uv.x, uv.y - 3.0 * s ) ) * 0.0918;",
" sum += texture2D( texture, vec2( uv.x, uv.y - 2.0 * s ) ) * 0.12245;",
" sum += texture2D( texture, vec2( uv.x, uv.y - 1.0 * s ) ) * 0.1531;",
" sum += texture2D( texture, vec2( uv.x, uv.y ) ) * 0.1633;",
" sum += texture2D( texture, vec2( uv.x, uv.y + 1.0 * s ) ) * 0.1531;",
" sum += texture2D( texture, vec2( uv.x, uv.y + 2.0 * s ) ) * 0.12245;",
" sum += texture2D( texture, vec2( uv.x, uv.y + 3.0 * s ) ) * 0.0918;",
" sum += texture2D( texture, vec2( uv.x, uv.y + 4.0 * s ) ) * 0.051;",
" return sum;",
"}"
].join( "\n" ) );
THREE.BlurNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.BlurNode.prototype.constructor = THREE.BlurNode;
THREE.BlurNode.prototype.updateFrame = function( delta ) {
if ( this.size ) {
this.horizontal.number = this.radius.x / this.size.x;
this.vertical.number = this.radius.y / this.size.y;
} else if ( this.value.value && this.value.value.image ) {
var image = this.value.value.image;
this.horizontal.number = this.radius.x / image.width;
this.vertical.number = this.radius.y / image.height;
}
};
THREE.BlurNode.prototype.generate = function( builder, output ) {
var material = builder.material, blurX = THREE.BlurNode.fBlurX, blurY = THREE.BlurNode.fBlurY;
builder.include( blurX );
builder.include( blurY );
if ( builder.isShader( 'fragment' ) ) {
var blurCode = [], code;
if ( this.blurX ) {
blurCode.push( blurX.name + '(' + this.value.build( builder, 'sampler2D' ) + ',' + this.coord.build( builder, 'v2' ) + ',' + this.horizontal.build( builder, 'fv1' ) + ')' );
}
if ( this.blurY ) {
blurCode.push( blurY.name + '(' + this.value.build( builder, 'sampler2D' ) + ',' + this.coord.build( builder, 'v2' ) + ',' + this.vertical.build( builder, 'fv1' ) + ')' );
}
if ( blurCode.length == 2 ) code = '(' + blurCode.join( '+' ) + '/2.0)';
else if ( blurCode.length ) code = '(' + blurCode[ 0 ] + ')';
else code = 'vec4( 0.0 )';
return builder.format( code, this.getType( builder ), output );
} else {
console.warn( "THREE.BlurNode is not compatible with " + builder.shader + " shader." );
return builder.format( 'vec4( 0.0 )', this.getType( builder ), output );
}
};

49
node_modules/three/examples/js/nodes/utils/BumpNode.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.BumpNode = function( value, coord, scale ) {
THREE.TempNode.call( this, 'v3' );
this.value = value;
this.coord = coord || new THREE.UVNode();
this.scale = scale || new THREE.Vector2Node( 1, 1 );
};
THREE.BumpNode.fBumpToNormal = new THREE.FunctionNode( [
"vec3 bumpToNormal( sampler2D bumpMap, vec2 uv, vec2 scale ) {",
" vec2 dSTdx = dFdx( uv );",
" vec2 dSTdy = dFdy( uv );",
" float Hll = texture2D( bumpMap, uv ).x;",
" float dBx = texture2D( bumpMap, uv + dSTdx ).x - Hll;",
" float dBy = texture2D( bumpMap, uv + dSTdy ).x - Hll;",
" return vec3( .5 + ( dBx * scale.x ), .5 + ( dBy * scale.y ), 1.0 );",
"}"
].join( "\n" ), null, { derivatives: true } );
THREE.BumpNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.BumpNode.prototype.constructor = THREE.BumpNode;
THREE.BumpNode.prototype.generate = function( builder, output ) {
var material = builder.material, func = THREE.BumpNode.fBumpToNormal;
builder.include( func );
if ( builder.isShader( 'fragment' ) ) {
return builder.format( func.name + '(' + this.value.build( builder, 'sampler2D' ) + ',' +
this.coord.build( builder, 'v2' ) + ',' +
this.scale.build( builder, 'v2' ) + ')', this.getType( builder ), output );
} else {
console.warn( "THREE.BumpNode is not compatible with " + builder.shader + " shader." );
return builder.format( 'vec3( 0.0 )', this.getType( builder ), output );
}
};

View File

@@ -0,0 +1,70 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ColorAdjustmentNode = function( rgb, adjustment, method ) {
THREE.TempNode.call( this, 'v3' );
this.rgb = rgb;
this.adjustment = adjustment;
this.method = method || THREE.ColorAdjustmentNode.SATURATION;
};
THREE.ColorAdjustmentNode.SATURATION = 'saturation';
THREE.ColorAdjustmentNode.HUE = 'hue';
THREE.ColorAdjustmentNode.VIBRANCE = 'vibrance';
THREE.ColorAdjustmentNode.BRIGHTNESS = 'brightness';
THREE.ColorAdjustmentNode.CONTRAST = 'contrast';
THREE.ColorAdjustmentNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.ColorAdjustmentNode.prototype.constructor = THREE.ColorAdjustmentNode;
THREE.ColorAdjustmentNode.prototype.generate = function( builder, output ) {
var rgb = this.rgb.build( builder, 'v3' );
var adjustment = this.adjustment.build( builder, 'fv1' );
var name;
switch ( this.method ) {
case THREE.ColorAdjustmentNode.SATURATION:
name = 'saturation_rgb';
break;
case THREE.ColorAdjustmentNode.HUE:
name = 'hue_rgb';
break;
case THREE.ColorAdjustmentNode.VIBRANCE:
name = 'vibrance_rgb';
break;
case THREE.ColorAdjustmentNode.BRIGHTNESS:
return builder.format( '(' + rgb + '+' + adjustment + ')', this.getType( builder ), output );
break;
case THREE.ColorAdjustmentNode.CONTRAST:
return builder.format( '(' + rgb + '*' + adjustment + ')', this.getType( builder ), output );
break;
}
builder.include( name );
return builder.format( name + '(' + rgb + ',' + adjustment + ')', this.getType( builder ), output );
};

69
node_modules/three/examples/js/nodes/utils/JoinNode.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.JoinNode = function( x, y, z, w ) {
THREE.TempNode.call( this, 'fv1' );
this.x = x;
this.y = y;
this.z = z;
this.w = w;
};
THREE.JoinNode.inputs = [ 'x', 'y', 'z', 'w' ];
THREE.JoinNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.JoinNode.prototype.constructor = THREE.JoinNode;
THREE.JoinNode.prototype.getNumElements = function() {
var inputs = THREE.JoinNode.inputs;
var i = inputs.length;
while ( i -- ) {
if ( this[ inputs[ i ] ] !== undefined ) {
++ i;
break;
}
}
return Math.max( i, 2 );
};
THREE.JoinNode.prototype.getType = function( builder ) {
return builder.getFormatFromLength( this.getNumElements() );
};
THREE.JoinNode.prototype.generate = function( builder, output ) {
var material = builder.material;
var type = this.getType( builder );
var length = this.getNumElements();
var inputs = THREE.JoinNode.inputs;
var outputs = [];
for ( var i = 0; i < length; i ++ ) {
var elm = this[ inputs[ i ] ];
outputs.push( elm ? elm.build( builder, 'fv1' ) : '0.' );
}
var code = ( length > 1 ? builder.getConstructorFromLength( length ) : '' ) + '(' + outputs.join( ',' ) + ')';
return builder.format( code, type, output );
};

View File

@@ -0,0 +1,22 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.LuminanceNode = function( rgb ) {
THREE.TempNode.call( this, 'fv1' );
this.rgb = rgb;
};
THREE.LuminanceNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.LuminanceNode.prototype.constructor = THREE.LuminanceNode;
THREE.LuminanceNode.prototype.generate = function( builder, output ) {
builder.include( 'luminance_rgb' );
return builder.format( 'luminance_rgb(' + this.rgb.build( builder, 'v3' ) + ')', this.getType( builder ), output );
};

View File

@@ -0,0 +1,22 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.NoiseNode = function( coord ) {
THREE.TempNode.call( this, 'fv1' );
this.coord = coord;
};
THREE.NoiseNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.NoiseNode.prototype.constructor = THREE.NoiseNode;
THREE.NoiseNode.prototype.generate = function( builder, output ) {
builder.include( 'snoise' );
return builder.format( 'snoise(' + this.coord.build( builder, 'v2' ) + ')', this.getType( builder ), output );
};

View File

@@ -0,0 +1,42 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.NormalMapNode = function( value, uv, scale, normal, position ) {
THREE.TempNode.call( this, 'v3' );
this.value = value;
this.scale = scale || new THREE.FloatNode( 1 );
this.normal = normal || new THREE.NormalNode( THREE.NormalNode.LOCAL );
this.position = position || new THREE.PositionNode( THREE.NormalNode.VIEW );
};
THREE.NormalMapNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.NormalMapNode.prototype.constructor = THREE.NormalMapNode;
THREE.NormalMapNode.prototype.generate = function( builder, output ) {
var material = builder.material;
builder.include( 'perturbNormal2Arb' );
if ( builder.isShader( 'fragment' ) ) {
return builder.format( 'perturbNormal2Arb(-' + this.position.build( builder, 'v3' ) + ',' +
this.normal.build( builder, 'v3' ) + ',' +
this.value.build( builder, 'v3' ) + ',' +
this.value.coord.build( builder, 'v2' ) + ',' +
this.scale.build( builder, 'v2' ) + ')', this.getType( builder ), output );
} else {
console.warn( "THREE.NormalMapNode is not compatible with " + builder.shader + " shader." );
return builder.format( 'vec3( 0.0 )', this.getType( builder ), output );
}
};

View File

@@ -0,0 +1,25 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.ResolutionNode = function( renderer ) {
THREE.Vector2Node.call( this );
this.requestUpdate = true;
this.renderer = renderer;
};
THREE.ResolutionNode.prototype = Object.create( THREE.Vector2Node.prototype );
THREE.ResolutionNode.prototype.constructor = THREE.ResolutionNode;
THREE.ResolutionNode.prototype.updateFrame = function( delta ) {
var size = this.renderer.getSize();
this.x = size.width;
this.y = size.height;
};

View File

@@ -0,0 +1,64 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.RoughnessToBlinnExponentNode = function() {
THREE.TempNode.call( this, 'fv1' );
};
THREE.RoughnessToBlinnExponentNode.getSpecularMIPLevel = new THREE.FunctionNode( [
// taken from here: http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html
"float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {",
//float envMapWidth = pow( 2.0, maxMIPLevelScalar );
//float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
"float maxMIPLevelScalar = float( maxMIPLevel );",
"float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );",
// clamp to allowable LOD ranges.
"return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );",
"}"
].join( "\n" ) );
THREE.RoughnessToBlinnExponentNode.prototype = Object.create( THREE.TempNode.prototype );
THREE.RoughnessToBlinnExponentNode.prototype.constructor = THREE.RoughnessToBlinnExponentNode;
THREE.RoughnessToBlinnExponentNode.prototype.generate = function( builder, output ) {
var material = builder.material;
if ( builder.isShader( 'fragment' ) ) {
if ( material.isDefined( 'PHYSICAL' ) ) {
builder.include( THREE.RoughnessToBlinnExponentNode.getSpecularMIPLevel );
if ( builder.isCache( 'clearCoat' ) ) {
return builder.format( 'getSpecularMIPLevel( Material_ClearCoat_BlinnShininessExponent( material ), 8 )', this.type, output );
} else {
return builder.format( 'getSpecularMIPLevel( Material_BlinnShininessExponent( material ), 8 )', this.type, output );
}
} else {
console.warn( "THREE.RoughnessToBlinnExponentNode is only compatible with PhysicalMaterial." );
return builder.format( '0.0', this.type, output );
}
} else {
console.warn( "THREE.RoughnessToBlinnExponentNode is not compatible with " + builder.shader + " shader." );
return builder.format( '0.0', this.type, output );
}
};

View File

@@ -0,0 +1,72 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.SwitchNode = function( node, components ) {
THREE.GLNode.call( this );
this.node = node;
this.components = components || 'x';
};
THREE.SwitchNode.prototype = Object.create( THREE.GLNode.prototype );
THREE.SwitchNode.prototype.constructor = THREE.SwitchNode;
THREE.SwitchNode.prototype.getType = function( builder ) {
return builder.getFormatFromLength( this.components.length );
};
THREE.SwitchNode.prototype.generate = function( builder, output ) {
var type = this.node.getType( builder );
var inputLength = builder.getFormatLength( type ) - 1;
var node = this.node.build( builder, type );
if ( inputLength > 0 ) {
// get max length
var outputLength = 0;
var components = builder.colorToVector( this.components );
var i, len = components.length;
for ( i = 0; i < len; i ++ ) {
outputLength = Math.max( outputLength, builder.getIndexByElement( components.charAt( i ) ) );
}
if ( outputLength > inputLength ) outputLength = inputLength;
// split
node += '.';
for ( i = 0; i < len; i ++ ) {
var elm = components.charAt( i );
var idx = builder.getIndexByElement( components.charAt( i ) );
if ( idx > outputLength ) idx = outputLength;
node += builder.getElementByIndex( idx );
}
return builder.format( node, this.getType( builder ), output );
} else {
// join
return builder.format( node, type, output )
}
};

View File

@@ -0,0 +1,22 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.TimerNode = function( value, scale ) {
THREE.FloatNode.call( this, value );
this.requestUpdate = true;
this.scale = scale !== undefined ? scale : 1;
};
THREE.TimerNode.prototype = Object.create( THREE.FloatNode.prototype );
THREE.TimerNode.prototype.constructor = THREE.TimerNode;
THREE.TimerNode.prototype.updateFrame = function( delta ) {
this.number += delta * this.scale;
};

View File

@@ -0,0 +1,59 @@
/**
* @author sunag / http://www.sunag.com.br/
*/
THREE.VelocityNode = function( target, params ) {
THREE.Vector3Node.call( this );
this.requestUpdate = true;
this.target = target;
this.position = this.target.position.clone();
this.velocity = new THREE.Vector3();
this.moment = new THREE.Vector3();
this.params = params || {};
};
THREE.VelocityNode.prototype = Object.create( THREE.Vector3Node.prototype );
THREE.VelocityNode.prototype.constructor = THREE.VelocityNode;
THREE.VelocityNode.prototype.updateFrame = function( delta ) {
this.velocity.subVectors( this.target.position, this.position );
this.position.copy( this.target.position );
switch ( this.params.type ) {
case "elastic":
delta *= this.params.fps || 60;
var spring = Math.pow( this.params.spring, delta );
var friction = Math.pow( this.params.friction, delta );
// spring
this.moment.x += this.velocity.x * spring;
this.moment.y += this.velocity.y * spring;
this.moment.z += this.velocity.z * spring;
// friction
this.moment.x *= friction;
this.moment.y *= friction;
this.moment.z *= friction;
this.value.copy( this.moment );
break;
default:
this.value.copy( this.velocity );
break;
}
};