aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/mandel-material.js
diff options
context:
space:
mode:
authorhwc4872012-06-12 10:28:26 -0700
committerhwc4872012-06-12 10:28:26 -0700
commitd4ca478ad313c6c20834e410ba14ad3a5e7b20bf (patch)
tree28e44c5ab1b2f9dbfd32aedba51402ac2d26a0ff /js/lib/rdge/materials/mandel-material.js
parentdb2bb0ab5d2747f0d07878e3b8a7d2d10c755110 (diff)
downloadninja-d4ca478ad313c6c20834e410ba14ad3a5e7b20bf.tar.gz
Material cleanup & bug fixes.
Diffstat (limited to 'js/lib/rdge/materials/mandel-material.js')
-rw-r--r--js/lib/rdge/materials/mandel-material.js48
1 files changed, 12 insertions, 36 deletions
diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js
index e75d74ba..e1c19145 100644
--- a/js/lib/rdge/materials/mandel-material.js
+++ b/js/lib/rdge/materials/mandel-material.js
@@ -14,7 +14,7 @@ var MandelMaterial = function MandelMaterial() {
14 this._name = "MandelMaterial"; 14 this._name = "MandelMaterial";
15 this._shaderName = "mandel"; 15 this._shaderName = "mandel";
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;
@@ -27,32 +27,23 @@ var MandelMaterial = function MandelMaterial() {
27 /////////////////////////////////////////////////////////////////////// 27 ///////////////////////////////////////////////////////////////////////
28 // Material Property Accessors 28 // Material Property Accessors
29 /////////////////////////////////////////////////////////////////////// 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;
30 37
31 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
32 39
33 this.isAnimated = function() { 40 this.isAnimated = function() { return true; };
34 return true; 41 this.getShaderDef = function() { return MandelMaterialDef; }
35 };
36 42
37 /////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////
38 // Methods 44 // Methods
39 /////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////
40 // duplcate method requirde 46 // duplcate method requirde
41 this.dup = function( world ) {
42 // get the current values;
43 var propNames = [], propValues = [], propTypes = [], propLabels = [];
44 this.getAllProperties(propNames, propValues, propTypes, propLabels);
45
46 // allocate a new material
47 var newMat = new MandelMaterial();
48
49 // copy over the current values;
50 var n = propNames.length;
51 for (var i = 0; i < n; i++)
52 newMat.setProperty(propNames[i], propValues[i]);
53
54 return newMat;
55 };
56 47
57 this.init = function( world ) { 48 this.init = function( world ) {
58 // save the world 49 // save the world
@@ -72,27 +63,11 @@ var MandelMaterial = function MandelMaterial() {
72 this._shader['default'].u_time.set( [this._time] ); 63 this._shader['default'].u_time.set( [this._time] );
73 } 64 }
74 65
75 // set up the texture
76 var texMapName = this._propValues[this._propNames[0]];
77 this._glTex = new Texture( world, texMapName );
78
79 // set the shader values in the shader 66 // set the shader values in the shader
67 this.setShaderValues();
80 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 68 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
81 this.update( 0 ); 69 this.update( 0 );
82 }; 70 };
83
84 this.update = function( time ) {
85 var material = this._materialNode;
86 if (material) {
87 var technique = material.shaderProgram['default'];
88 var renderer = RDGE.globals.engine.getContext().renderer;
89 if (renderer && technique) {
90 if (this._shader && this._shader['default'])
91 this._shader['default'].u_time.set( [this._time] );
92 this._time = time;
93 }
94 }
95 };
96}; 71};
97 72
98/////////////////////////////////////////////////////////////////////////////////////// 73///////////////////////////////////////////////////////////////////////////////////////
@@ -124,6 +99,7 @@ var MandelMaterialDef =
124 { 99 {
125 'u_tex0': { 'type' : 'tex2d' }, 100 'u_tex0': { 'type' : 'tex2d' },
126 'u_time' : { 'type' : 'float' }, 101 'u_time' : { 'type' : 'float' },
102 'u_speed' : { 'type' : 'float' },
127 'u_resolution' : { 'type' : 'vec2' }, 103 'u_resolution' : { 'type' : 'vec2' },
128 }, 104 },
129 105