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.js704
1 files changed, 352 insertions, 352 deletions
<
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
index 4e2a1a7c..873059bc 100644
--- a/js/lib/rdge/materials/cloud-material.js
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -28,12 +28,12 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE. 28POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 29</copyright> */
30 30
31var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 31var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
32var Material = require("js/lib/rdge/materials/material").Material; 32var Material = require("js/lib/rdge/materials/material").Material;
33var GLWorld = require("js/lib/drawing/world").World; 33var GLWorld = require("js/lib/drawing/world").World;
34var Texture = require("js/lib/rdge/texture").Texture; 34var Texture = require("js/lib/rdge/texture").Texture;
35var ElementMediator = require("js/mediators/element-mediator").ElementMediator; 35var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
36var TagTool = require("js/tools/TagTool").TagTool; 36var TagTool = require("js/tools/TagTool").TagTool;
37 37
38/////////////////////////////////////////////////////////////////////// 38///////////////////////////////////////////////////////////////////////
39// Class GLMaterial 39// Class GLMaterial
@@ -47,33 +47,33 @@ var CloudMaterial = function CloudMaterial()
47 this._name = "Cloud"; 47 this._name = "Cloud";
48 this._shaderName = "cloud"; 48 this._shaderName = "cloud";
49 49
50 this._texMap = 'assets/images/cloud10.png'; 50 this._texMap = 'assets/images/cloud10.png';
51 this._texMap = 'assets/images/cloud2.jpg'; 51 this._texMap = 'assets/images/cloud2.jpg';
52 //this._texMap = 'assets/images/CL13.png'; 52 //this._texMap = 'assets/images/CL13.png';
53 //this._texMap = 'assets/images/material_paint.png'; 53 //this._texMap = 'assets/images/material_paint.png';
54 //this._texMap = 'assets/images/us_flag.png'; 54 //this._texMap = 'assets/images/us_flag.png';
55 //this._texMap = 'assets/images/cubelight.png'; 55 //this._texMap = 'assets/images/cubelight.png';
56 this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 56 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
57 57
58 // base size of cloud polygons. Random adjustments made to each quad 58 // base size of cloud polygons. Random adjustments made to each quad
59 this._cloudSize = 40; 59 this._cloudSize = 40;
60 60
61 this._time = 0.0; 61 this._time = 0.0;
62 this._dTime = 0.01; 62 this._dTime = 0.01;
63 63
64 // parameter initial values 64 // parameter initial values
65 this._time = 0.0; 65 this._time = 0.0;
66 this._surfaceAlpha = 0.5; 66 this._surfaceAlpha = 0.5;
67// this._zmin = 2.0; 67// this._zmin = 2.0;
68// this._zmax = 5.0; 68// this._zmax = 5.0;
69 this._zmin = 5.0; 69 this._zmin = 5.0;
70 this._zmax = 10.0; 70 this._zmax = 10.0;
71 71
72 // the adjusted zMin and zMax values are 72 // the adjusted zMin and zMax values are
73 // what get sent to the shader. They are initialized 73 // what get sent to the shader. They are initialized
74 // in buildGeometry 74 // in buildGeometry
75 this._adjustedZMin = this._zmin; 75 this._adjustedZMin = this._zmin;
76 this._adjustedZMax = this._zmax; 76 this._adjustedZMax = this._zmax;
77 77
78 78
79 79
@@ -132,68 +132,68 @@ var CloudMaterial = function CloudMaterial()
132 /**************************************************************/ 132 /**************************************************************/
133 133
134 this.init = function (world) { 134 this.init = function (world) {
135 var GLWorld = require("js/lib/drawing/world").World, 135 var GLWorld = require("js/lib/drawing/world").World,
136 NJUtils = require("js/lib/NJUtils").NJUtils; 136 NJUtils = require("js/lib/NJUtils").NJUtils;
137 137
138 // save the world 138 // save the world
139 if (world) this.setWorld( world ); 139 if (world) this.setWorld( world );
140 var dstWorld = world; 140 var dstWorld = world;
141 141
142 // create a canvas to render into 142 // create a canvas to render into
143 var dstCanvas = this.getWorld().getCanvas(); 143 var dstCanvas = this.getWorld().getCanvas();
144 var doc = this.getWorld().getCanvas().ownerDocument; 144 var doc = this.getWorld().getCanvas().ownerDocument;
145 var canvasID = "__canvas__"; 145 var canvasID = "__canvas__";
146 //this._srcCanvas = doc.createElement(canvasID); 146 //this._srcCanvas = doc.createElement(canvasID);
147 this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); 147 this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
148 srcCanvas = this._srcCanvas; 148 srcCanvas = this._srcCanvas;
149 srcCanvas.width = dstCanvas.width; 149 srcCanvas.width = dstCanvas.width;
150 srcCanvas.height = dstCanvas.height; 150 srcCanvas.height = dstCanvas.height;
151 151
152 ////////////////////////////////////////////////////////////////////////////////// 152 //////////////////////////////////////////////////////////////////////////////////
153 // IS THIS NECESSARY?? 153 // IS THIS NECESSARY??
154// var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height, 154// var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height,
155// Matrix.I(4), [0,0,0], srcCanvas); 155// Matrix.I(4), [0,0,0], srcCanvas);
156// ElementMediator.addElement(srcCanvas, elementModel.data, true); 156// ElementMediator.addElement(srcCanvas, elementModel.data, true);
157 ////////////////////////////////////////////////////////////////////////////////// 157 //////////////////////////////////////////////////////////////////////////////////
158 158
159 // build the source. 159 // build the source.
160 // the source being the world/canvas/geometry of the clouds. 160 // 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 161 // the source is used to create a texture map that is then used by
162 // the destimation. 162 // the destimation.
163 this.buildSource(); 163 this.buildSource();
164 164
165 // set up the shader 165 // set up the shader
166 this._shader = new RDGE.jshader(); 166 this._shader = new RDGE.jshader();
167 this._shader.def = cloudMapMaterialDef; 167 this._shader.def = cloudMapMaterialDef;
168 this._shader.init(); 168 this._shader.init();
169 169
170 // set up the material node 170 // set up the material node
171 this._materialNode = RDGE.createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID()); 171 this._materialNode = RDGE.createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID());
172 this._materialNode.setShader(this._shader); 172 this._materialNode.setShader(this._shader);
173 173
174 // initialize the time 174 // initialize the time
175 this._time = 0; 175 this._time = 0;
176 176
177 // create the texture to map the source cloud generation world/canvas to the destination 177 // create the texture to map the source cloud generation world/canvas to the destination
178 var wrap = 'REPEAT', mips = true; 178 var wrap = 'REPEAT', mips = true;
179 this._glTex = new Texture( world, this._srcCanvas, wrap, mips ); 179 this._glTex = new Texture( world, this._srcCanvas, wrap, mips );
180 180
181 // set the shader values in the shader 181 // set the shader values in the shader
182 this.updateTexture(); 182 this.updateTexture();
183 this.update( 0 ); 183 this.update( 0 );
184 }; 184 };
185 /**************************************************************/ 185 /**************************************************************/
186 186
187 this.updateTexture = function () 187 this.updateTexture = function ()
188 { 188 {
189 var material = this._materialNode; 189 var material = this._materialNode;
190 if (material) 190 if (material)
191 { 191 {
192 var technique = material.shaderProgram['default']; 192 var technique = material.shaderProgram['default'];
193 var saveContext = RDGE.globals.engine.getContext(); 193 var saveContext = RDGE.globals.engine.getContext();
194 var renderer = RDGE.globals.engine.getContext().renderer; 194 var renderer = RDGE.globals.engine.getContext().renderer;
195 if (renderer && technique) 195 if (renderer && technique)
196 { 196 {
197 var texMapName = this._propValues[this._propNames[0]]; 197 var texMapName = this._propValues[this._propNames[0]];
198 var wrap = 'REPEAT', mips = true; 198 var wrap = 'REPEAT', mips = true;
199 if (this._glTex) 199 if (this._glTex)
@@ -201,236 +201,236 @@ var CloudMaterial = function CloudMaterial()
201 this._glTex.render(); 201 this._glTex.render();
202 202
203 var tex = this._glTex.getTexture(); 203 var tex = this._glTex.getTexture();
204 if (tex) 204 if (tex)
205 technique.u_tex0.set( tex ); 205 technique.u_tex0.set( tex );
206 }
207 }
208
209 // restore the context
210 RDGE.globals.engine.setContext( saveContext.id );
211 }
212 };
213
214 this.updateColor = function()
215 {
216 }
217
218 this.update = function( time )
219 {
220 if (this._srcWorld)
221 {
222 //this._srcWorld.update();
223 this._srcWorld.draw();
224 RDGE.globals.engine.setContext( this.getWorld()._canvas.rdgeid );
225 }
226
227 var technique, renderer, tex;
228
229 // update the cloud map material
230 var material = this._materialNode;
231 if (material)
232 {
233 technique = material.shaderProgram['default'];
234 renderer = RDGE.globals.engine.getContext().renderer;
235