aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/star-material.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-06-19 07:58:10 -0700
committerValerio Virgillito2012-06-19 07:58:10 -0700
commit483ad57efcd6475776f580c3af5b60e6deeaf781 (patch)
tree3bc8f2b21826c0ee6d37bc77753d45a882783cbf /js/lib/rdge/materials/star-material.js
parent918a4f5870e972b6e4e301c3237e065a1ffd26f5 (diff)
parentc65c532d081afd73e4a325abe4ab97c6726c02db (diff)
downloadninja-483ad57efcd6475776f580c3af5b60e6deeaf781.tar.gz
Merge pull request #298 from ericmueller/Textures
Textures
Diffstat (limited to 'js/lib/rdge/materials/star-material.js')
-rw-r--r--js/lib/rdge/materials/star-material.js53
1 files changed, 29 insertions, 24 deletions
diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js
index f3f4474d..760cf128 100644
--- a/js/lib/rdge/materials/star-material.js
+++ b/js/lib/rdge/materials/star-material.js
@@ -5,44 +5,44 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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 StarMaterial = function StarMaterial() { 10var StarMaterial = function StarMaterial() {
10 /////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////
11 // Instance variables 12 // Instance variables
12 /////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////
13 this._name = "StarMaterial"; 14 this._name = "Star";
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