diff options
Diffstat (limited to 'js/lib/rdge/materials/keleidoscope-material.js')
-rw-r--r-- | js/lib/rdge/materials/keleidoscope-material.js | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js index 4506bb8c..2754420f 100644 --- a/js/lib/rdge/materials/keleidoscope-material.js +++ b/js/lib/rdge/materials/keleidoscope-material.js | |||
@@ -5,6 +5,7 @@ | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | 7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; |
8 | var Texture = require("js/lib/rdge/texture").Texture; | ||
8 | 9 | ||
9 | var KeleidoscopeMaterial = function KeleidoscopeMaterial() { | 10 | var KeleidoscopeMaterial = function KeleidoscopeMaterial() { |
10 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
@@ -13,7 +14,7 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { | |||
13 | this._name = "KeleidoscopeMaterial"; | 14 | this._name = "KeleidoscopeMaterial"; |
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; |
@@ -23,11 +24,19 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { | |||
23 | /////////////////////////////////////////////////////////////////////// | 24 | /////////////////////////////////////////////////////////////////////// |
24 | // all defined in parent PulseMaterial.js | 25 | // all defined in parent PulseMaterial.js |
25 | // load the local default value | 26 | // load the local default value |
26 | 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; | ||
27 | 34 | ||
28 | /////////////////////////////////////////////////////////////////////// | 35 | /////////////////////////////////////////////////////////////////////// |
29 | // Material Property Accessors | 36 | // Material Property Accessors |
30 | /////////////////////////////////////////////////////////////////////// | 37 | /////////////////////////////////////////////////////////////////////// |
38 | this.isAnimated = function() { return true; }; | ||
39 | this.getShaderDef = function() { return keleidoscopeMaterialDef; } | ||
31 | 40 | ||
32 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
33 | 42 | ||
@@ -36,19 +45,6 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { | |||
36 | // Methods | 45 | // Methods |
37 | /////////////////////////////////////////////////////////////////////// | 46 | /////////////////////////////////////////////////////////////////////// |
38 | // duplcate method requirde | 47 | // 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 | 48 | ||
53 | this.init = function( world ) { | 49 | this.init = function( world ) { |
54 | // save the world | 50 | // save the world |
@@ -69,28 +65,10 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { | |||
69 | } | 65 | } |
70 | 66 | ||
71 | // set the shader values in the shader | 67 | // set the shader values in the shader |
72 | this.updateTexture(); | 68 | this.setShaderValues(); |
73 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | 69 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); |
74 | this.update( 0 ); | 70 | this.update( 0 ); |
75 | }; | 71 | }; |
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 | }; | 72 | }; |
95 | 73 | ||
96 | /////////////////////////////////////////////////////////////////////////////////////// | 74 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -121,6 +99,7 @@ var keleidoscopeMaterialDef = | |||
121 | 'params' : | 99 | 'params' : |
122 | { | 100 | { |
123 | 'u_tex0': { 'type' : 'tex2d' }, | 101 | 'u_tex0': { 'type' : 'tex2d' }, |
102 | 'u_speed' : { 'type' : 'float' }, | ||
124 | 'u_time' : { 'type' : 'float' }, | 103 | 'u_time' : { 'type' : 'float' }, |
125 | 'u_resolution' : { 'type' : 'vec2' }, | 104 | 'u_resolution' : { 'type' : 'vec2' }, |
126 | }, | 105 | }, |