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

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 );
};