aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/deform-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/deform-material.js')
-rw-r--r--js/lib/rdge/materials/deform-material.js31
1 files changed, 15 insertions, 16 deletions
diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js
index 328330bf..91202b24 100644
--- a/js/lib/rdge/materials/deform-material.js
+++ b/js/lib/rdge/materials/deform-material.js
@@ -5,6 +5,7 @@
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 ///////////////////////////////////////////////////////////////////////
@@ -13,7 +14,7 @@ var DeformMaterial = function DeformMaterial() {
13 this._name = "DeformMaterial"; 14 this._name = "DeformMaterial";
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;
@@ -23,11 +24,21 @@ var DeformMaterial = function DeformMaterial() {
23 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
24 // all defined in parent PulseMaterial.js 25 // all defined in parent PulseMaterial.js
25 // load the local default value 26 // load the local default value
26 this._propValues[this._propNames[0]] = this._texMap.slice(0); 27 var u_tex0_index = 0;
28 this._propNames = ["u_tex0", "u_speed" ];
29 this._propLabels = ["Texture map", "Speed" ];
30 this._propTypes = ["file", "float" ];
31 this._propValues = [];
32 this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0);
33 this._propValues[this._propNames[1]] = 1.0;
34
35 this._propValues[ this._propNames[ u_tex0_index] ] = this._defaultTexMap.slice(0);
27 36
28 /////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////
29 // Material Property Accessors 38 // Material Property Accessors
30 /////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////
40 this.isAnimated = function() { return true; };
41 this.getShaderDef = function() { return pulseMaterialDef; }
31 42
32 /////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////
33 44
@@ -36,19 +47,6 @@ var DeformMaterial = function DeformMaterial() {
36 // Methods 47 // Methods
37 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
38 // duplcate method requirde 49 // 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 50
53 this.init = function (world) { 51 this.init = function (world) {
54 // save the world 52 // save the world
@@ -69,7 +67,7 @@ var DeformMaterial = function DeformMaterial() {
69 } 67 }
70 68
71 // set the shader values in the shader 69 // set the shader values in the shader
72 this.updateTexture(); 70 this.setShaderValues();
73 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 71 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
74 this.update(0); 72 this.update(0);
75 }; 73 };
@@ -104,6 +102,7 @@ var deformMaterialDef =
104 { 102 {
105 'u_tex0': { 'type' : 'tex2d' }, 103 'u_tex0': { 'type' : 'tex2d' },
106 'u_time' : { 'type' : 'float' }, 104 'u_time' : { 'type' : 'float' },
105 'u_speed' : { 'type' : 'float' },
107 'u_resolution' : { 'type' : 'vec2' } 106 'u_resolution' : { 'type' : 'vec2' }
108 }, 107 },
109 108