diff options
Diffstat (limited to 'js/lib/rdge/materials/tunnel-material.js')
-rw-r--r-- | js/lib/rdge/materials/tunnel-material.js | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/js/lib/rdge/materials/tunnel-material.js b/js/lib/rdge/materials/tunnel-material.js index 83bf9021..34e96ef9 100644 --- a/js/lib/rdge/materials/tunnel-material.js +++ b/js/lib/rdge/materials/tunnel-material.js | |||
@@ -6,45 +6,43 @@ | |||
6 | 6 | ||
7 | 7 | ||
8 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | 8 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; |
9 | var Texture = require("js/lib/rdge/texture").Texture; | ||
9 | 10 | ||
10 | var TunnelMaterial = function TunnelMaterial() { | 11 | var TunnelMaterial = function TunnelMaterial() { |
11 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
12 | // Instance variables | 13 | // Instance variables |
13 | /////////////////////////////////////////////////////////////////////// | 14 | /////////////////////////////////////////////////////////////////////// |
14 | this._name = "TunnelMaterial"; | 15 | this._name = "Tunnel"; |
15 | this._shaderName = "tunnel"; | 16 | this._shaderName = "tunnel"; |
16 | 17 | ||
17 | this._texMap = 'assets/images/rocky-normal.jpg'; | 18 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; |
18 | 19 | ||
19 | this._time = 0.0; | 20 | this._time = 0.0; |
20 | this._dTime = 0.001; | 21 | this._dTime = 0.001; |
21 | 22 | ||
23 | // array textures indexed by shader uniform name | ||
24 | this._glTextures = []; | ||
25 | |||
22 | /////////////////////////////////////////////////////////////////////// | 26 | /////////////////////////////////////////////////////////////////////// |
23 | // Properties | 27 | // Material Property Accessors |
24 | /////////////////////////////////////////////////////////////////////// | 28 | /////////////////////////////////////////////////////////////////////// |
25 | // all defined in parent PulseMaterial.js | 29 | var u_tex0_index = 0, u_speed_index = 1; |
26 | // load the local default value | 30 | this._propNames = ["u_tex0", "u_speed" ]; |
27 | this._propValues[this._propNames[0]] = this._texMap.slice(0); | 31 | this._propLabels = ["Texture map", "Speed" ]; |
32 | this._propTypes = ["file", "float" ]; | ||
33 | this._propValues = []; | ||
34 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | ||
35 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
28 | 36 | ||
29 | /////////////////////////////////////////////////////////////////////// | 37 | /////////////////////////////////////////////////////////////////////// |
30 | // Methods | 38 | // Material Property Accessors |
31 | /////////////////////////////////////////////////////////////////////// | 39 | /////////////////////////////////////////////////////////////////////// |
32 | // duplcate method requirde | 40 | this.isAnimated = function() { return true; }; |
33 | this.dup = function (world) { | 41 | this.getShaderDef = function() { return tunnelMaterialDef; }; |
34 | // allocate a new uber material | ||
35 | var newMat = new TunnelMaterial(); | ||
36 | |||
37 | // copy over the current values; | ||
38 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
39 | this.getAllProperties(propNames, propValues, propTypes, propLabels); | ||
40 | var n = propNames.length; | ||
41 | for (var i = 0; i < n; i++) { | ||
42 | newMat.setProperty(propNames[i], propValues[i]); | ||
43 | } | ||
44 | |||
45 | return newMat; | ||
46 | }; | ||
47 | 42 | ||
43 | /////////////////////////////////////////////////////////////////////// | ||
44 | // Methods | ||
45 | /////////////////////////////////////////////////////////////////////// | ||
48 | this.init = function (world) { | 46 | this.init = function (world) { |
49 | // save the world | 47 | // save the world |
50 | if (world) this.setWorld(world); | 48 | if (world) this.setWorld(world); |
@@ -64,7 +62,7 @@ var TunnelMaterial = function TunnelMaterial() { | |||
64 | } | 62 | } |
65 | 63 | ||
66 | // set the shader values in the shader | 64 | // set the shader values in the shader |
67 | this.updateTexture(); | 65 | this.setShaderValues(); |
68 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); | 66 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); |
69 | this.update(0); | 67 | this.update(0); |
70 | }; | 68 | }; |
@@ -99,6 +97,7 @@ var tunnelMaterialDef = | |||
99 | { | 97 | { |
100 | 'u_tex0': { 'type' : 'tex2d' }, | 98 | 'u_tex0': { 'type' : 'tex2d' }, |
101 | 'u_time' : { 'type' : 'float' }, | 99 | 'u_time' : { 'type' : 'float' }, |
100 | 'u_speed' : { 'type' : 'float' }, | ||
102 | 'u_resolution' : { 'type' : 'vec2' } | 101 | 'u_resolution' : { 'type' : 'vec2' } |
103 | }, | 102 | }, |
104 | 103 | ||