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.js58
1 files changed, 22 insertions, 36 deletions
diff --git a/js/lib/rdge/materials/twist-material.js b/js/lib/rdge/materials/twist-material.js
index 7fcca081..b757afb8 100644
--- a/js/lib/rdge/materials/twist-material.js
+++ b/js/lib/rdge/materials/twist-material.js
@@ -6,46 +6,44 @@ 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() {
12 /////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////
13 // Instance variables 14 // Instance variables
14 /////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////
15 this._name = "TwistMaterial"; 16 this._name = "Twist";
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
24 // array textures indexed by shader uniform name
25 this._glTextures = [];
26
23 /////////////////////////////////////////////////////////////////////// 27 ///////////////////////////////////////////////////////////////////////
24 // Properties 28 // Material Property Accessors
25 /////////////////////////////////////////////////////////////////////// 29 ///////////////////////////////////////////////////////////////////////
26 // all defined in parent PulseMaterial.js 30 var u_tex0_index = 0, u_speed_index = 1;
27 // load the local default value 31 this._propNames = ["u_tex0", "u_speed" ];
28 this._propValues[this._propNames[0]] = this._texMap.slice(0); 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;
29 37
30 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
31 // Methods 39 // Material Property Accessors
32 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
33 // duplcate method requirde 41 this.isAnimated = function() { return true; };
34 this.dup = function (world) { 42 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 43
44 ///////////////////////////////////////////////////////////////////////
45 // Methods
46 ///////////////////////////////////////////////////////////////////////
49 this.init = function (world) { 47 this.init = function (world) {
50 // save the world 48 // save the world
51 if (world) this.setWorld(world); 49 if (world) this.setWorld(world);
@@ -65,23 +63,10 @@ var TwistMaterial = function TwistMaterial() {
65 } 63 }
66 64
67 // set the shader values in the shader 65 // set the shader values in the shader
68 this.updateTexture(); 66 this.setShaderValues();
69 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 67 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
70 this.update(0); 68 this.update(0);
71 }; 69 };
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}; 70};
86 71
87/////////////////////////////////////////////////////////////////////////////////////// 72///////////////////////////////////////////////////////////////////////////////////////
@@ -113,6 +98,7 @@ var twistMaterialDef =
113 { 98 {
114 'u_tex0': { 'type': 'tex2d' }, 99 'u_tex0': { 'type': 'tex2d' },
115 'u_time': { 'type': 'float' }, 100 'u_time': { 'type': 'float' },
101 'u_speed': { 'type': 'float' },
116 'u_resolution': { 'type': 'vec2' } 102 'u_resolution': { 'type': 'vec2' }
117 }, 103 },
118 104