diff options
Diffstat (limited to 'js/lib/rdge/materials/star-material.js')
-rw-r--r-- | js/lib/rdge/materials/star-material.js | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js index f3f4474d..c99a1639 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,35 @@ 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 | // array textures indexed by shader uniform name |
22 | // Properties | 23 | this._glTextures = []; |
23 | /////////////////////////////////////////////////////////////////////// | 24 | |
24 | // all defined in parent PulseMaterial.js | 25 | /////////////////////////////////////////////////////////////////////// |
25 | // load the local default value | 26 | // Property Accessors |
26 | this._propValues[this._propNames[0]] = this._texMap.slice(0); | 27 | /////////////////////////////////////////////////////////////////////// |
28 | this.isAnimated = function() { return true; }; | ||
29 | this.getShaderDef = function() { return starMaterialDef; } | ||
30 | |||
31 | /////////////////////////////////////////////////////////////////////// | ||
32 | // Material Property Accessors | ||
33 | /////////////////////////////////////////////////////////////////////// | ||
34 | var u_tex0_index = 0, u_speed_index = 1; | ||
35 | this._propNames = ["u_tex0", "u_speed" ]; | ||
36 | this._propLabels = ["Texture map", "Speed" ]; | ||
37 | this._propTypes = ["file", "float" ]; | ||
38 | this._propValues = []; | ||
39 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | ||
40 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
41 | /////////////////////////////////////////////////////////////////////// | ||
27 | 42 | ||
28 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
29 | // Methods | 44 | // Methods |
30 | /////////////////////////////////////////////////////////////////////// | 45 | /////////////////////////////////////////////////////////////////////// |
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 | 46 | ||
47 | this.init = function (world) { | 47 | this.init = function (world) { |
48 | // save the world | 48 | // save the world |
@@ -62,8 +62,12 @@ var StarMaterial = function StarMaterial() { | |||
62 | this._shader['default'].u_time.set([this._time]); | 62 | this._shader['default'].u_time.set([this._time]); |
63 | } | 63 | } |
64 | 64 | ||
65 | // set up the texture | ||
66 | var texMapName = this._propValues[this._propNames[0]]; | ||
67 | this._glTex = new Texture( world, texMapName ); | ||
68 | |||
65 | // set the shader values in the shader | 69 | // set the shader values in the shader |
66 | this.updateTexture(); | 70 | this.setShaderValues(); |
67 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); | 71 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); |
68 | this.update(0); | 72 | this.update(0); |
69 | }; | 73 | }; |
@@ -98,6 +102,7 @@ var starMaterialDef = | |||
98 | { | 102 | { |
99 | 'u_tex0': { 'type': 'tex2d' }, | 103 | 'u_tex0': { 'type': 'tex2d' }, |
100 | 'u_time': { 'type': 'float' }, | 104 | 'u_time': { 'type': 'float' }, |
105 | 'u_speed': { 'type': 'float' }, | ||
101 | 'u_resolution': { 'type': 'vec2' } | 106 | 'u_resolution': { 'type': 'vec2' } |
102 | }, | 107 | }, |
103 | 108 | ||