diff options
Diffstat (limited to 'js/lib/rdge/materials/deform-material.js')
-rw-r--r-- | js/lib/rdge/materials/deform-material.js | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js index 328330bf..7ff5b3e3 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 | ||
7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | 7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; |
8 | var Texture = require("js/lib/rdge/texture").Texture; | ||
8 | 9 | ||
9 | var DeformMaterial = function DeformMaterial() { | 10 | var DeformMaterial = function DeformMaterial() { |
10 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
@@ -13,21 +14,34 @@ 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; |
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 | ||