aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/cloud-material.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-19 10:25:16 -0700
committerJose Antonio Marquez2012-06-19 10:25:16 -0700
commit4d2a5acd1631f0cf4e38f127c886f481668ddce0 (patch)
tree3bc8f2b21826c0ee6d37bc77753d45a882783cbf /js/lib/rdge/materials/cloud-material.js
parent616b31a644ee221edcbc19f821b2194e8edf9fad (diff)
parent483ad57efcd6475776f580c3af5b60e6deeaf781 (diff)
downloadninja-4d2a5acd1631f0cf4e38f127c886f481668ddce0.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/lib/rdge/materials/cloud-material.js')
-rw-r--r--js/lib/rdge/materials/cloud-material.js439
1 files changed, 357 insertions, 82 deletions
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
index bde42ac3..fc833565 100644
--- a/js/lib/rdge/materials/cloud-material.js
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -4,25 +4,55 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
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;
10var Texture = require("js/lib/rdge/texture").Texture;
11var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
12var TagTool = require("js/tools/TagTool").TagTool;
13
9/////////////////////////////////////////////////////////////////////// 14///////////////////////////////////////////////////////////////////////
10// Class GLMaterial 15// Class GLMaterial
11// RDGE representation of a material. 16// RDGE representation of a material.
12/////////////////////////////////////////////////////////////////////// 17///////////////////////////////////////////////////////////////////////
13var CloudMaterial = function CloudMaterial() { 18var CloudMaterial = function CloudMaterial()
19{
14 /////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////
15 // Instance variables 21 // Instance variables
16 /////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////
17 this._name = "CloudMaterial"; 23 this._name = "Cloud";
18 this._shaderName = "cloud"; 24 this._shaderName = "cloud";
19 25
26 this._texMap = 'assets/images/cloud10.png';
20 this._texMap = 'assets/images/cloud2.jpg'; 27 this._texMap = 'assets/images/cloud2.jpg';
28 //this._texMap = 'assets/images/CL13.png';
29 //this._texMap = 'assets/images/material_paint.png';
30 //this._texMap = 'assets/images/us_flag.png';
31 //this._texMap = 'assets/images/cubelight.png';
21 this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 32 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
22 33
34 // base size of cloud polygons. Random adjustments made to each quad
35 this._cloudSize = 40;
36
23 this._time = 0.0; 37 this._time = 0.0;
24 this._dTime = 0.01; 38 this._dTime = 0.01;
25 39
40 // parameter initial values
41 this._time = 0.0;
42 this._surfaceAlpha = 0.5;
43// this._zmin = 2.0;
44// this._zmax = 5.0;
45 this._zmin = 5.0;
46 this._zmax = 10.0;
47
48 // the adjusted zMin and zMax values are
49 // what get sent to the shader. They are initialized
50 // in buildGeometry
51 this._adjustedZMin = this._zmin;
52 this._adjustedZMax = this._zmax;
53
54
55
26 /////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////
27 // Property Accessors 57 // Property Accessors
28 /////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////
@@ -34,7 +64,6 @@ var CloudMaterial = function CloudMaterial() {
34 64
35 this.setDiffuseColor = function (c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); }; 65 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; }; 66 this.getDiffuseColor = function () { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; };
37
38 this.isAnimated = function () { return true; }; 67 this.isAnimated = function () { return true; };
39 68
40 /////////////////////////////////////////////////////////////////////// 69 ///////////////////////////////////////////////////////////////////////
@@ -65,7 +94,6 @@ var CloudMaterial = function CloudMaterial() {
65 case "diffusecolor": 94 case "diffusecolor":
66 this.setDiffuseColor(value); 95 this.setDiffuseColor(value);
67 break; 96 break;
68
69 case "color": 97 case "color":
70 break; 98 break;
71 } 99 }
@@ -77,97 +105,300 @@ var CloudMaterial = function CloudMaterial() {
77 // Methods 105 // Methods
78 /////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////
79 // duplicate method required 107 // duplicate method required
80 this.dup = function (world) { 108 /**************************************************************/
81 // save the world
82 if (world) this.setWorld(world);
83
84 // allocate a new uber material
85 var newMat = new CloudMaterial();
86
87 // copy over the current values;
88 var propNames = [], propValues = [], propTypes = [], propLabels = [];
89 this.getAllProperties(propNames, propValues, propTypes, propLabels);
90 var n = propNames.length;
91 for (var i = 0; i < n; i++) {
92 newMat.setProperty(propNames[i], propValues[i]);
93 }
94
95 return newMat;
96 };
97 109
98 this.init = function (world) { 110 this.init = function (world) {
99 // save the world 111 var GLWorld = require("js/lib/drawing/world").World,
100 if (world) this.setWorld(world); 112 NJUtils = require("js/lib/NJUtils").NJUtils;
101 113
102 // this variable declared above is inherited set to a smaller delta. 114 // save the world
103 // the cloud material runs a little faster 115 if (world) this.setWorld( world );
104 this._dTime = 0.01; 116 var dstWorld = world;
105 117
106 // set up the shader 118 // create a canvas to render into
107 this._shader = new RDGE.jshader(); 119 var dstCanvas = this.getWorld().getCanvas();
108 this._shader.def = cloudMaterialDef; 120 var doc = this.getWorld().getCanvas().ownerDocument;
109 this._shader.init(); 121 var canvasID = "__canvas__";
110 122 //this._srcCanvas = doc.createElement(canvasID);
111 // set up the material node 123 this._srcCanvas = NJUtils.makeNJElement("canvas", canvasID, "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
112 this._materialNode = RDGE.createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID()); 124 srcCanvas = this._srcCanvas;
113 this._materialNode.setShader(this._shader); 125 srcCanvas.width = dstCanvas.width;
114 126 srcCanvas.height = dstCanvas.height;
115 this._time = 0; 127
116 if (this._shader && this._shader['default']) { 128 //////////////////////////////////////////////////////////////////////////////////
117 this._shader['default'].u_time.set([this._time]); 129 // IS THIS NECESSARY??
118 this._shader['default'].u_DiffuseColor.set(this._diffuseColor); 130// var elementModel = TagTool.makeElement(~~srcCanvas.width, ~~srcCanvas.height,
119 } 131// Matrix.I(4), [0,0,0], srcCanvas);
120 132// ElementMediator.addElement(srcCanvas, elementModel.data, true);
121 // set the shader values in the shader 133 //////////////////////////////////////////////////////////////////////////////////
122 this.updateTexture(); 134
123 this.update(0); 135 // build the source.
124 }; 136 // the source being the world/canvas/geometry of the clouds.
125 137 // the source is used to create a texture map that is then used by
126 this.updateColor = function () { 138 // the destimation.
127 var material = this._materialNode; 139 this.buildSource();
128 if (material) { 140
129 var technique = material.shaderProgram['default']; 141 // set up the shader
130 var renderer = RDGE.globals.engine.getContext().renderer; 142 this._shader = new RDGE.jshader();
131 if (renderer && technique) { 143 this._shader.def = cloudMapMaterialDef;
132 var color = this._propValues[this._propNames[1]]; 144 this._shader.init();
133 technique.u_DiffuseColor.set(this._diffuseColor); 145
134 } 146 // set up the material node
135 } 147 this._materialNode = RDGE.createMaterialNode("cloudMapMaterial" + "_" + world.generateUniqueNodeID());
148 this._materialNode.setShader(this._shader);
149
150 // initialize the time
151 this._time = 0;
152
153 // create the texture to map the source cloud generation world/canvas to the destination
154 var wrap = 'REPEAT', mips = true;
155 this._glTex = new Texture( world, this._srcCanvas, wrap, mips );
156
157 // set the shader values in the shader
158 this.updateTexture();
159 this.update( 0 );
136 }; 160 };
161 /**************************************************************/
137 162
138 this.updateTexture = function () { 163 this.updateTexture = function ()
164 {
139 var material = this._materialNode; 165 var material = this._materialNode;
140 if (material) { 166 if (material)
167 {
141 var technique = material.shaderProgram['default']; 168 var technique = material.shaderProgram['default'];
142 var renderer = RDGE.globals.engine.getContext().renderer; 169 var saveContext = RDGE.globals.engine.getContext();
143 if (renderer && technique) { 170 var renderer = RDGE.globals.engine.getContext().renderer;
171 if (renderer && technique)
172 {
144 var texMapName = this._propValues[this._propNames[0]]; 173 var texMapName = this._propValues[this._propNames[0]];
145 var wrap = 'REPEAT', mips = true; 174 var wrap = 'REPEAT', mips = true;
146 var tex = this.loadTexture(texMapName, wrap, mips); 175 if (this._glTex)
176 {
177 this._glTex.render();
147 178
148