aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/cloud-material.js
diff options
context:
space:
mode:
authorhwc4872012-04-16 05:59:01 -0700
committerhwc4872012-04-16 05:59:01 -0700
commitc0aa5e88890fbf74124d019df96c33215da99f17 (patch)
tree9bff6d97cc19288b4d2c7bfd40a71f608b853fab /js/lib/rdge/materials/cloud-material.js
parent8992d9baf542135e910bb59328a592d9e330703a (diff)
downloadninja-c0aa5e88890fbf74124d019df96c33215da99f17.tar.gz
Cloud material
Diffstat (limited to 'js/lib/rdge/materials/cloud-material.js')
-rw-r--r--js/lib/rdge/materials/cloud-material.js53
1 files changed, 28 insertions, 25 deletions
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
index e2292c7a..2b40b84c 100644
--- a/js/lib/rdge/materials/cloud-material.js
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -31,13 +31,13 @@ var CloudMaterial = function CloudMaterial() {
31 this._cloudSize = 40; 31 this._cloudSize = 40;
32 32
33 this._time = 0.0; 33 this._time = 0.0;
34 this._dTime = 0.01; 34 this._dTime = 0.001;
35 35
36 // parameter initial values 36 // parameter initial values
37 this._time = 0.0; 37 this._time = 0.0;
38 this._surfaceAlpha = 0.6; 38 this._surfaceAlpha = 0.5;
39 this._zmin = 0.1; 39 this._zmin = 6.0;
40 this._zmax = 10.0; 40 this._zmax = 10;
41 41
42 42
43 /////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////
@@ -129,9 +129,9 @@ var CloudMaterial = function CloudMaterial() {
129 129
130 ////////////////////////////////////////////////////////////////////////////////// 130 //////////////////////////////////////////////////////////////////////////////////
131 // IS THIS NECESSARY?? 131 // IS THIS NECESSARY??
132 //var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height, 132 var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height,
133 // Matrix.I(4), [0,0,0], srcCanvas); 133 Matrix.I(4), [0,0,0], srcCanvas);
134 //ElementMediator.addElement(srcCanvas, elementModel.data, true); 134 ElementMediator.addElement(srcCanvas, elementModel.data, true);
135 ////////////////////////////////////////////////////////////////////////////////// 135 //////////////////////////////////////////////////////////////////////////////////
136 136
137 // build the source. 137 // build the source.
@@ -212,13 +212,12 @@ var CloudMaterial = function CloudMaterial() {
212 renderer = g_Engine.getContext().renderer; 212 renderer = g_Engine.getContext().renderer;
213 if (renderer && technique) 213 if (renderer && technique)
214 { 214 {
215 if (this._glTex) 215 if (this._glTex)
216 { 216 {
217 this._glTex.render(); 217 this._glTex.render();
218 tex = this._glTex.getTexture(); 218 tex = this._glTex.getTexture();
219 technique.u_tex0.set( tex ); 219 technique.u_tex0.set( tex );
220 } 220 }
221 }
222 } 221 }
223 } 222 }
224 223
@@ -230,13 +229,10 @@ var CloudMaterial = function CloudMaterial() {
230 renderer = g_Engine.getContext().renderer; 229 renderer = g_Engine.getContext().renderer;
231 if (renderer && technique) 230 if (renderer && technique)
232 { 231 {
233 if (this._shader && this._shader['default']) { 232 technique.u_time.set( [this._time] );
234 this._shader['default'].u_time.set( [this._time] );
235 }
236
237 this._time += this._dTime; 233 this._time += this._dTime;
238 if (this._time > 200.0) this._time = 0.0;
239 } 234 }
235 }
240 }; 236 };
241 237
242 this.buildSource = function() 238 this.buildSource = function()
@@ -293,6 +289,9 @@ var CloudMaterial = function CloudMaterial() {
293 } 289 }
294 } 290 }
295 291
292 // start the render loop on the source canvas
293 srcWorld.restartRenderLoop();
294
296 // restore the original context 295 // restore the original context
297 g_Engine.setContext( saveContext.id ); 296 g_Engine.setContext( saveContext.id );
298 this.getWorld().start(); 297 this.getWorld().start();
@@ -332,19 +331,25 @@ var CloudMaterial = function CloudMaterial() {
332 //this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 331 //this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
333 var ctr = [x,y], width = 2*hWidth, height = 2*hHeight; 332 var ctr = [x,y], width = 2*hWidth, height = 2*hHeight;
334 var cloudSize = width > height ? 0.25*width : 0.25*height; 333 var cloudSize = width > height ? 0.25*width : 0.25*height;
335 //var prim = RectangleGeometry.create( ctr, width, height ); 334
336 //return prim; 335 // calculate the range of z's in GL space from
336 // the user specified range
337 var zNear = world.getZNear(), zFar = world.getZFar();
338 var zMin = (-(this._zmin - world.getViewDistance())*(zFar - zNear) + 2.0*zFar*zNear)/(zFar + zNear),
339 zMax = (-(this._zmax - world.getViewDistance())*(zFar - zNear) + 2.0*zFar*zNear)/(zFar + zNear);
340 if (zMin > zMax) { var t = zMin; zMin = zMax; zMax = t; }
341 var dz = zMax - zMin;
337 342
338 var verts = [], 343 var verts = [],
339 normals = [ [0,0,1], [0,0,1], [0,0,1], [0,0,1] ], 344 normals = [ [0,0,1], [0,0,1], [0,0,1], [0,0,1] ],
340 uvs = [ [0,0], [1,0], [1,1], [0,1] ]; 345 uvs = [ [0,0], [1,0], [1,1], [0,1] ];
341 346
342 for ( i = 0; i < 12; i++ ) 347 for ( i = 0; i < 20; i++ )
343 { 348 {
344 var x = hWidth*2*(Math.random() - 0.5), 349 var x = hWidth*2*(Math.random() - 0.5),
345 //y = hHeight*2.0*(Math.random() * Math.random() - 0.5), 350 //y = hHeight*2.0*(Math.random() * Math.random() - 0.5),
346 y = hHeight*2.0*(Math.random() - 0.5), 351 y = hHeight*2.0*(Math.random() - 0.5),
347 z = 0, //i, 352 z = zMin + Math.random()*dz;
348 zRot = (Math.random() - 0.5) * Math.PI, 353 zRot = (Math.random() - 0.5) * Math.PI,
349 sz = cloudSize * Math.random(); 354 sz = cloudSize * Math.random();
350 355
@@ -357,9 +362,7 @@ var CloudMaterial = function CloudMaterial() {
357 verts[3] = [ sz, -sz, 0]; 362 verts[3] = [ sz, -sz, 0];
358 363
359 var rotMat = Matrix.RotationZ( zRot ); 364 var rotMat = Matrix.RotationZ( zRot );
360 //var scaleMat = Matrix.Scale( [sz,sz,sz] );
361 var transMat = Matrix.Translation( [x,y,z] ); 365 var transMat = Matrix.Translation( [x,y,z] );
362
363 var mat = glmat4.multiply( transMat, rotMat, [] ); 366 var mat = glmat4.multiply( transMat, rotMat, [] );
364 367
365 glmat4.multiplyVec3( mat, verts[0] ); 368 glmat4.multiplyVec3( mat, verts[0] );