From e065244ac75d1d0f25fd5c75cb58e714a13fe16b Mon Sep 17 00:00:00 2001 From: Jonathan Duran Date: Wed, 14 Mar 2012 08:59:17 -0700 Subject: Squashed commit of the following: merge master into timeline Signed-off-by: Jonathan Duran --- js/lib/rdge/materials/bump-metal-material.js | 10 +- js/lib/rdge/materials/deform-material.js | 2 +- js/lib/rdge/materials/flat-material.js | 41 ++++---- js/lib/rdge/materials/fly-material.js | 2 +- js/lib/rdge/materials/julia-material.js | 2 +- js/lib/rdge/materials/keleidoscope-material.js | 2 +- js/lib/rdge/materials/linear-gradient-material.js | 2 +- js/lib/rdge/materials/mandel-material.js | 2 +- js/lib/rdge/materials/plasma-material.js | 37 +++----- js/lib/rdge/materials/pulse-material.js | 11 ++- js/lib/rdge/materials/radial-blur-material.js | 9 +- js/lib/rdge/materials/radial-gradient-material.js | 7 +- js/lib/rdge/materials/relief-tunnel-material.js | 2 +- js/lib/rdge/materials/square-tunnel-material.js | 2 +- js/lib/rdge/materials/star-material.js | 2 +- js/lib/rdge/materials/taper-material.js | 8 +- js/lib/rdge/materials/tunnel-material.js | 2 +- js/lib/rdge/materials/twist-material.js | 2 +- js/lib/rdge/materials/twist-vert-material.js | 6 +- js/lib/rdge/materials/uber-material.js | 109 +++++++++++++++++++++- js/lib/rdge/materials/water-material.js | 2 +- js/lib/rdge/materials/z-invert-material.js | 2 +- 22 files changed, 195 insertions(+), 69 deletions(-) (limited to 'js/lib/rdge') diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 61126952..fa6f5300 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -75,7 +75,7 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this.setProperty = function( prop, value ) { // every material should do something with the "color" property - if (prop === "color") prop = "lightDiff"; + if (prop === "color") return; // make sure we have legitimate imput var ok = this.validateProperty( prop, value ); @@ -116,7 +116,7 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this._shader['default'].u_light0Diff.set( this.getLightDiff() ); // set up the material node - this._materialNode = createMaterialNode( this.getShaderName() ); + this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); this._materialNode.setShader(this._shader); // set some image maps @@ -158,10 +158,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + exportStr += "lightDiff: " + this.getLightDiff() + "\n"; exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n"; exportStr += "specularTexture: " + this.getSpecularTexture() + "\n"; - exportStr += "normalMap: " + this.getNormalTexture() + "\n"; + exportStr += "normalMap: " + this.getNormalTexture() + "\n"; // every material needs to terminate like this exportStr += "endMaterial\n"; diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js index 1e6af6ac..dfd89d12 100644 --- a/js/lib/rdge/materials/deform-material.js +++ b/js/lib/rdge/materials/deform-material.js @@ -60,7 +60,7 @@ var DeformMaterial = function DeformMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("deformMaterial"); + this._materialNode = createMaterialNode("deformMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index be8bf2b8..97e4f646 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js @@ -36,19 +36,27 @@ var FlatMaterial = function FlatMaterial() { // duplcate method requirde this.dup = function() { return new FlatMaterial(); } ; - this.init = function() + this.init = function( world ) { - // set up the shader - this._shader = new jshader(); - this._shader.def = flatShaderDef; - this._shader.init(); - - // set the defaults - this._shader.colorMe.color.set( this.getColor() ); - - // set up the material node - this._materialNode = createMaterialNode("flatMaterial"); - this._materialNode.setShader(this._shader); + // save the world + if (world) + { + this.setWorld( world ); + + // set up the shader + this._shader = new jshader(); + this._shader.def = flatShaderDef; + this._shader.init(); + + // set the defaults + this._shader.colorMe.color.set( this.getColor() ); + + // set up the material node + this._materialNode = createMaterialNode("flatMaterial_" + world.generateUniqueNodeID() ); + this._materialNode.setShader(this._shader); + } + else + throw new Error( "GLWorld not supplied to material initialization" ); }; @@ -73,15 +81,12 @@ var FlatMaterial = function FlatMaterial() { }; /////////////////////////////////////////////////////////////////////// - this.export = function() { + this.export = function() + { // this function should be overridden by subclasses var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; - - if (this._shader) - exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; - else - exportStr += "color: " + this.getColor() + "\n"; + exportStr += "color: " + String(this._propValues["color"]) + "\n"; exportStr += "endMaterial\n"; return exportStr; diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js index 8eadb3ab..bd92ecd8 100644 --- a/js/lib/rdge/materials/fly-material.js +++ b/js/lib/rdge/materials/fly-material.js @@ -53,7 +53,7 @@ var FlyMaterial = function FlyMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("flyMaterial"); + this._materialNode = createMaterialNode("flyMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js index 07536f33..976dfad3 100644 --- a/js/lib/rdge/materials/julia-material.js +++ b/js/lib/rdge/materials/julia-material.js @@ -55,7 +55,7 @@ var JuliaMaterial = function JuliaMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("juliaMaterial"); + this._materialNode = createMaterialNode("juliaMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js index 3ef5d613..16d1ccfa 100644 --- a/js/lib/rdge/materials/keleidoscope-material.js +++ b/js/lib/rdge/materials/keleidoscope-material.js @@ -60,7 +60,7 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("keleidoscopeMaterial"); + this._materialNode = createMaterialNode("keleidoscopeMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 2c52c67d..8e05e23d 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js @@ -212,7 +212,7 @@ var LinearGradientMaterial = function LinearGradientMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode( this.getShaderName() ); + this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); this._materialNode.setShader(this._shader); // send the current values to the shader diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index 07e009a2..d9f00383 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js @@ -66,7 +66,7 @@ var MandelMaterial = function MandelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("mandelMaterial"); + this._materialNode = createMaterialNode("mandelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 9ecc2b48..86b1a93c 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -17,8 +17,6 @@ var PlasmaMaterial = function PlasmaMaterial() { this._dTime = 0.01; this._speed = 1.0; - this._color = [1,0,0,1]; - /////////////////////////////////////////////////////////////////////// // Property Accessors @@ -30,20 +28,12 @@ var PlasmaMaterial = function PlasmaMaterial() { /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["color"]; - this._propLabels = ["Color"]; - this._propTypes = ["color"]; - this._propValues = []; - - this._propValues[ this._propNames[0] ] = this._color; - - this.setProperty = function( prop, value ) { - // make sure we have legitimate imput - if (this.validateProperty( prop, value )) { - this._color = value.slice(0); - this._shader['default'][prop].set(value); - } + + this.setProperty = function( prop, value ) + { + // plasma has no properties }; + /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// @@ -54,7 +44,10 @@ var PlasmaMaterial = function PlasmaMaterial() { return new PlasmaMaterial(); }; - this.init = function() { + this.init = function( world) + { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = plasmaShaderDef; @@ -62,20 +55,15 @@ var PlasmaMaterial = function PlasmaMaterial() { // set the default value this._time = 0; - this._shader['default'].u_time = this._time; - this.setProperty( "color", [this._time, 0, 0, 1] ); + this._shader['default'].u_time.set( [this._time] ); // set up the material node - this._materialNode = createMaterialNode("plasmaMaterial"); + this._materialNode = createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); }; this.update = function( time ) { - this._shader['default'].u_time = this._time; - var color = this.getProperty( "color" ); - color[0] = this._time; - this.setProperty( "color", color ); - //console.log( "update color to: " + color ); + this._shader['default'].u_time.set( [this._time] ); this._time += this._dTime; } @@ -109,7 +97,6 @@ var plasmaShaderDef = 'params' : { 'u_time' : { 'type' : 'float' }, - 'color' : { 'type' : 'vec4' } }, // render states diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 63cab2f4..81db36c6 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -101,7 +101,7 @@ var PulseMaterial = function PulseMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("pulseMaterial"); + this._materialNode = createMaterialNode("pulseMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; @@ -178,6 +178,13 @@ var PulseMaterial = function PulseMaterial() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; + + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var texMapName = this._propValues[this._propNames[0]]; + exportStr += "texture: " +texMapName + "\n"; // every material needs to terminate like this exportStr += "endMaterial\n"; @@ -193,6 +200,8 @@ var PulseMaterial = function PulseMaterial() { var rtnStr; try { + this._propValues[this._propNames[0]] = pu.nextValue( "texture: " ); + var endKey = "endMaterial\n"; var index = importStr.indexOf( endKey ); index += endKey.length; diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 41e68182..46cdda74 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -94,7 +94,7 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("radialBlurMaterial"); + this._materialNode = createMaterialNode("radialBlurMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; @@ -161,6 +161,13 @@ var RadialBlurMaterial = function RadialBlurMaterial() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; exportStr += "name: " + this.getName() + "\n"; + + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var texMapName = this._propValues[this._propNames[0]]; + exportStr += "texture: " + texMapName + "\n"; // every material needs to terminate like this exportStr += "endMaterial\n"; diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index 13be50f5..d19b44b7 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js @@ -193,14 +193,17 @@ var RadialGradientMaterial = function RadialGradientMaterial() { return new RadialGradientMaterial(); }; - this.init = function() { + this.init = function( world ) + { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = radialGradientMaterialDef; this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("radialGradientMaterial"); + this._materialNode = createMaterialNode("radialGradientMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); // set the shader values in the shader diff --git a/js/lib/rdge/materials/relief-tunnel-material.js b/js/lib/rdge/materials/relief-tunnel-material.js index 20290895..52c40543 100644 --- a/js/lib/rdge/materials/relief-tunnel-material.js +++ b/js/lib/rdge/materials/relief-tunnel-material.js @@ -54,7 +54,7 @@ var ReliefTunnelMaterial = function ReliefTunnelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("reliefTunnelMaterial"); + this._materialNode = createMaterialNode("reliefTunnelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/square-tunnel-material.js b/js/lib/rdge/materials/square-tunnel-material.js index b5cbff30..9264872f 100644 --- a/js/lib/rdge/materials/square-tunnel-material.js +++ b/js/lib/rdge/materials/square-tunnel-material.js @@ -55,7 +55,7 @@ var SquareTunnelMaterial = function SquareTunnelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("squareTunnelMaterial"); + this._materialNode = createMaterialNode("squareTunnelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js index 9c0f3172..d7d797e4 100644 --- a/js/lib/rdge/materials/star-material.js +++ b/js/lib/rdge/materials/star-material.js @@ -55,7 +55,7 @@ var StarMaterial = function StarMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("starMaterial"); + this._materialNode = createMaterialNode("starMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index eeb08aec..03a7ba9c 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js @@ -42,8 +42,10 @@ function TaperMaterial() // duplcate method requirde this.dup = function() { return new TaperMaterial(); } - this.init = function() + this.init = function( world ) { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = taperShaderDef; @@ -53,7 +55,7 @@ function TaperMaterial() this._shader.colorMe.color.set( this.getColor() ); // set up the material node - this._materialNode = createMaterialNode("taperMaterial"); + this._materialNode = createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); // initialize the taper properties @@ -102,7 +104,7 @@ function TaperMaterial() exportStr += "name: " + this.getName() + "\n"; if (this._shader) - exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; + exportStr += "color: " + this._shader.colorMe.color + "\n"; else exportStr += "color: " + this.getColor() + "\n"; exportStr += "endMaterial\n"; diff --git a/js/lib/rdge/materials/tunnel-material.js b/js/lib/rdge/materials/tunnel-material.js index fe787d16..fe0fbd51 100644 --- a/js/lib/rdge/materials/tunnel-material.js +++ b/js/lib/rdge/materials/tunnel-material.js @@ -56,7 +56,7 @@ var TunnelMaterial = function TunnelMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("tunnelMaterial"); + this._materialNode = createMaterialNode("tunnelMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/twist-material.js b/js/lib/rdge/materials/twist-material.js index eb562e99..163c8a77 100644 --- a/js/lib/rdge/materials/twist-material.js +++ b/js/lib/rdge/materials/twist-material.js @@ -56,7 +56,7 @@ var TwistMaterial = function TwistMaterial() { this._shader.init(); // set up the material node - this._materialNode = createMaterialNode("twistMaterial"); + this._materialNode = createMaterialNode("twistMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); this._time = 0; diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index c2573071..05172a1b 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -46,8 +46,10 @@ function TwistVertMaterial() // duplcate method requirde this.dup = function() { return new TwistVertMaterial(); } - this.init = function() + this.init = function( world ) { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = twistVertShaderDef; @@ -57,7 +59,7 @@ function TwistVertMaterial() this._shader.twistMe.color.set( this.getColor() ); // set up the material node - this._materialNode = createMaterialNode("twistVertMaterial"); + this._materialNode = createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); // initialize the twist vert properties diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 6bc35d51..655d8e2a 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -33,6 +33,8 @@ var UberMaterial = function UberMaterial() { this._useEnvironmentMap = true; this._useLights = [true, true, true, true]; + this._MAX_LIGHTS = 4; + /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// @@ -363,10 +365,115 @@ var UberMaterial = function UberMaterial() { this._shader = this.buildUberShader( this._ubershaderCaps ); // set up the material node - this._materialNode = createMaterialNode("uberMaterial"); + this._materialNode = createMaterialNode("uberMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); }; + this.import = function( importStr ) + { + // limit the key searches to this material + var endKey = "endMaterial\n"; + var index = importStr.indexOf( endKey ); + index += endKey.length; + importStr = importStr.substr( index ); + var pu = new MaterialParser( importStr ); + + var matProps = pu.nextValue( "materialProps: " ); + if (matProps) + { + var ambientColor = Number( pu.nextValue( "ambientColor: " )); this.setProperty( "ambientColor", ambientColor ); + var diffuseColor = Number( pu.nextValue( "diffuseColor: " )); this.setProperty( "diffuseColor", diffuseColor ); + var specularColor = Number( pu.nextValue( "specularColor: " )); this.setProperty( "specularColor", specularColor ); + var specularPower = Number( pu.nextValue( "specularPower: " )); this.setProperty( "specularPower", specularPower ); + } + + var lightProps = pu.nextValue( "theLights" ); + } + + this.export = function() + { + // every material needs the base type and instance name + var exportStr = "material: " + this.getShaderName() + "\n"; + exportStr += "name: " + this.getName() + "\n"; + + var caps = this._ubershaderCaps; + + // export the material properties + if (typeof caps.material != 'undefined') + { + exportStr += "materialProps: true\n"; + exportStr += "ambientColor: " + caps.material.ambientColor + "\n"; + exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n"; + exportStr += "specularColor: " + caps.material.specularColor + "\n"; + exportStr += "specularPower: " + caps.material.specularPower + "\n"; + } + + if (typeof caps.lighting != 'undefined') + { + exportStr += "lightProps: true\n"; + + var light = caps.lighting['light' + i]; + for (var i=0; i