aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/cloud-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/cloud-material.js')
-rw-r--r--js/lib/rdge/materials/cloud-material.js731
1 files changed, 366 insertions, 365 deletions
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
index 4e2a1a7c..748e26dd 100644
--- a/js/lib/rdge/materials/cloud-material.js
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -28,12 +29,12 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE. 29POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 30</copyright> */
30 31
31var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 32var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
32var Material = require("js/lib/rdge/materials/material").Material; 33var Material = require("js/lib/rdge/materials/material").Material;
33var GLWorld = require("js/lib/drawing/world").World; 34var GLWorld = require("js/lib/drawing/world").World;
34var Texture = require("js/lib/rdge/texture").Texture; 35var Texture = require("js/lib/rdge/texture").Texture;
35var ElementMediator = require("js/mediators/element-mediator").ElementMediator; 36var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
36var TagTool = require("js/tools/TagTool").TagTool; 37var TagTool = require("js/tools/TagTool").TagTool;
37 38
38/////////////////////////////////////////////////////////////////////// 39///////////////////////////////////////////////////////////////////////
39// Class GLMaterial 40// Class GLMaterial
@@ -47,33 +48,33 @@ var CloudMaterial = function CloudMaterial()
47 this._name = "Cloud"; 48 this._name = "Cloud";
48 this._shaderName = "cloud"; 49 this._shaderName = "cloud";
49 50
50 this._texMap = 'assets/images/cloud10.png'; 51 this._texMap = 'assets/images/cloud10.png';
51 this._texMap = 'assets/images/cloud2.jpg'; 52 this._texMap = 'assets/images/cloud2.jpg';
52 //this._texMap = 'assets/images/CL13.png'; 53 //this._texMap = 'assets/images/CL13.png';
53 //this._texMap = 'assets/images/material_paint.png'; 54 //this._texMap = 'assets/images/material_paint.png';
54 //this._texMap = 'assets/images/us_flag.png'; 55 //this._texMap = 'assets/images/us_flag.png';
55 //this._texMap = 'assets/images/cubelight.png'; 56 //this._texMap = 'assets/images/cubelight.png';
56 this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 57 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
57 58
58 // base size of cloud polygons. Random adjustments made to each quad 59 // base size of cloud polygons. Random adjustments made to each quad
59 this._cloudSize = 40; 60 this._cloudSize = 40;
60 61
61 this._time = 0.0; 62 this._time = 0.0;
62 this._dTime = 0.01; 63 this._dTime = 0.01;
63 64
64 // parameter initial values 65 // parameter initial values
65 this._time = 0.0; 66 this._time = 0.0;
66 this._surfaceAlpha = 0.5; 67 this._surfaceAlpha = 0.5;
67// this._zmin = 2.0; 68// this._zmin = 2.0;
68// this._zmax = 5.0; 69// this._zmax = 5.0;
69 this._zmin = 5.0; 70 this._zmin = 5.0;
70 this._zmax = 10.0; 71 this._zmax = 10.0;
71 72
72 // the adjusted zMin and zMax values are 73 // the adjusted zMin and zMax values are
73 // what get sent to the shader. They are initialized 74 // what get sent to the shader. They are initialized
74 // in buildGeometry 75 // in buildGeometry
75 this._adjustedZMin = this._zmin; 76 this._adjustedZMin = this._zmin;
76 this._adjustedZMax = this._zmax; 77 this._adjustedZMax = this._zmax;
77 78
78 79
79 80
@@ -132,68 +133,68 @@ var CloudMaterial = function CloudMaterial()
132 /**************************************************************/ 133 /**************************************************************/
133 134
134 this.init = function (world) { 135 this.init = function (world) {
135 var GLWorld = require("js/lib/drawing/world").World, 136 var GLWorld = require("js/lib/drawing/world").World,
136 NJUtils = require("js/lib/NJUtils").NJUtils; 137 NJUtils = require("js/lib/NJUtils").NJUtils;
137 138
138 // save the world 139 // save the world
139 if (world) this.setWorld( world ); 140 if (world) this.setWorld( world );
140 var dstWorld = world; 141 var dstWorld = world;
141 142
142 // create a canvas to render into 143 // create a canvas to render into
143 var dstCanvas = this.getWorld().getCanvas(); 144 var dstCanvas = this.getWorld().getCanvas();
144 var doc = this.getWorld().getCanvas().ownerDocument; 145 var doc = this.getWorld().getCanvas().ownerDocument;
145 var canvasID = "__canvas__"; 146 var canvasID = "__canvas__";
146 //this._srcCanvas = doc.createElement(canvasID); 147 //this._srcCanvas = doc.createElement(canvasID);
147 this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); 148 this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
148 srcCanvas = this._srcCanvas; 149 srcCanvas = this._srcCanvas;
149 srcCanvas.width = dstCanvas.width; 150 srcCanvas.width = dstCanvas.width;
150 srcCanvas.height = dstCanvas.height; 151 srcCanvas.height = dstCanvas.height;
151 152
152 ////////////////////////////////////////////////////////////////////////////////// 153 //////////////////////////////////////////////////////////////////////////////////
153 // IS THIS NECESSARY?? 154 // IS THIS NECESSARY??
154// var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height, 155// var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height,
155// Matrix.I(4), [0,0,0], srcCanvas); 156// Matrix.I(4), [0,0,0], srcCanvas);
156// ElementMediator.addElement(srcCanvas, elementModel.data, true); 157// ElementMediator.addElement(srcCanvas, elementModel.data, true);
157 ////////////////////////////////////////////////////////////////////////////////// 158 //////////////////////////////////////////////////////////////////////////////////
158 159
159 // build the source. 160 // build the source.
160 // the source being the world/canvas/geometry of the clouds. 161 // the source being the world/canvas/geometry of the clouds.
161 // the source is used to create a texture map that is then used by 162 // the source is used to create a texture map that is then used by
162 // the destimation. 163 // the destimation.
163 this.buildSource(); 164 this.buildSource();
164 165
165 // set up the shader 166 // set up the shader
166 this._shader = new RDGE.jshader(); 167 this._shader = new RDGE.jshader();
167 this._shader.def = cloudMapMaterialDef; 168 this._shader.def = cloudMapMaterialDef;
168 this._shader.init(); 169 this._shader.init();
169 170
170 // set up the material node 171 // set up the material node
171 this._materialNode = RDGE.createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID()); 172 this._materialNode = RDGE.createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID());
172 this._materialNode.setShader(this._shader); 173 this._materialNode.setShader(this._shader);
173 174
174 // initialize the time 175 // initialize the time
175 this._time = 0; 176 this._time = 0;
176 177
177 // create the texture to map the source cloud generation world/canvas to the destination 178 // create the texture to map the source cloud generation world/canvas to the destination
178 var wrap = 'REPEAT', mips = true; 179 var wrap = 'REPEAT', mips = true;
179 this._glTex = new Texture( world, this._srcCanvas, wrap, mips ); 180 this._glTex = new Texture( world, this._srcCanvas, wrap, mips );
180 181
181 // set the shader values in the shader 182 // set the shader values in the shader
182 this.updateTexture(); 183 this.updateTexture();
183 this.update( 0 ); 184 this.update( 0 );
184 }; 185 };
185 /**************************************************************/ 186 /**************************************************************/
186 187
187 this.updateTexture = function () 188 this.updateTexture = function ()
188 { 189 {
189 var material = this._materialNode; 190 var material = this._materialNode;
190 if (material) 191 if (material)
191 { 192 {
192 var technique = material.shaderProgram['default']; 193 var technique = material.shaderProgram['default'];
193 var saveContext = RDGE.globals.engine.getContext(); 194 var saveContext = RDGE.globals.engine.getContext();
194 var renderer = RDGE.globals.engine.getContext().renderer; 195 var renderer = RDGE.globals.engine.getContext().renderer;
195 if (r