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, 17 insertions, 35 deletions
diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js
index 4506bb8c..b16d9022 100644
--- a/js/lib/rdge/materials/keleidoscope-material.js
+++ b/js/lib/rdge/materials/keleidoscope-material.js
@@ -5,29 +5,41 @@
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 KeleidoscopeMaterial = function KeleidoscopeMaterial() { 10var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
10 /////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////
11 // Instance variables 12 // Instance variables
12 /////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////
13 this._name = "KeleidoscopeMaterial"; 14 this._name = "Keleidoscope";
14 this._shaderName = "keleidoscope"; 15 this._shaderName = "keleidoscope";
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;
27 37
28 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
29 // Material Property Accessors 39 // Material Property Accessors
30 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
41 this.isAnimated = function() { return true; };
42 this.getShaderDef = function() { return keleidoscopeMaterialDef; }
31 43
32 /////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////
33 45
@@ -36,19 +48,6 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
36 // Methods 48 // Methods
37 /////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////
38 // duplcate method requirde 50 // duplcate method requirde
39 this.dup = function( world ) {
40 // allocate a new uber material
41 var newMat = new KeleidoscopeMaterial();
42
43 // copy over the current values;
44 var propNames = [], propValues = [], propTypes = [], propLabels = [];
45 this.getAllProperties( propNames, propValues, propTypes, propLabels);
46 var n = propNames.length;
47 for (var i=0; i<n; i++)
48 newMat.setProperty( propNames[i], propValues[i] );
49
50 return newMat;
51 };
52 51
53 this.init = function( world ) { 52 this.init = function( world ) {
54 // save the world 53 // save the world
@@ -69,28 +68,10 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() {
69 } 68 }
70 69
71 // set the shader values in the shader 70 // set the shader values in the shader
72 this.updateTexture(); 71 this.setShaderValues();
73 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 72 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
74 this.update( 0 ); 73 this.update( 0 );
75 }; 74 };
76
77 this.update = function( time )
78 {
79 var material = this._materialNode;
80 if (material)
81 {
82 var technique = material.shaderProgram['default'];
83 var renderer = RDGE.globals.engine.getContext().renderer;
84 if (renderer && technique)
85 {
86 if (this._shader && this._shader['default']) {
87 this._shader['default'].u_time.set( [this._time] );
88 }
89
90 this._time = time;
91 }
92 }
93 };
94}; 75};
95 76
96/////////////////////////////////////////////////////////////////////////////////////// 77///////////////////////////////////////////////////////////////////////////////////////
@@ -121,6 +102,7 @@ var keleidoscopeMaterialDef =
121 'params' : 102 'params' :
122 { 103 {
123 'u_tex0': { 'type' : 'tex2d' }, 104 'u_tex0': { 'type' : 'tex2d' },
105 'u_speed' : { 'type' : 'float' },
124 'u_time' : { 'type' : 'float' }, 106 'u_time' : { 'type' : 'float' },
125 'u_resolution' : { 'type' : 'vec2' }, 107 'u_resolution' : { 'type' : 'vec2' },
126 }, 108 },