aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/z-invert-material.js
diff options
context:
space:
mode:
authorhwc4872012-06-12 10:28:26 -0700
committerhwc4872012-06-12 10:28:26 -0700
commitd4ca478ad313c6c20834e410ba14ad3a5e7b20bf (patch)
tree28e44c5ab1b2f9dbfd32aedba51402ac2d26a0ff /js/lib/rdge/materials/z-invert-material.js
parentdb2bb0ab5d2747f0d07878e3b8a7d2d10c755110 (diff)
downloadninja-d4ca478ad313c6c20834e410ba14ad3a5e7b20bf.tar.gz
Material cleanup & bug fixes.
Diffstat (limited to 'js/lib/rdge/materials/z-invert-material.js')
-rw-r--r--js/lib/rdge/materials/z-invert-material.js49
1 files changed, 21 insertions, 28 deletions
diff --git a/js/lib/rdge/materials/z-invert-material.js b/js/lib/rdge/materials/z-invert-material.js
index e1149f8b..99b835b3 100644
--- a/js/lib/rdge/materials/z-invert-material.js
+++ b/js/lib/rdge/materials/z-invert-material.js
@@ -15,37 +15,33 @@ var ZInvertMaterial = function ZInvertMaterial() {
15 this._name = "ZInvertMaterial"; 15 this._name = "ZInvertMaterial";
16 this._shaderName = "zinvert"; 16 this._shaderName = "zinvert";
17 17
18 this._texMap = 'assets/images/rocky-normal.jpg'; 18 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
19 19
20 this._time = 0.0; 20 this._time = 0.0;
21 this._dTime = 0.01; 21 this._dTime = 0.01;
22 22
23 /////////////////////////////////////////////////////////////////////// 23 this.isAnimated = function() { return true; };
24 // Properties 24 this.getShaderDef = function() { return zInvertMaterialDef; };
25 /////////////////////////////////////////////////////////////////////// 25
26 // all defined in parent PulseMaterial.js 26 ///////////////////////////////////////////////////////////////////////
27 // load the local default value 27 // Properties
28 this._propValues[this._propNames[0]] = this._texMap.slice(0); 28 ///////////////////////////////////////////////////////////////////////
29 // all defined in parent PulseMaterial.js
30 // load the local default value
31 this._propNames = ["u_tex0", "u_speed"];
32 this._propLabels = ["Texture map", "Speed"];
33 this._propTypes = ["file", "float"];
34
35 var u_tex_index = 0,
36 u_speed_index = 1;
37
38 this._propValues = [];
39 this._propValues[ this._propNames[u_tex_index ] ] = this._defaultTexMap.slice(0);
40 this._propValues[ this._propNames[u_speed_index ] ] = 1.0;
29 41
30 /////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////
31 // Methods 43 // Methods
32 /////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////
33 // duplicate method required
34 this.dup = function (world) {
35 // get the current values;
36 var propNames = [], propValues = [], propTypes = [], propLabels = [];
37 this.getAllProperties(propNames, propValues, propTypes, propLabels);
38
39 // allocate a new material
40 var newMat = new ZInvertMaterial();
41
42 // copy over the current values;
43 var n = propNames.length;
44 for (var i = 0; i < n; i++)
45 newMat.setProperty(propNames[i], propValues[i]);
46
47 return newMat;
48 };
49 45
50 this.init = function (world) { 46 this.init = function (world) {
51 // save the world 47 // save the world
@@ -65,12 +61,8 @@ var ZInvertMaterial = function ZInvertMaterial() {
65 this._shader['default'].u_time.set([this._time]); 61 this._shader['default'].u_time.set([this._time]);
66 } 62 }
67 63
68 // set up the texture
69 var texMapName = this._propValues[this._propNames[0]];
70 this._glTex = new Texture( world, texMapName );
71
72 // set the shader values in the shader 64 // set the shader values in the shader
73 this.updateTexture(); 65 this.setShaderValues();
74 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 66 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
75 this.update(0); 67 this.update(0);
76 }; 68 };
@@ -105,6 +97,7 @@ var zInvertMaterialDef =
105 { 97 {
106 'u_tex0': { 'type': 'tex2d' }, 98 'u_tex0': { 'type': 'tex2d' },
107 'u_time': { 'type': 'float' }, 99 'u_time': { 'type': 'float' },
100 'u_speed': { 'type': 'float' },
108 'u_resolution': { 'type': 'vec2' } 101 'u_resolution': { 'type': 'vec2' }
109 }, 102 },
110 103