aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/uber-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/uber-material.js')
-rwxr-xr-xjs/lib/rdge/materials/uber-material.js262
1 files changed, 131 insertions, 131 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js
index 416cb980..8bd44e60 100755
--- a/js/lib/rdge/materials/uber-material.js
+++ b/js/lib/rdge/materials/uber-material.js
@@ -45,11 +45,11 @@ var UberMaterial = function UberMaterial() {
45 this._diffuseColor = [1.0, 1.0, 1.0, 1.0]; 45 this._diffuseColor = [1.0, 1.0, 1.0, 1.0];
46 this._specularColor = [1.0, 1.0, 1.0, 1.0]; 46 this._specularColor = [1.0, 1.0, 1.0, 1.0];
47 this._specularPower = 32.0; 47 this._specularPower = 32.0;
48 this._environmentAmount = 0.2; // 0 .. 1 48 this._environmentAmount = 0.2; // 0 .. 1
49 49
50 // set the default maps 50 // set the default maps
51 this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; 51 this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' };
52 //this._diffuseMapOb = { 'texture' : 'texture', 'wrap' : 'REPEAT' }; 52 //this._diffuseMapOb = { 'texture' : 'texture', 'wrap' : 'REPEAT' };
53 this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' }; 53 this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' };
54 this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' }; 54 this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' };
55 this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount }; 55 this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount };
@@ -140,86 +140,86 @@ var UberMaterial = function UberMaterial() {
140 // define the 4 lights 140 // define the 4 lights
141 this._lights = [ 141 this._lights = [
142 142
143 { 143 {
144 'type': 'point', // can be 'directional', 'point' or 'spot' 144 'type': 'point', // can be 'directional', 'point' or 'spot'
145 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity. 145 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity.
146 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit. 146 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit.
147 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights 147 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights
148 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights 148 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights
149 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic 149 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic
150 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color 150 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color
151 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color 151 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color
152 }, 152 },
153 { 153 {
154 'type': 'point', 154 'type': 'point',
155 'spotInnerCutoff': 9.0, 155 'spotInnerCutoff': 9.0,
156 'spotOuterCutoff': 20.0, 156 'spotOuterCutoff': 20.0,
157 'position': [-8.0, 2.0, 8.0], 157 'position': [-8.0, 2.0, 8.0],
158 'direction': [1.0, -1.0, -1.0], 158 'direction': [1.0, -1.0, -1.0],
159 'attenuation': [1.0, 0.025, 0.00125], 159 'attenuation': [1.0, 0.025, 0.00125],
160 'diffuseColor': [0.5, 1.0, 0.5, 1.0], 160 'diffuseColor': [0.5, 1.0, 0.5, 1.0],
161 'specularColor': [1.0, 1.0, 1.0, 1.0] 161 'specularColor': [1.0, 1.0, 1.0, 1.0]
162 }, 162 },
163 { 163 {
164 'type': 'point', 164 'type': 'point',
165 'spotInnerCutoff': 9.0, 165 'spotInnerCutoff': 9.0,
166 'spotOuterCutoff': 20.0, 166 'spotOuterCutoff': 20.0,
167 'position': [-8.0, 2.0, -8.0], 167 'position': [-8.0, 2.0, -8.0],
168 'direction': [1.0, -1.0, 1.0], 168 'direction': [1.0, -1.0, 1.0],
169 'attenuation': [1.0, 0.25, 0.0125], 169 'attenuation': [1.0, 0.25, 0.0125],
170 'diffuseColor': [0.5, 0.5, 1.0, 1.0], 170 'diffuseColor': [0.5, 0.5, 1.0, 1.0],
171 'specularColor': [1.0, 1.0, 1.0, 1.0] 171 'specularColor': [1.0, 1.0, 1.0, 1.0]
172 }, 172 },
173 { 173 {
174 'type': 'point', 174 'type': 'point',
175 'spotInnerCutoff': 9.0, 175 'spotInnerCutoff': 9.0,
176 'spotOuterCutoff': 20.0, 176 'spotOuterCutoff': 20.0,
177 'position': [8.0, 4.0, -8.0], 177 'position': [8.0, 4.0, -8.0],
178 'direction': [-1.0, -1.0, 1.0], 178 'direction': [-1.0, -1.0, 1.0],
179 'attenuation': [1.0, 0.25, 0.0125], 179 'attenuation': [1.0, 0.25, 0.0125],
180 'diffuseColor': [1.0, 1.0, 0.5, 1.0], 180 'diffuseColor': [1.0, 1.0, 0.5, 1.0],
181 'specularColor': [1.0, 1.0, 1.0, 1.0] 181 'specularColor': [1.0, 1.0, 1.0, 1.0]
182 } 182 }
183 ]; 183 ];
184 184
185 this._ubershaderCaps = 185 this._ubershaderCaps =
186 { 186 {
187 // ubershader material properties. 187 // ubershader material properties.
188 'material': { 188 'material': {
189 'ambientColor': this._ambientColor, // material ambient color 189 'ambientColor': this._ambientColor, // material ambient color
190 'diffuseColor': this._diffuseColor, // material diffuse color 190 'diffuseColor': this._diffuseColor, // material diffuse color
191 'specularColor': this._specularColor, // material specular color 191 'specularColor': this._specularColor, // material specular color
192 'specularPower': this._specularPower // material specular power (shininess) 192 'specularPower': this._specularPower // material specular power (shininess)
193 }, 193 },
194 194
195 // ubershader supports up to four lights. 195 // ubershader supports up to four lights.
196 'lighting': { 196 'lighting': {
197 'light0': this._lights[0], 197 'light0': this._lights[0],
198 'light1': this._lights[1], 198 'light1': this._lights[1],
199 'light2': this._lights[2], 199 'light2': this._lights[2],
200 'light3': this._lights[3] 200 'light3': this._lights[3]
201 }, 201 },
202 202
203 // uvTransform can be used to scale or offset the texture coordinates. 203 // uvTransform can be used to scale or offset the texture coordinates.
204 'uvTransform': [2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1], 204 'uvTransform': [2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1],
205 205
206 // optional diffuse map 206 // optional diffuse map
207 'diffuseMap': this._diffuseMapOb, 207 'diffuseMap': this._diffuseMapOb,
208 208
209 // optional normal map 209 // optional normal map
210 'normalMap': this._normalMapOb, 210 'normalMap': this._normalMapOb,
211 211
212 // optional specular map 212 // optional specular map
213 'specularMap': this._specularMapOb, 213 'specularMap': this._specularMapOb,
214 214
215 // optional environment map 215 // optional environment map
216 'environmentMap': this._environmentMapOb 216 'environmentMap': this._environmentMapOb
217 }; 217 };
218 218
219 this.updateAmbientColor = function () { 219 this.updateAmbientColor = function () {
220 this._ambientColor = this._propValues['ambientColor'].slice(0); 220 this._ambientColor = this._propValues['ambientColor'].slice(0);
221 var material = this._materialNode; 221 var material = this._materialNode;
222 //console.log( "ambient color: " + this._ambientColor ); 222 //console.log( "ambient color: " + this._ambientColor );
223 if (material) { 223 if (material) {
224 var technique = material.shaderProgram.defaultTechnique; 224 var technique = material.shaderProgram.defaultTechnique;
225 technique.u_ambientColor.set(this._ambientColor); 225 technique.u_ambientColor.set(this._ambientColor);
@@ -295,34 +295,34 @@ var UberMaterial = function UberMaterial() {
295 } 295 }
296 }; 296 };
297 297
298 this.updateDiffuseMap = function(value) { 298 this.updateDiffuseMap = function(value) {
299 var value = this._propValues[ "diffuseMap" ]; 299 var value = this._propValues[ "diffuseMap" ];
300 this._diffuseMapOb.texture = value; 300 this._diffuseMapOb.texture = value;
301 301
302 if ((value == null) || (value.length == 0)) { 302 if ((value == null) || (value.length == 0)) {
303 if (this._useDiffuseMap) { 303 if (this._useDiffuseMap) {
304 this._useDiffuseMap = false; 304 this._useDiffuseMap = false;
305 this._diffuseTexture = undefined; 305 this._diffuseTexture = undefined;
306 this.rebuildShader(); 306 this.rebuildShader();
307 } 307 }
308 } else { 308 } else {
309 if (!this._useDiffuseMap) { 309 if (!this._useDiffuseMap) {
310 this._useDiffuseMap = true; 310 this._useDiffuseMap = true;
311 this.rebuildShader(); 311 this.rebuildShader();
312 } else { 312 } else {
313 var material = this._materialNode; 313 var material = this._materialNode;
314 if (material) { 314 if (material) {
315 var technique = material.shaderProgram.defaultTechnique; 315 var technique = material.shaderProgram.defaultTechnique;
316 var renderer = RDGE.globals.engine.getContext().renderer; 316 var renderer = RDGE.globals.engine.getContext().renderer;
317 if (renderer && technique) { 317 if (renderer && technique) {
318 this._diffuseTexture = new Texture( this.getWorld(), value, this._ubershaderCaps.diffuseMap.wrap ); 318 this._diffuseTexture = new Texture( this.getWorld(), value, this._ubershaderCaps.diffuseMap.wrap );
319 var tex = this._diffuseTexture.getTexture(); 319 var tex = this._diffuseTexture.getTexture();
320 technique.s_diffuseMap.set( tex ); 320 technique.s_diffuseMap.set( tex );
321 } 321 }
322 } 322 }
323 } 323 }
324 } 324 }
325 }; 325 };
326 326
327 this.updateSpecularMap = function () { 327 this.updateSpecularMap = function () {
328 var value = this._propValues["specularMap"]; 328 var value = this._propValues["specularMap"];
@@ -395,7 +395,7 @@ var UberMaterial = function UberMaterial() {
395 newMat._useNormalMap = this._useNormalMap; 395 newMat._useNormalMap = this._useNormalMap;
396 newMat._useSpecularMap = this._useSpecularMap; 396 newMat._useSpecularMap = this._useSpecular