diff options
Diffstat (limited to 'js/lib/rdge/materials/mandel-material.js')
-rw-r--r-- | js/lib/rdge/materials/mandel-material.js | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index a82a4bfc..4f3def4a 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js | |||
@@ -5,16 +5,15 @@ | |||
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 | /////////////////////////////////////////////////////////////////////// |
11 | // Instance variables | 12 | // Instance variables |
12 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
13 | this._name = "MandelMaterial"; | 14 | this._name = "Mandel"; |
14 | this._shaderName = "mandel"; | 15 | this._shaderName = "mandel"; |
15 | 16 | ||
16 | this._texMap = 'assets/images/rocky-normal.jpg'; | ||
17 | |||
18 | this._time = 0.0; | 17 | this._time = 0.0; |
19 | this._dTime = 0.01; | 18 | this._dTime = 0.01; |
20 | 19 | ||
@@ -26,31 +25,22 @@ var MandelMaterial = function MandelMaterial() { | |||
26 | /////////////////////////////////////////////////////////////////////// | 25 | /////////////////////////////////////////////////////////////////////// |
27 | // Material Property Accessors | 26 | // Material Property Accessors |
28 | /////////////////////////////////////////////////////////////////////// | 27 | /////////////////////////////////////////////////////////////////////// |
28 | var u_speed_index = 0; | ||
29 | this._propNames = [ "u_speed" ]; | ||
30 | this._propLabels = [ "Speed" ]; | ||
31 | this._propTypes = [ "float" ]; | ||
32 | this._propValues = []; | ||
33 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
29 | 34 | ||
30 | /////////////////////////////////////////////////////////////////////// | 35 | /////////////////////////////////////////////////////////////////////// |
31 | 36 | ||
32 | this.isAnimated = function() { | 37 | this.isAnimated = function() { return true; }; |
33 | return true; | 38 | this.getShaderDef = function() { return MandelMaterialDef; } |
34 | }; | ||
35 | 39 | ||
36 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
37 | // Methods | 41 | // Methods |
38 | /////////////////////////////////////////////////////////////////////// | 42 | /////////////////////////////////////////////////////////////////////// |
39 | // duplcate method requirde | 43 | // 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 | 44 | ||
55 | this.init = function( world ) { | 45 | this.init = function( world ) { |
56 | // save the world | 46 | // save the world |
@@ -71,22 +61,10 @@ var MandelMaterial = function MandelMaterial() { | |||
71 | } | 61 | } |
72 | 62 | ||
73 | // set the shader values in the shader | 63 | // set the shader values in the shader |
64 | this.setShaderValues(); | ||
74 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | 65 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); |
75 | this.update( 0 ); | 66 | this.update( 0 ); |
76 | }; | 67 | }; |
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 | }; | 68 | }; |
91 | 69 | ||
92 | /////////////////////////////////////////////////////////////////////////////////////// | 70 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -116,8 +94,8 @@ var MandelMaterialDef = | |||
116 | // parameters | 94 | // parameters |
117 | 'params' : | 95 | 'params' : |
118 | { | 96 | { |
119 | 'u_tex0': { 'type' : 'tex2d' }, | ||
120 | 'u_time' : { 'type' : 'float' }, | 97 | 'u_time' : { 'type' : 'float' }, |
98 | 'u_speed' : { 'type' : 'float' }, | ||
121 | 'u_resolution' : { 'type' : 'vec2' }, | 99 | 'u_resolution' : { 'type' : 'vec2' }, |
122 | }, | 100 | }, |
123 | 101 | ||