diff options
Diffstat (limited to 'js/lib/rdge/materials/star-material.js')
-rw-r--r-- | js/lib/rdge/materials/star-material.js | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js index f3f4474d..9f94b8c3 100644 --- a/js/lib/rdge/materials/star-material.js +++ b/js/lib/rdge/materials/star-material.js | |||
@@ -5,6 +5,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
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 StarMaterial = function StarMaterial() { | 10 | var StarMaterial = function StarMaterial() { |
10 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
@@ -13,36 +14,32 @@ var StarMaterial = function StarMaterial() { | |||
13 | this._name = "StarMaterial"; | 14 | this._name = "StarMaterial"; |
14 | this._shaderName = "star"; | 15 | this._shaderName = "star"; |
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 | ||
21 | /////////////////////////////////////////////////////////////////////// | 22 | /////////////////////////////////////////////////////////////////////// |
22 | // Properties | 23 | // Property Accessors |
23 | /////////////////////////////////////////////////////////////////////// | 24 | /////////////////////////////////////////////////////////////////////// |
24 | // all defined in parent PulseMaterial.js | 25 | this.isAnimated = function() { return true; }; |
25 | // load the local default value | 26 | this.getShaderDef = function() { return starMaterialDef; } |
26 | this._propValues[this._propNames[0]] = this._texMap.slice(0); | 27 | |
28 | /////////////////////////////////////////////////////////////////////// | ||
29 | // Material Property Accessors | ||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | var u_tex0_index = 0, u_speed_index = 1; | ||
32 | this._propNames = ["u_tex0", "u_speed" ]; | ||
33 | this._propLabels = ["Texture map", "Speed" ]; | ||
34 | this._propTypes = ["file", "float" ]; | ||
35 | this._propValues = []; | ||
36 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | ||
37 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
38 | /////////////////////////////////////////////////////////////////////// | ||
27 | 39 | ||
28 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
29 | // Methods | 41 | // Methods |
30 | /////////////////////////////////////////////////////////////////////// | 42 | /////////////////////////////////////////////////////////////////////// |
31 | // duplcate method requirde | ||
32 | this.dup = function () { | ||
33 | // allocate a new uber material | ||
34 | var newMat = new StarMaterial(); | ||
35 | |||
36 | // copy over the current values; | ||
37 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
38 | this.getAllProperties(propNames, propValues, propTypes, propLabels); | ||
39 | var n = propNames.length; | ||
40 | for (var i = 0; i < n; i++) { | ||
41 | newMat.setProperty(propNames[i], propValues[i]); | ||
42 | } | ||
43 | |||
44 | return newMat; | ||
45 | }; | ||
46 | 43 | ||
47 | this.init = function (world) { | 44 | this.init = function (world) { |
48 | // save the world | 45 | // save the world |
@@ -62,8 +59,12 @@ var StarMaterial = function StarMaterial() { | |||
62 | this._shader['default'].u_time.set([this._time]); | 59 | this._shader['default'].u_time.set([this._time]); |
63 | } | 60 | } |
64 | 61 | ||
62 | // set up the texture | ||
63 | var texMapName = this._propValues[this._propNames[0]]; | ||
64 | this._glTex = new Texture( world, texMapName ); | ||
65 | |||
65 | // set the shader values in the shader | 66 | // set the shader values in the shader |
66 | this.updateTexture(); | 67 | this.setShaderValues(); |
67 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); | 68 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); |
68 | this.update(0); | 69 | this.update(0); |
69 | }; | 70 | }; |
@@ -98,6 +99,7 @@ var starMaterialDef = | |||
98 | { | 99 | { |
99 | 'u_tex0': { 'type': 'tex2d' }, | 100 | 'u_tex0': { 'type': 'tex2d' }, |
100 | 'u_time': { 'type': 'float' }, | 101 | 'u_time': { 'type': 'float' }, |
102 | 'u_speed': { 'type': 'float' }, | ||
101 | 'u_resolution': { 'type': 'vec2' } | 103 | 'u_resolution': { 'type': 'vec2' } |
102 | }, | 104 | }, |
103 | 105 | ||