From 6c994c4b90023cecf4fd0caafb404b859fe28f54 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 6 Jun 2012 16:34:41 -0700 Subject: material cleanup and rearchitecture --- js/lib/rdge/materials/bump-metal-material.js | 2 - js/lib/rdge/materials/cloud-material.js | 17 --- js/lib/rdge/materials/deform-material.js | 16 -- js/lib/rdge/materials/flag-material.js | 16 -- js/lib/rdge/materials/flat-material.js | 18 ++- js/lib/rdge/materials/fly-material.js | 1 + js/lib/rdge/materials/material.js | 219 +++++++++++++++++++++------ js/lib/rdge/materials/pulse-material.js | 189 +++-------------------- js/lib/rdge/materials/taper-material.js | 102 +++++++------ js/lib/rdge/materials/water-material.js | 45 +++--- 10 files changed, 297 insertions(+), 328 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 4d19c9c1..30624f7b 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -108,8 +108,6 @@ var BumpMetalMaterial = function BumpMetalMaterial() { /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// - // duplcate method requirde - this.dup = function() { return new BumpMetalMaterial(); }; this.init = function( world ) { diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js index 2c7fced2..2153b857 100644 --- a/js/lib/rdge/materials/cloud-material.js +++ b/js/lib/rdge/materials/cloud-material.js @@ -106,23 +106,6 @@ var CloudMaterial = function CloudMaterial() /////////////////////////////////////////////////////////////////////// // duplicate method required /**************************************************************/ - this.dup = function (world) { - // save the world - if (world) this.setWorld(world); - - // allocate a new uber material - var newMat = new CloudMaterial(); - - // copy over the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - var n = propNames.length; - for (var i = 0; i < n; i++) { - newMat.setProperty(propNames[i], propValues[i]); - } - - return newMat; - }; this.init = function (world) { var GLWorld = require("js/lib/drawing/world").World, diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js index c7f9cadc..70742c77 100644 --- a/js/lib/rdge/materials/deform-material.js +++ b/js/lib/rdge/materials/deform-material.js @@ -37,22 +37,6 @@ var DeformMaterial = function DeformMaterial() { // Methods /////////////////////////////////////////////////////////////////////// // duplcate method requirde - this.dup = function (world) - { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new DeformMaterial(); - - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); - - return newMat; - }; this.init = function (world) { // save the world diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js index d1788fb8..aaf36ebf 100644 --- a/js/lib/rdge/materials/flag-material.js +++ b/js/lib/rdge/materials/flag-material.js @@ -51,22 +51,6 @@ var FlagMaterial = function FlagMaterial() { // Methods /////////////////////////////////////////////////////////////////////// // duplcate method requirde - this.dup = function( world ) - { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new uber material - var newMat = new FlagMaterial(); - - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); - - return newMat; - }; this.setProperty = function( prop, value ) { diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index 40da9305..e5498b65 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js @@ -34,7 +34,22 @@ var FlatMaterial = function FlatMaterial() { // Methods /////////////////////////////////////////////////////////////////////// // duplcate method requirde - this.dup = function () { return new FlatMaterial(); }; + this.dup = function( world ) + { + // get the current values; + var propNames = [], propValues = [], propTypes = [], propLabels = []; + this.getAllProperties(propNames, propValues, propTypes, propLabels); + + // allocate a new material + var newMat = new FlatMaterial(); + + // copy over the current values; + var n = propNames.length; + for (var i = 0; i < n; i++) + newMat.setProperty(propNames[i], propValues[i]); + + return newMat; + }; this.init = function (world) { // save the world @@ -72,6 +87,7 @@ var FlatMaterial = function FlatMaterial() { // make sure we have legitimate input if (this.validateProperty(prop, value)) { this._propValues[prop] = value; + if (prop === 'color') this._color = value.slice(); if (this._shader && this._shader.colorMe) { this._shader.colorMe[prop].set(value); } diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js index ca38cc83..5e14f3af 100644 --- a/js/lib/rdge/materials/fly-material.js +++ b/js/lib/rdge/materials/fly-material.js @@ -106,6 +106,7 @@ var flyMaterialDef = { 'u_tex0': { 'type' : 'tex2d' }, 'u_time' : { 'type' : 'float' }, + 'u_speed' : { 'type' : 'float' }, 'u_resolution' : { 'type' : 'vec2' }, }, diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 856513e2..d2586b58 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js @@ -4,6 +4,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ +var Texture = require("js/lib/rdge/texture").Texture; + + /////////////////////////////////////////////////////////////////////// // Class GLMaterial // GL representation of a material. @@ -15,19 +18,16 @@ var Material = function GLMaterial( world ) { this._name = "GLMaterial"; this._shaderName = "undefined"; + this._time = 0.0; + this._dTime = 0.01; + // keep a reference to the owning GLWorld this._world = null; if(world) { this._world = world; } - this._shininess = 60; - - this._ambient = [0.0, 0.0, 0.0, 1.0]; - this._diffuse = [0.0, 0.0, 0.0, 1.0]; - this._specular = [0.0, 0.0, 0.0, 1.0]; - - this._texture = null; + this._glTextures = []; // indexed by uniform name // vertex deformation variables this._hasVertexDeformation = false; @@ -46,13 +46,6 @@ var Material = function GLMaterial( world ) { /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// - this.getShininess = function() { - return this._shininess; - }; - - this.setShininess = function(s) { - this._shininess = s; - }; this.setName = function(n) { this._name = n; @@ -78,30 +71,6 @@ var Material = function GLMaterial( world ) { return this._world; }; - this.setAmbient = function(r, g, b, a) { - this._ambient = [r, g, b, a]; - }; - - this.getAmbient = function() { - return [this._ambient[0], this._ambient[1], this._ambient[2], this._ambient[3]]; - }; - - this.setDiffuse = function(r, g, b, a) { - this._diffuse = [r, g, b, a]; - }; - - this.getDiffuse = function() { - return [this._diffuse[0], this._diffuse[1], this._diffuse[2], this._diffuse[3]]; - }; - - this.setSpecular = function(r, g, b, a) { - this._specular = [r, g, b, a]; - }; - - this.getSpecular = function() { - return [this._specular[0], this._specular[1], this._specular[2], this._specular[3]]; - }; - this.getShader = function() { return this._shader; }; @@ -116,6 +85,10 @@ var Material = function GLMaterial( world ) { return false; }; + this.getTechniqueName = function() { + return 'default' + }; + // the vertex shader can apply deformations requiring refinement in // certain areas. this.hasVertexDeformation = function() { @@ -166,6 +139,43 @@ var Material = function GLMaterial( world ) { } }; + this.hasProperty = function( prop ) + { + var propNames = [], dummy = []; + this.getAllProperties( propNames, dummy, dummy, dummy ) + for (var i=0; i