aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/fly-material.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-19 10:25:16 -0700
committerJose Antonio Marquez2012-06-19 10:25:16 -0700
commit4d2a5acd1631f0cf4e38f127c886f481668ddce0 (patch)
tree3bc8f2b21826c0ee6d37bc77753d45a882783cbf /js/lib/rdge/materials/fly-material.js
parent616b31a644ee221edcbc19f821b2194e8edf9fad (diff)
parent483ad57efcd6475776f580c3af5b60e6deeaf781 (diff)
downloadninja-4d2a5acd1631f0cf4e38f127c886f481668ddce0.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/lib/rdge/materials/fly-material.js')
-rw-r--r--js/lib/rdge/materials/fly-material.js38
1 files changed, 21 insertions, 17 deletions
diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js
index 37bef66a..4e8bd9b5 100644
--- a/js/lib/rdge/materials/fly-material.js
+++ b/js/lib/rdge/materials/fly-material.js
@@ -5,43 +5,46 @@
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 FlyMaterial = function FlyMaterial() { 10var FlyMaterial = function FlyMaterial() {
10 /////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////
11 // Instance variables 12 // Instance variables
12 /////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////
13 this._name = "FlyMaterial"; 14 this._name = "Fly";
14 this._shaderName = "fly"; 15 this._shaderName = "fly";
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, u_speed_index = 1;
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[u_tex0_index]] = this._defaultTexMap.slice(0);
36 this._propValues[this._propNames[u_speed_index]] = 1.0;
37
38 ///////////////////////////////////////////////////////////////////////
39 // Material Property Accessors
40 ///////////////////////////////////////////////////////////////////////
41 this.isAnimated = function() { return true; };
42 this.getShaderDef = function() { return flyMaterialDef; };
27 43
28 /////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////
29 // Methods 45 // Methods
30 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
31 // duplcate method requirde 47 // duplcate method requirde
32 this.dup = function( world ) {
33 // allocate a new uber material
34 var newMat = new FlyMaterial();
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 return newMat;
44 };
45 48
46 this.init = function( world ) { 49 this.init = function( world ) {
47 // save the world 50 // save the world
@@ -62,7 +65,7 @@ var FlyMaterial = function FlyMaterial() {
62 } 65 }
63 66
64 // set the shader values in the shader 67 // set the shader values in the shader
65 this.updateTexture(); 68 this.setShaderValues();
66 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 69 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
67 this.update( 0 ); 70 this.update( 0 );
68 }; 71 };
@@ -98,6 +101,7 @@ var flyMaterialDef =
98 { 101 {
99 'u_tex0': { 'type' : 'tex2d' }, 102 'u_tex0': { 'type' : 'tex2d' },
100 'u_time' : { 'type' : 'float' }, 103 'u_time' : { 'type' : 'float' },
104 'u_speed' : { 'type' : 'float' },
101 'u_resolution' : { 'type' : 'vec2' }, 105 'u_resolution' : { 'type' : 'vec2' },
102 }, 106 },
103 107