From d4ca478ad313c6c20834e410ba14ad3a5e7b20bf Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 12 Jun 2012 10:28:26 -0700 Subject: Material cleanup & bug fixes. --- js/lib/rdge/materials/mandel-material.js | 48 ++++++++------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) (limited to 'js/lib/rdge/materials/mandel-material.js') diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index e75d74ba..e1c19145 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js @@ -14,7 +14,7 @@ var MandelMaterial = function MandelMaterial() { this._name = "MandelMaterial"; this._shaderName = "mandel"; - this._texMap = 'assets/images/rocky-normal.jpg'; + this._defaultTexMap = 'assets/images/rocky-normal.jpg'; this._time = 0.0; this._dTime = 0.01; @@ -27,32 +27,23 @@ var MandelMaterial = function MandelMaterial() { /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// + 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; /////////////////////////////////////////////////////////////////////// - this.isAnimated = function() { - return true; - }; + this.isAnimated = function() { return true; }; + this.getShaderDef = function() { return MandelMaterialDef; } /////////////////////////////////////////////////////////////////////// // 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 MandelMaterial(); - - // 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,27 +63,11 @@ var MandelMaterial = function MandelMaterial() { 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.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; - } - } - }; }; /////////////////////////////////////////////////////////////////////////////////////// @@ -124,6 +99,7 @@ var MandelMaterialDef = { 'u_tex0': { 'type' : 'tex2d' }, 'u_time' : { 'type' : 'float' }, + 'u_speed' : { 'type' : 'float' }, 'u_resolution' : { 'type' : 'vec2' }, }, -- cgit v1.2.3