From db2bb0ab5d2747f0d07878e3b8a7d2d10c755110 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 7 Jun 2012 17:07:21 -0700 Subject: Material cleanup --- js/lib/rdge/materials/keleidoscope-material.js | 52 ++++++-------------------- 1 file changed, 12 insertions(+), 40 deletions(-) (limited to 'js/lib/rdge/materials/keleidoscope-material.js') diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js index e9f1b10e..2754420f 100644 --- a/js/lib/rdge/materials/keleidoscope-material.js +++ b/js/lib/rdge/materials/keleidoscope-material.js @@ -14,7 +14,7 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { this._name = "KeleidoscopeMaterial"; this._shaderName = "keleidoscope"; - this._texMap = 'assets/images/rocky-normal.jpg'; + this._defaultTexMap = 'assets/images/rocky-normal.jpg'; this._time = 0.0; this._dTime = 0.01; @@ -24,11 +24,19 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { /////////////////////////////////////////////////////////////////////// // all defined in parent PulseMaterial.js // load the local default value - this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + var u_tex0_index = 0, u_speed_index = 1; + this._propNames = ["u_tex0", "u_speed" ]; + this._propLabels = ["Texture map", "Speed" ]; + this._propTypes = ["file", "float" ]; + this._propValues = []; + this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); + this._propValues[this._propNames[u_speed_index]] = 1.0; /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// + this.isAnimated = function() { return true; }; + this.getShaderDef = function() { return keleidoscopeMaterialDef; } /////////////////////////////////////////////////////////////////////// @@ -37,21 +45,6 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { // 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 KeleidoscopeMaterial(); - - // 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 @@ -71,33 +64,11 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { this._shader['default'].u_time.set( [this._time] ); } - // set up the texture - var texMapName = this._propValues[this._propNames[0]]; - this._glTex = new Texture( world, texMapName ); - // set the shader values in the shader - this.updateTexture(); + this.setShaderValues(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); this.update( 0 ); }; - - this.update = function( time ) - { - var material = this._materialNode; - if (material) - { - var technique = material.shaderProgram['default']; - var renderer = RDGE.globals.engine.getContext().renderer; - if (renderer && technique) - { - if (this._shader && this._shader['default']) { - this._shader['default'].u_time.set( [this._time] ); - } - - this._time = time; - } - } - }; }; /////////////////////////////////////////////////////////////////////////////////////// @@ -128,6 +99,7 @@ var keleidoscopeMaterialDef = 'params' : { 'u_tex0': { 'type' : 'tex2d' }, + 'u_speed' : { 'type' : 'float' }, 'u_time' : { 'type' : 'float' }, 'u_resolution' : { 'type' : 'vec2' }, }, -- cgit v1.2.3