diff options
Diffstat (limited to 'js/lib/rdge/materials/mandel-material.js')
-rw-r--r-- | js/lib/rdge/materials/mandel-material.js | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index a82a4bfc..e1c19145 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-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 MandelMaterial = function MandelMaterial() { | 10 | var MandelMaterial = function MandelMaterial() { |
10 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
@@ -13,7 +14,7 @@ var MandelMaterial = function MandelMaterial() { | |||
13 | this._name = "MandelMaterial"; | 14 | this._name = "MandelMaterial"; |
14 | this._shaderName = "mandel"; | 15 | this._shaderName = "mandel"; |
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; |
@@ -26,31 +27,23 @@ var MandelMaterial = function MandelMaterial() { | |||
26 | /////////////////////////////////////////////////////////////////////// | 27 | /////////////////////////////////////////////////////////////////////// |
27 | // Material Property Accessors | 28 | // Material Property Accessors |
28 | /////////////////////////////////////////////////////////////////////// | 29 | /////////////////////////////////////////////////////////////////////// |
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; | ||
29 | 37 | ||
30 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
31 | 39 | ||
32 | this.isAnimated = function() { | 40 | this.isAnimated = function() { return true; }; |
33 | return true; | 41 | this.getShaderDef = function() { return MandelMaterialDef; } |
34 | }; | ||
35 | 42 | ||
36 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
37 | // Methods | 44 | // Methods |
38 | /////////////////////////////////////////////////////////////////////// | 45 | /////////////////////////////////////////////////////////////////////// |
39 | // duplcate method requirde | 46 | // duplcate method requirde |
40 | this.dup = function( world ) { | ||
41 | // allocate a new uber material | ||
42 | var newMat = new MandelMaterial(); | ||
43 | |||
44 | // copy over the current values; | ||
45 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
46 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
47 | var n = propNames.length; | ||
48 | for (var i=0; i<n; i++) { | ||
49 | newMat.setProperty( propNames[i], propValues[i] ); | ||
50 | } | ||
51 | |||
52 | return newMat; | ||
53 | }; | ||
54 | 47 | ||
55 | this.init = function( world ) { | 48 | this.init = function( world ) { |
56 | // save the world | 49 | // save the world |
@@ -71,22 +64,10 @@ var MandelMaterial = function MandelMaterial() { | |||
71 | } | 64 | } |
72 | 65 | ||
73 | // set the shader values in the shader | 66 | // set the shader values in the shader |
67 | this.setShaderValues(); | ||
74 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | 68 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); |
75 | this.update( 0 ); | 69 | this.update( 0 ); |
76 | }; | 70 | }; |
77 | |||
78 | this.update = function( time ) { | ||
79 | var material = this._materialNode; | ||
80 | if (material) { | ||
81 | var technique = material.shaderProgram['default']; | ||
82 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
83 | if (renderer && technique) { | ||
84 | if (this._shader && this._shader['default']) | ||
85 | this._shader['default'].u_time.set( [this._time] ); | ||
86 | this._time = time; | ||
87 | } | ||
88 | } | ||
89 | }; | ||
90 | }; | 71 | }; |
91 | 72 | ||
92 | /////////////////////////////////////////////////////////////////////////////////////// | 73 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -118,6 +99,7 @@ var MandelMaterialDef = | |||
118 | { | 99 | { |
119 | 'u_tex0': { 'type' : 'tex2d' }, | 100 | 'u_tex0': { 'type' : 'tex2d' }, |
120 | 'u_time' : { 'type' : 'float' }, | 101 | 'u_time' : { 'type' : 'float' }, |
102 | 'u_speed' : { 'type' : 'float' }, | ||
121 | 'u_resolution' : { 'type' : 'vec2' }, | 103 | 'u_resolution' : { 'type' : 'vec2' }, |
122 | }, | 104 | }, |
123 | 105 | ||