aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhwc4872012-04-15 05:16:34 -0700
committerhwc4872012-04-15 05:16:34 -0700
commit8992d9baf542135e910bb59328a592d9e330703a (patch)
tree268465b69fd37ec1dc33d304de959e79dc619ecd
parent331b2ad4d602016f9bb3d03be759fd81fed50c10 (diff)
downloadninja-8992d9baf542135e910bb59328a592d9e330703a.tar.gz
Cloud Material
-rwxr-xr-xassets/shaders/Basic.vert.glsl3
-rw-r--r--assets/shaders/BasicTex.frag.glsl19
-rw-r--r--assets/shaders/Cloud.frag.glsl4
-rwxr-xr-xjs/lib/drawing/world.js13
-rwxr-xr-xjs/lib/geom/rectangle.js7
-rwxr-xr-xjs/lib/math/matrix.js9
-rw-r--r--js/lib/rdge/materials/cloud-material.js270
-rw-r--r--js/lib/rdge/texture.js2
8 files changed, 236 insertions, 91 deletions
diff --git a/assets/shaders/Basic.vert.glsl b/assets/shaders/Basic.vert.glsl
index 0d5b8d63..f96f8322 100755
--- a/assets/shaders/Basic.vert.glsl
+++ b/assets/shaders/Basic.vert.glsl
@@ -14,6 +14,8 @@ precision highp float;
14attribute vec3 a_pos; 14attribute vec3 a_pos;
15attribute vec2 texcoord; 15attribute vec2 texcoord;
16 16
17// varying
18varying vec2 v_texCoord0;
17 19
18// matrix uniforms 20// matrix uniforms
19uniform mat4 u_mvMatrix; 21uniform mat4 u_mvMatrix;
@@ -22,5 +24,6 @@ uniform mat4 u_worldMatrix;
22 24
23void main(void) 25void main(void)
24{ 26{
27 v_texCoord0 = texcoord;
25 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ; 28 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ;
26} \ No newline at end of file 29} \ No newline at end of file
diff --git a/assets/shaders/BasicTex.frag.glsl b/assets/shaders/BasicTex.frag.glsl
new file mode 100644
index 00000000..a716e77d
--- /dev/null
+++ b/assets/shaders/BasicTex.frag.glsl
@@ -0,0 +1,19 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7
8#ifdef GL_ES
9precision highp float;
10#endif
11
12uniform sampler2D u_tex0;
13
14varying vec2 v_texCoord0;
15
16
17void main() {
18 gl_FragColor = texture2D(u_tex0, v_texCoord0);
19}
diff --git a/assets/shaders/Cloud.frag.glsl b/assets/shaders/Cloud.frag.glsl
index b07bb627..ba1ef39e 100644
--- a/assets/shaders/Cloud.frag.glsl
+++ b/assets/shaders/Cloud.frag.glsl
@@ -17,7 +17,7 @@ varying vec2 v_texCoord0;
17 17
18void main() 18void main()
19{ 19{
20 // gl_FragColor = texture2D(u_tex0, v_texCoord0) * u_surfaceAlpha; 20 gl_FragColor = texture2D(u_tex0, v_texCoord0) * u_surfaceAlpha;
21 gl_FragColor = vec4(1,0,0,1); 21 //gl_FragColor = texture2D(u_tex0, v_texCoord0);
22} 22}
23 \ No newline at end of file 23 \ No newline at end of file
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 5eca26b8..4ca738f4 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -73,6 +73,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
73 this._firstRender = true; 73 this._firstRender = true;
74 74
75 this._worldCount = worldCounter; 75 this._worldCount = worldCounter;
76 console.log( "creating world " + this._worldCount );
76 worldCounter++; 77 worldCounter++;
77 78
78 // keep a counter for generating node names 79 // keep a counter for generating node names
@@ -514,6 +515,18 @@ World.prototype.restartRenderLoop = function() {
514 } 515 }
515}; 516};
516 517
518World.prototype.stop = function()
519{
520 if (this._canvas && this._canvas.task)
521 this._canvas.task.stop();
522}
523
524World.prototype.start = function()
525{
526 if (this._canvas && this._canvas.task)
527 this._canvas.task.start();
528}
529
517//append to the list of objects if obj doesn't already exist 530//append to the list of objects if obj doesn't already exist
518//if obj exists, then don't add to list of objects 531//if obj exists, then don't add to list of objects
519World.prototype.addIfNewObject = function (obj) { 532World.prototype.addIfNewObject = function (obj) {
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index d4dd8033..70f6b01b 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -1294,6 +1294,7 @@ RectangleGeometry.init = function()
1294 1294
1295RectangleGeometry.addQuad = function( verts, normals, uvs ) 1295RectangleGeometry.addQuad = function( verts, normals, uvs )
1296{ 1296{
1297 var offset = this.vertices.length/3;
1297 for (var i=0; i<4; i++) 1298 for (var i=0; i<4; i++)
1298 { 1299 {
1299 RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); 1300 RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]);
@@ -1301,13 +1302,13 @@ RectangleGeometry.addQuad = function( verts, normals, uvs )
1301 RectangleGeometry.pushUV( uvs[i] ); 1302 RectangleGeometry.pushUV( uvs[i] );
1302 } 1303 }
1303 1304
1304 RectangleGeometry.pushIndices( 0, 1, 2 ); 1305 RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset );
1305 RectangleGeometry.pushIndices( 2, 3, 0 ); 1306 RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset );
1306} 1307}
1307 1308
1308RectangleGeometry.buildPrimitive = function() 1309RectangleGeometry.buildPrimitive = function()
1309{ 1310{
1310 var nVertices = this.vertices.length; 1311 var nVertices = this.vertices.length/3;
1311 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1312 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1312} 1313}
1313 1314
diff --git a/js/lib/math/matrix.js b/js/lib/math/matrix.js
index 77a0966d..3a5a8215 100755
--- a/js/lib/math/matrix.js
+++ b/js/lib/math/matrix.js
@@ -67,6 +67,15 @@ Matrix.Rotation = function(angle, axis) {
67 return mat; 67 return mat;
68}; 68};
69 69
70Matrix.Scale = function( scaleVec ) {
71 var mat = Matrix.I(4);
72 mat[ 0] = scaleVec[0];
73 mat[ 5] = scaleVec[1];
74 mat[10] = scaleVec[2];
75
76 return mat;
77};
78
70Matrix.flatten = function (mat) { 79Matrix.flatten = function (mat) {
71 var result = []; 80 var result = [];
72 if (this.elements.length == 0) { 81 if (this.elements.length == 0) {
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
index 126751c6..e2292c7a 100644
--- a/js/lib/rdge/materials/cloud-material.js
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -8,6 +8,8 @@ var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialP
8var Material = require("js/lib/rdge/materials/material").Material; 8var Material = require("js/lib/rdge/materials/material").Material;
9var GLWorld = require("js/lib/drawing/world").World; 9var GLWorld = require("js/lib/drawing/world").World;
10var Texture = require("js/lib/rdge/texture").Texture; 10var Texture = require("js/lib/rdge/texture").Texture;
11var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
12var TagTool = require("js/tools/TagTool").TagTool;
11 13
12/////////////////////////////////////////////////////////////////////// 14///////////////////////////////////////////////////////////////////////
13// Class GLMaterial 15// Class GLMaterial
@@ -20,7 +22,9 @@ var CloudMaterial = function CloudMaterial() {
20 this._name = "CloudMaterial"; 22 this._name = "CloudMaterial";
21 this._shaderName = "cloud"; 23 this._shaderName = "cloud";
22 24
23 this._texMap = 'assets/images/cloud10.png'; 25 //this._texMap = 'assets/images/cloud10.png';
26 this._texMap = 'assets/images/us_flag.png';
27 //this._texMap = 'assets/images/cubelight.png';
24 this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 28 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
25 29
26 // base size of cloud polygons. Random adjustments made to each quad 30 // base size of cloud polygons. Random adjustments made to each quad
@@ -31,7 +35,7 @@ var CloudMaterial = function CloudMaterial() {
31 35
32 // parameter initial values 36 // parameter initial values
33 this._time = 0.0; 37 this._time = 0.0;
34 this._surfaceAlpha = 1.0; 38 this._surfaceAlpha = 0.6;
35 this._zmin = 0.1; 39 this._zmin = 0.1;
36 this._zmax = 10.0; 40 this._zmax = 10.0;
37 41
@@ -111,80 +115,54 @@ var CloudMaterial = function CloudMaterial() {
111 115
112 // save the world 116 // save the world
113 if (world) this.setWorld( world ); 117 if (world) this.setWorld( world );
114 118 var dstWorld = world;
115 // this variable declared above is inherited set to a smaller delta.
116 // the cloud material runs a little faster
117 this._dTime = 0.01;
118 119
119 // create a canvas to render into 120 // create a canvas to render into
120 var doc = world.getCanvas().ownerDocument; 121 var dstCanvas = this.getWorld().getCanvas();
122 var doc = this.getWorld().getCanvas().ownerDocument;
121 var canvasID = "__canvas__"; 123 var canvasID = "__canvas__";
122 //this._srcCanvas = doc.createElement(canvasID); 124 //this._srcCanvas = doc.createElement(canvasID);
123 this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); 125 this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
124 var dstCanvas = this.getWorld().getCanvas(), 126 srcCanvas = this._srcCanvas;
125 srcCanvas = this._srcCanvas;
126 srcCanvas.width = dstCanvas.width; 127 srcCanvas.width = dstCanvas.width;
127 srcCanvas.height = dstCanvas.height; 128 srcCanvas.height = dstCanvas.height;
128 129
129 // save the current RDGE context 130 //////////////////////////////////////////////////////////////////////////////////
130 var saveContext = g_Engine.getContext(); 131 // IS THIS NECESSARY??
131 132 //var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height,
132 // build a world to do the rendering 133 // Matrix.I(4), [0,0,0], srcCanvas);
133 this._srcWorld = new GLWorld( this._srcCanvas, true, true ); 134 //ElementMediator.addElement(srcCanvas, elementModel.data, true);
134 var srcWorld = this._srcWorld; 135 //////////////////////////////////////////////////////////////////////////////////
135 this._srcCanvas.__GLWorld = srcWorld;
136 136
137 // build the geometry 137 // build the source.
138 var prim = this.buildGeometry( srcWorld, srcCanvas.width, srcCanvas.height );