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.js53
1 files changed, 18 insertions, 35 deletions
diff --git a/js/lib/rdge/materials/twist-material.js b/js/lib/rdge/materials/twist-material.js
index 7fcca081..35f7eda2 100644
--- a/js/lib/rdge/materials/twist-material.js
+++ b/js/lib/rdge/materials/twist-material.js
@@ -6,6 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7 7
8var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; 8var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
9var Texture = require("js/lib/rdge/texture").Texture;
9 10
10/////////////////////////////////////////////////////////////////////// 11///////////////////////////////////////////////////////////////////////
11var TwistMaterial = function TwistMaterial() { 12var TwistMaterial = function TwistMaterial() {
@@ -15,37 +16,31 @@ var TwistMaterial = function TwistMaterial() {
15 this._name = "TwistMaterial"; 16 this._name = "TwistMaterial";
16 this._shaderName = "twist"; 17 this._shaderName = "twist";
17 18
18 this._texMap = 'assets/images/rocky-normal.jpg'; 19 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
19 20
20 this._time = 0.0; 21 this._time = 0.0;
21 this._dTime = 0.01; 22 this._dTime = 0.01;
22 23
23 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
24 // Properties 25 // Material Property Accessors
25 /////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////
26 // all defined in parent PulseMaterial.js 27 var u_tex0_index = 0, u_speed_index = 1;
27 // load the local default value 28 this._propNames = ["u_tex0", "u_speed" ];
28 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;
29 34
30 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
31 // Methods 36 // Material Property Accessors
32 /////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////
33 // duplcate method requirde 38 this.isAnimated = function() { return true; };
34 this.dup = function (world) { 39 this.getShaderDef = function() { return twistMaterialDef; };
35 // allocate a new uber material
36 var newMat = new TwistMaterial();
37
38 // copy over the current values;
39 var propNames = [], propValues = [], propTypes = [], propLabels = [];
40 this.getAllProperties(propNames, propValues, propTypes, propLabels);
41 var n = propNames.length;
42 for (var i = 0; i < n; i++) {
43 newMat.setProperty(propNames[i], propValues[i]);
44 }
45
46 return newMat;
47 };
48 40
41 ///////////////////////////////////////////////////////////////////////
42 // Methods
43 ///////////////////////////////////////////////////////////////////////
49 this.init = function (world) { 44 this.init = function (world) {
50 // save the world 45 // save the world
51 if (world) this.setWorld(world); 46 if (world) this.setWorld(world);
@@ -65,23 +60,10 @@ var TwistMaterial = function TwistMaterial() {
65 } 60 }
66 61
67 // set the shader values in the shader 62 // set the shader values in the shader
68 this.updateTexture(); 63 this.setShaderValues();
69 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 64 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
70 this.update(0); 65 this.update(0);
71 }; 66 };
72
73 this.update = function (time) {
74 var material = this._materialNode;
75 if (material) {
76 var technique = material.shaderProgram['default'];
77 var renderer = RDGE.globals.engine.getContext().renderer;
78 if (renderer && technique) {
79 if (this._shader && this._shader['default'])
80 this._shader['default'].u_time.set([this._time]);
81 this._time = time;
82 }
83 }
84 };
85}; 67};
86 68
87/////////////////////////////////////////////////////////////////////////////////////// 69///////////////////////////////////////////////////////////////////////////////////////
@@ -113,6 +95,7 @@ var twistMaterialDef =
113 { 95 {
114 'u_tex0': { 'type': 'tex2d' }, 96 'u_tex0': { 'type': 'tex2d' },
115 'u_time': { 'type': 'float' }, 97 'u_time': { 'type': 'float' },
98 'u_speed': { 'type': 'float' },
116 'u_resolution': { 'type': 'vec2' } 99 'u_resolution': { 'type': 'vec2' }
117 }, 100 },
118 101