aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/twist-material.js')
-rw-r--r--js/lib/rdge/materials/twist-material.js57
1 files changed, 17 insertions, 40 deletions
diff --git a/js/lib/rdge/materials/twist-material.js b/js/lib/rdge/materials/twist-material.js
index 9e2c124a..35f7eda2 100644
--- a/js/lib/rdge/materials/twist-material.js
+++ b/js/lib/rdge/materials/twist-material.js
@@ -16,38 +16,31 @@ var TwistMaterial = function TwistMaterial() {
16 this._name = "TwistMaterial"; 16 this._name = "TwistMaterial";
17 this._shaderName = "twist"; 17 this._shaderName = "twist";
18 18
19 this._texMap = 'assets/images/rocky-normal.jpg'; 19 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
20 20
21 this._time = 0.0; 21 this._time = 0.0;
22 this._dTime = 0.01; 22 this._dTime = 0.01;
23 23
24 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
25 // Properties 25 // Material Property Accessors
26 /////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////
27 // all defined in parent PulseMaterial.js 27 var u_tex0_index = 0, u_speed_index = 1;
28 // load the local default value 28 this._propNames = ["u_tex0", "u_speed" ];
29 this._propValues[this._propNames[0]] = this._texMap.slice(0); 29 this._propLabels = ["Texture map", "Speed" ];
30 this._propTypes = ["file", "float" ];
31 this._propValues = [];
32 this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0);
33 this._propValues[this._propNames[u_speed_index]] = 1.0;
30 34
31 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
32 // Methods 36 // Material Property Accessors
33 /////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////
34 // duplcate method requirde 38 this.isAnimated = function() { return true; };
35 this.dup = function (world) { 39 this.getShaderDef = function() { return twistMaterialDef; };
36 // get the current values;
37 var propNames = [], propValues = [], propTypes = [], propLabels = [];
38 this.getAllProperties(propNames, propValues, propTypes, propLabels);
39
40 // allocate a new material
41 var newMat = new TwistMaterial();
42
43 // copy over the current values;
44 var n = propNames.length;
45 for (var i = 0; i < n; i++)
46 newMat.setProperty(propNames[i], propValues[i]);
47
48 return newMat;
49 };
50 40
41 ///////////////////////////////////////////////////////////////////////
42 // Methods
43 ///////////////////////////////////////////////////////////////////////
51 this.init = function (world) { 44 this.init = function (world) {
52 // save the world 45 // save the world
53 if (world) this.setWorld(world); 46 if (world) this.setWorld(world);
@@ -66,28 +59,11 @@ var TwistMaterial = function TwistMaterial() {
66 this._shader['default'].u_time.set([this._time]); 59 this._shader['default'].u_time.set([this._time]);
67 } 60 }
68 61
69 // set up the texture
70 var texMapName = this._propValues[this._propNames[0]];
71 this._glTex = new Texture( world, texMapName );
72
73 // set the shader values in the shader 62 // set the shader values in the shader
74 this.updateTexture(); 63 this.setShaderValues();
75 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 64 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
76 this.update(0); 65 this.update(0);
77 }; 66 };
78
79 this.update = function (time) {
80 var material = this._materialNode;
81 if (material) {
82 var technique = material.shaderProgram['default'];
83 var renderer = RDGE.globals.engine.getContext().renderer;
84 if (renderer && technique) {
85 if (this._shader && this._shader['default'])
86 this._shader['default'].u_time.set([this._time]);
87 this._time = time;
88 }
89 }
90 };
91}; 67};
92 68
93/////////////////////////////////////////////////////////////////////////////////////// 69///////////////////////////////////////////////////////////////////////////////////////
@@ -119,6 +95,7 @@ var twistMaterialDef =
119 { 95 {
120 'u_tex0': { 'type': 'tex2d' }, 96 'u_tex0': { 'type': 'tex2d' },
121 'u_time': { 'type': 'float' }, 97 'u_time': { 'type': 'float' },
98 'u_speed': { 'type': 'float' },
122 'u_resolution': { 'type': 'vec2' } 99 'u_resolution': { 'type': 'vec2' }
123 }, 100 },
124 101