diff options
-rw-r--r-- | assets/shaders/Cloud.frag.glsl | 23 | ||||
-rw-r--r-- | assets/shaders/Cloud.vert.glsl | 42 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 30 | ||||
-rw-r--r-- | js/lib/rdge/materials/cloud-material.js | 122 | ||||
-rwxr-xr-x | js/models/materials-model.js | 3 |
5 files changed, 179 insertions, 41 deletions
diff --git a/assets/shaders/Cloud.frag.glsl b/assets/shaders/Cloud.frag.glsl new file mode 100644 index 00000000..522e17bb --- /dev/null +++ b/assets/shaders/Cloud.frag.glsl | |||
@@ -0,0 +1,23 @@ | |||
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 | uniform float u_surfaceAlpha; | ||
14 | |||
15 | varying vec4 v_Colors; | ||
16 | varying vec2 v_texCoord0; | ||
17 | |||
18 | |||
19 | void main() | ||
20 | { | ||
21 | gl_FragColor = texture2D(u_tex0, v_texCoord0) * u_surfaceAlpha; | ||
22 | } | ||
23 | \ No newline at end of file | ||
diff --git a/assets/shaders/Cloud.vert.glsl b/assets/shaders/Cloud.vert.glsl new file mode 100644 index 00000000..fbd7f40b --- /dev/null +++ b/assets/shaders/Cloud.vert.glsl | |||
@@ -0,0 +1,42 @@ | |||
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 | // attributes | ||
13 | attribute vec3 a_pos; | ||
14 | attribute vec2 texcoord; | ||
15 | |||
16 | // uniforms | ||
17 | uniform float u_time; | ||
18 | uniform float u_zmin; | ||
19 | uniform float u_zmax; | ||
20 | uniform float u_surfaceAlpha; | ||
21 | |||
22 | // matrix uniforms | ||
23 | uniform mat4 u_mvMatrix; | ||
24 | uniform mat4 u_projMatrix; | ||
25 | uniform mat4 u_worldMatrix; | ||
26 | |||
27 | // varying | ||
28 | varying vec2 v_texCoord0; | ||
29 | |||
30 | // constants | ||
31 | const float zSpeed = 1.0; | ||
32 | |||
33 | |||
34 | void main() | ||
35 | { | ||
36 | // Transform position | ||
37 | vec4 pos = a_pos; | ||
38 | pos.z += u+time*zSpeed; | ||
39 | gl_Position = u_projMatrix * u_mvMatrix * pos; | ||
40 | |||
41 | v_texCoord0 = texcoord; | ||
42 | } \ No newline at end of file | ||
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 51947ff1..f41c27f6 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -1280,11 +1280,41 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices; | |||
1280 | RectangleGeometry.getVertex = RectangleFill.getVertex; | 1280 | RectangleGeometry.getVertex = RectangleFill.getVertex; |
1281 | RectangleGeometry.getUV = RectangleFill.getUV; | 1281 | RectangleGeometry.getUV = RectangleFill.getUV; |
1282 | 1282 | ||
1283 | RectangleGeometry.init = function() | ||
1284 | { | ||
1285 | this.vertices = []; | ||
1286 | this.normals = []; | ||
1287 | this.uvs = []; | ||
1288 | this.indices = []; | ||
1289 | } | ||
1290 | |||
1291 | RectangleGeometry.addQuad = function( verts, normals, uvs ) | ||
1292 | { | ||
1293 | for (var i=0; i<4; i++) | ||
1294 | { | ||
1295 | RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); | ||
1296 | RectangleGeometry.pushNormal( normals[i] ); | ||
1297 | RectangleGeometry.pushUV( uvs[i] ); | ||
1298 | } | ||
1299 | |||
1300 | RectangleGeometry.pushIndices( 0, 1, 2 ); | ||
1301 | RectangleGeometry.pushIndices( 2, 3, 0 ); | ||
1302 | } | ||
1303 | |||
1304 | RectangleGeometry.buildPrimitive = function() | ||
1305 | { | ||
1306 | var nVertices = this.vertices.length; | ||
1307 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | ||
1308 | } | ||
1309 | |||
1310 | |||
1311 | |||
1283 | 1312 | ||
1284 | Rectangle.prototype = new GeomObj(); | 1313 | Rectangle.prototype = new GeomObj(); |
1285 | 1314 | ||
1286 | if (typeof exports === "object") { | 1315 | if (typeof exports === "object") { |
1287 | exports.Rectangle = Rectangle; | 1316 | exports.Rectangle = Rectangle; |
1317 | exports.RectangleGeometry = RectangleGeometry; | ||
1288 | } | 1318 | } |
1289 | 1319 | ||
1290 | 1320 | ||
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js index f7f4c6bb..198f7cfa 100644 --- a/js/lib/rdge/materials/cloud-material.js +++ b/js/lib/rdge/materials/cloud-material.js | |||
@@ -4,8 +4,11 @@ | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
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; | ||
10 | var Texture = require("js/lib/rdge/texture").Texture; | ||
11 | |||
9 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
10 | // Class GLMaterial | 13 | // Class GLMaterial |
11 | // RDGE representation of a material. | 14 | // RDGE representation of a material. |
@@ -20,9 +23,19 @@ var CloudMaterial = function CloudMaterial() { | |||
20 | this._texMap = 'assets/images/cloud2.jpg'; | 23 | this._texMap = 'assets/images/cloud2.jpg'; |
21 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; | 24 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; |
22 | 25 | ||
26 | // base size of cloud polygons. Random adjustments made to each quad | ||
27 | this._cloudSize = 40; | ||
28 | |||
23 | this._time = 0.0; | 29 | this._time = 0.0; |
24 | this._dTime = 0.01; | 30 | this._dTime = 0.01; |
25 | 31 | ||
32 | // parameter initial values | ||
33 | this._time = 0.0; | ||
34 | this._surfaceAlpha = 0.5; | ||
35 | this._zmin = 0.1; | ||
36 | this._zmax = 10.0; | ||
37 | |||
38 | |||
26 | /////////////////////////////////////////////////////////////////////// | 39 | /////////////////////////////////////////////////////////////////////// |
27 | // Property Accessors | 40 | // Property Accessors |
28 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
@@ -32,9 +45,6 @@ var CloudMaterial = function CloudMaterial() { | |||
32 | this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; | 45 | this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; |
33 | this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }; | 46 | this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }; |
34 | 47 | ||
35 | this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); }; | ||
36 | this.getDiffuseColor = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; }; | ||
37 | |||
38 | this.isAnimated = function() { return true; }; | 48 | this.isAnimated = function() { return true; }; |
39 | 49 | ||
40 | /////////////////////////////////////////////////////////////////////// | 50 | /////////////////////////////////////////////////////////////////////// |
@@ -64,10 +74,6 @@ var CloudMaterial = function CloudMaterial() { | |||
64 | this.setTextureMap(value); | 74 | this.setTextureMap(value); |
65 | break; | 75 | break; |
66 | 76 | ||
67 | case "diffusecolor": | ||
68 | this.setDiffuseColor( value ); | ||
69 | break; | ||
70 | |||
71 | case "color": | 77 | case "color": |
72 | break; | 78 | break; |
73 | } | 79 | } |
@@ -100,6 +106,8 @@ var CloudMaterial = function CloudMaterial() { | |||
100 | 106 | ||
101 | this.init = function( world ) | 107 | this.init = function( world ) |
102 | { | 108 | { |
109 | var GLWorld = require("js/lib/drawing/world").World; | ||
110 | |||
103 | // save the world | 111 | // save the world |
104 | if (world) this.setWorld( world ); | 112 | if (world) this.setWorld( world ); |
105 | 113 | ||
@@ -107,6 +115,18 @@ var CloudMaterial = function CloudMaterial() { | |||
107 | // the cloud material runs a little faster | 115 | // the cloud material runs a little faster |
108 | this._dTime = 0.01; | 116 | this._dTime = 0.01; |
109 | 117 | ||
118 | // create a canvas to render into | ||
119 | var doc = world.getCanvas().ownerDocument; | ||
120 | var canvasID = "__canvas__"; | ||
121 | this._srcCanvas = doc.createElement(canvasID); | ||
122 | |||
123 | // build a world to do the rendering | ||
124 | this._srcWorld = new GLWorld( this._srcCanvas, true ); | ||
125 | var srcWorld = this._srcWorld; | ||
126 | |||
127 | // build the geometry | ||
128 | var prim = this.buildGeometry(); | ||
129 | |||
110 | // set up the shader | 130 | // set up the shader |
111 | this._shader = new jshader(); | 131 | this._shader = new jshader(); |
112 | this._shader.def = cloudMaterialDef; | 132 | this._shader.def = cloudMaterialDef; |
@@ -116,31 +136,34 @@ var CloudMaterial = function CloudMaterial() { | |||
116 | this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID()); | 136 | this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID()); |
117 | this._materialNode.setShader(this._shader); | 137 | this._materialNode.setShader(this._shader); |
118 | 138 | ||
139 | // initialize the shader uniforms | ||
119 | this._time = 0; | 140 | this._time = 0; |
120 | if (this._shader && this._shader['default']) { | 141 | if (this._shader && this._shader['default']) { |
121 | this._shader['default'].u_time.set( [this._time] ); | 142 | var t = this._shader['default']; |
122 | this._shader['default'].u_DiffuseColor.set( this._diffuseColor ); | 143 |