diff options
-rwxr-xr-x | assets/shaders/Basic.vert.glsl | 3 | ||||
-rw-r--r-- | assets/shaders/BasicTex.frag.glsl | 19 | ||||
-rw-r--r-- | assets/shaders/Cloud.frag.glsl | 4 | ||||
-rwxr-xr-x | js/lib/drawing/world.js | 13 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 7 | ||||
-rwxr-xr-x | js/lib/math/matrix.js | 9 | ||||
-rw-r--r-- | js/lib/rdge/materials/cloud-material.js | 270 | ||||
-rw-r--r-- | js/lib/rdge/texture.js | 2 |
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; | |||
14 | attribute vec3 a_pos; | 14 | attribute vec3 a_pos; |
15 | attribute vec2 texcoord; | 15 | attribute vec2 texcoord; |
16 | 16 | ||
17 | // varying | ||
18 | varying vec2 v_texCoord0; | ||
17 | 19 | ||
18 | // matrix uniforms | 20 | // matrix uniforms |
19 | uniform mat4 u_mvMatrix; | 21 | uniform mat4 u_mvMatrix; |
@@ -22,5 +24,6 @@ uniform mat4 u_worldMatrix; | |||
22 | 24 | ||
23 | void main(void) | 25 | void 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> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | ||
9 | precision highp float; | ||
10 | #endif | ||
11 | |||
12 | uniform sampler2D u_tex0; | ||
13 | |||
14 | varying vec2 v_texCoord0; | ||
15 | |||
16 | |||
17 | void 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 | ||
18 | void main() | 18 | void 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 | ||
518 | World.prototype.stop = function() | ||
519 | { | ||
520 | if (this._canvas && this._canvas.task) | ||
521 | this._canvas.task.stop(); | ||
522 | } | ||
523 | |||
524 | World.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 |
519 | World.prototype.addIfNewObject = function (obj) { | 532 | World.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 | ||
1295 | RectangleGeometry.addQuad = function( verts, normals, uvs ) | 1295 | RectangleGeometry.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 | ||
1308 | RectangleGeometry.buildPrimitive = function() | 1309 | RectangleGeometry.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 | ||
70 | Matrix.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 | |||
70 | Matrix.flatten = function (mat) { | 79 | Matrix.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 | |||
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var GLWorld = require("js/lib/drawing/world").World; | 9 | var GLWorld = require("js/lib/drawing/world").World; |
10 | var Texture = require("js/lib/rdge/texture").Texture; | 10 | var Texture = require("js/lib/rdge/texture").Texture; |
11 | var ElementMediator = require("js/mediators/element-mediator").ElementMediator; | ||
12 | var 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 ); |