aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/deform-material.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-06-19 15:56:23 -0700
committerNivesh Rajbhandari2012-06-19 15:56:23 -0700
commit3ed06c2a55b1ae840334efeb47f7743944ecb3ca (patch)
tree0ad3e94248a1d4828386c8743a670c709357a470 /js/lib/rdge/materials/deform-material.js
parenta0d18963d746e410511c29edd32bc1775d2d5851 (diff)
parent483ad57efcd6475776f580c3af5b60e6deeaf781 (diff)
downloadninja-3ed06c2a55b1ae840334efeb47f7743944ecb3ca.tar.gz
Merge branch 'refs/heads/ninja-internal' into GIO_Fixes
Diffstat (limited to 'js/lib/rdge/materials/deform-material.js')
-rw-r--r--js/lib/rdge/materials/deform-material.js36
1 files changed, 19 insertions, 17 deletions
diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js
index 328330bf..4354408d 100644
--- a/js/lib/rdge/materials/deform-material.js
+++ b/js/lib/rdge/materials/deform-material.js
@@ -5,29 +5,43 @@
5 </copyright> */ 5 </copyright> */
6 6
7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; 7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
8var Texture = require("js/lib/rdge/texture").Texture;
8 9
9var DeformMaterial = function DeformMaterial() { 10var DeformMaterial = function DeformMaterial() {
10 /////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////
11 // Instance variables 12 // Instance variables
12 /////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////
13 this._name = "DeformMaterial"; 14 this._name = "Deform";
14 this._shaderName = "deform"; 15 this._shaderName = "deform";
15 16
16 this._texMap = 'assets/images/rocky-normal.jpg'; 17 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
17 18
18 this._time = 0.0; 19 this._time = 0.0;
19 this._dTime = 0.01; 20 this._dTime = 0.01;
20 21
22 // array textures indexed by shader uniform name
23 this._glTextures = [];
24
21 /////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////
22 // Properties 26 // Properties
23 /////////////////////////////////////////////////////////////////////// 27 ///////////////////////////////////////////////////////////////////////
24 // all defined in parent PulseMaterial.js 28 // all defined in parent PulseMaterial.js
25 // load the local default value 29 // load the local default value
26 this._propValues[this._propNames[0]] = this._texMap.slice(0); 30 var u_tex0_index = 0;
31 this._propNames = ["u_tex0", "u_speed" ];
32 this._propLabels = ["Texture map", "Speed" ];
33 this._propTypes = ["file", "float" ];
34 this._propValues = [];
35 this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0);
36 this._propValues[this._propNames[1]] = 1.0;
37
38 this._propValues[ this._propNames[ u_tex0_index] ] = this._defaultTexMap.slice(0);
27 39
28 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
29 // Material Property Accessors 41 // Material Property Accessors
30 /////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////
43 this.isAnimated = function() { return true; };
44 this.getShaderDef = function() { return pulseMaterialDef; }
31 45
32 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
33 47
@@ -36,19 +50,6 @@ var DeformMaterial = function DeformMaterial() {
36 // Methods 50 // Methods
37 /////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////
38 // duplcate method requirde 52 // duplcate method requirde
39 this.dup = function (world) {
40 // allocate a new uber material
41 var newMat = new DeformMaterial();
42
43 // copy over the current values;
44 var propNames = [], propValues = [], propTypes = [], propLabels = [];
45 this.getAllProperties(propNames, propValues, propTypes, propLabels);
46 var n = propNames.length;
47 for (var i = 0; i < n; i++)
48 newMat.setProperty(propNames[i], propValues[i]);
49
50 return newMat;
51 };
52 53
53 this.init = function (world) { 54 this.init = function (world) {
54 // save the world 55 // save the world
@@ -69,7 +70,7 @@ var DeformMaterial = function DeformMaterial() {
69 } 70 }
70 71
71 // set the shader values in the shader 72 // set the shader values in the shader
72 this.updateTexture(); 73 this.setShaderValues();
73 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 74 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
74 this.update(0); 75 this.update(0);
75 }; 76 };
@@ -104,6 +105,7 @@ var deformMaterialDef =
104 { 105 {
105 'u_tex0': { 'type' : 'tex2d' }, 106 'u_tex0': { 'type' : 'tex2d' },
106 'u_time' : { 'type' : 'float' }, 107 'u_time' : { 'type' : 'float' },
108 'u_speed' : { 'type' : 'float' },
107 'u_resolution' : { 'type' : 'vec2' } 109 'u_resolution' : { 'type' : 'vec2' }
108 }, 110 },
109 111