aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/keleidoscope-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/keleidoscope-material.js')
-rw-r--r--js/lib/rdge/materials/keleidoscope-material.js52
1 files changed, 12 insertions, 40 deletions
diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js
index e9f1b10e..2754420f 100644
--- a/js/lib/rdge/materials/keleidoscope-material.js
+++ b/js/lib/rdge/materials/keleidoscope-material.js
@@ -14,7 +14,7 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
14 this._name = "KeleidoscopeMaterial"; 14 this._name = "KeleidoscopeMaterial";
15 this._shaderName = "keleidoscope"; 15 this._shaderName = "keleidoscope";
16 16
17 this._texMap = 'assets/images/rocky-normal.jpg'; 17 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
18 18
19 this._time = 0.0; 19 this._time = 0.0;
20 this._dTime = 0.01; 20 this._dTime = 0.01;
@@ -24,11 +24,19 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
24 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
25 // all defined in parent PulseMaterial.js 25 // all defined in parent PulseMaterial.js
26 // load the local default value 26 // load the local default value
27 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 27 var u_tex0_index = 0, u_speed_index = 1;
28 this._propNames = ["u_tex0", "u_speed" ];
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;
28 34
29 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
30 // Material Property Accessors 36 // Material Property Accessors
31 /////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////
38 this.isAnimated = function() { return true; };
39 this.getShaderDef = function() { return keleidoscopeMaterialDef; }
32 40
33 /////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////
34 42
@@ -37,21 +45,6 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
37 // Methods 45 // Methods
38 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
39 // duplcate method requirde 47 // duplcate method requirde
40 this.dup = function( world ) {
41 // get the current values;
42 var propNames = [], propValues = [], propTypes = [], propLabels = [];
43 this.getAllProperties(propNames, propValues, propTypes, propLabels);
44
45 // allocate a new material
46 var newMat = new KeleidoscopeMaterial();
47
48 // copy over the current values;
49 var n = propNames.length;
50 for (var i = 0; i < n; i++)
51 newMat.setProperty(propNames[i], propValues[i]);
52
53 return newMat;
54 };
55 48
56 this.init = function( world ) { 49 this.init = function( world ) {
57 // save the world 50 // save the world
@@ -71,33 +64,11 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
71 this._shader['default'].u_time.set( [this._time] ); 64 this._shader['default'].u_time.set( [this._time] );
72 } 65 }
73 66
74 // set up the texture
75 var texMapName = this._propValues[this._propNames[0]];
76 this._glTex = new Texture( world, texMapName );
77
78 // set the shader values in the shader 67 // set the shader values in the shader
79 this.updateTexture(); 68 this.setShaderValues();
80 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 69 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
81 this.update( 0 ); 70 this.update( 0 );
82 }; 71 };
83
84 this.update = function( time )
85 {
86 var material = this._materialNode;
87 if (material)
88 {
89 var technique = material.shaderProgram['default'];
90 var renderer = RDGE.globals.engine.getContext().renderer;
91 if (renderer && technique)
92 {
93 if (this._shader && this._shader['default']) {
94 this._shader['default'].u_time.set( [this._time] );
95 }
96
97 this._time = time;
98 }
99 }
100 };
101}; 72};
102 73
103/////////////////////////////////////////////////////////////////////////////////////// 74///////////////////////////////////////////////////////////////////////////////////////
@@ -128,6 +99,7 @@ var keleidoscopeMaterialDef =
128 'params' : 99 'params' :
129 { 100 {
130 'u_tex0': { 'type' : 'tex2d' }, 101 'u_tex0': { 'type' : 'tex2d' },
102 'u_speed' : { 'type' : 'float' },
131 'u_time' : { 'type' : 'float' }, 103 'u_time' : { 'type' : 'float' },
132 'u_resolution' : { 'type' : 'vec2' }, 104 'u_resolution' : { 'type' : 'vec2' },
133 }, 105 },