aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/backup-delete/Materials/UberMaterial.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-13 13:05:16 -0700
committerNivesh Rajbhandari2012-03-13 13:05:16 -0700
commite19376c54eedd1f1c457ba405b2f110be376a559 (patch)
treed48c090f71ed2cd6bd6ce38ff68c36ab69299985 /js/helper-classes/backup-delete/Materials/UberMaterial.js
parent970c2e63aa8ec3f70df2bf073cedb9e3b7617755 (diff)
parentf56b8cf4d3316d250c0f0045fb78f0dbd5c56e94 (diff)
downloadninja-e19376c54eedd1f1c457ba405b2f110be376a559.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/helper-classes/backup-delete/Materials/UberMaterial.js')
-rwxr-xr-xjs/helper-classes/backup-delete/Materials/UberMaterial.js73
1 files changed, 72 insertions, 1 deletions
diff --git a/js/helper-classes/backup-delete/Materials/UberMaterial.js b/js/helper-classes/backup-delete/Materials/UberMaterial.js
index c7855c95..1652b4c9 100755
--- a/js/helper-classes/backup-delete/Materials/UberMaterial.js
+++ b/js/helper-classes/backup-delete/Materials/UberMaterial.js
@@ -30,6 +30,8 @@ function UberMaterial()
30 this._specularPower = 32.0; 30 this._specularPower = 32.0;
31 this._environmentAmount = 0.2; // 0 .. 1 31 this._environmentAmount = 0.2; // 0 .. 1
32 32
33 this._MAX_LIGHTS = 4;
34
33 // set the default maps 35 // set the default maps
34 this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; 36 this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' };
35 this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' }; 37 this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' };
@@ -424,10 +426,79 @@ function UberMaterial()
424 this._shader = this.buildUberShader( this._ubershaderCaps ); 426 this._shader = this.buildUberShader( this._ubershaderCaps );
425 427
426 // set up the material node 428 // set up the material node
427 this._materialNode = createMaterialNode("uberMaterial"); 429 this._materialNode = createMaterialNode("uberMaterial_" + world.generateUniqueNodeID());
428 this._materialNode.setShader(this._shader); 430 this._materialNode.setShader(this._shader);
429 }; 431 };
430 432
433 this.import = function( importStr )
434 {
435 // limit the key searches to this material
436 var endKey = "endMaterial\n";
437 var index = importStr.indexOf( endKey );
438 index += endKey.length;
439 importStr = importStr.substr( index );
440 }
441
442 this.export = function()
443 {
444 // every material needs the base type and instance name
445 var exportStr = "material: " + this.getShaderName() + "\n";
446 exportStr += "name: " + this.getName() + "\n";
447
448 var caps = this._ubershaderCaps;
449
450 // export the material properties
451 if (typeof caps.material != 'undefined')
452 {
453 exportStr += "material: true\n";
454 exportStr += "ambientColor: " + caps.material.ambientColor + "\n";
455 exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n";
456 exportStr += "specularColor: " + caps.material.specularColor + "\n";
457 exportStr += "specularPower: " + caps.material.specularPower + "\n";
458 }
459
460 if (typeof caps.lighting != 'undefined')
461 {
462 var light = caps.lighting['light' + i];
463 var t;
464 for (var i=0; i<this._MAX_LIGHTS; i++)
465 {
466 var light = caps.lighting["light" + i];
467 if( typeof light != "undefined")
468 {
469 exportStr += "light" + i + ': ' + light.type + "\n";
470
471 if (light.type === 'directional')
472 {
473 exportStr += 'light' + i + 'Dir: ' + light['direction'] + '\n';
474 }
475 else if (light.type === 'spot')
476 {
477 exportStr += 'light' + i + 'Pos: ' + light['position'] + '\n';
478
479 var deg2Rad = Math.PI / 180;
480 exportStr += 'light' + i + 'Spot: ' + [ Math.cos( ( light['spotInnerCutoff'] || 45.0 ) * deg2Rad ),
481 Math.cos( ( light['spotOuterCutoff'] || 90.0 ) * deg2Rad )] + '\n';
482 }
483 else // light.type === 'point'
484 {
485 technique['u_light'+i+'Pos'].set(light['position'] || [ 0, 0, 0 ]);
486 technique['u_light'+i+'Atten'].set(light['attenuation'] || [ 1,0,0 ]);
487 }
488 exportStr += 'light' + i + 'Color: ' + light['diffuseColor'] || [ 1,1,1,1 ] + '\n';
489 exportStr += 'light' + i + 'SpecularColor: ' + light['specularColor'] || [ 1, 1, 1, 1 ] + '\n';
490
491 exportStr += "endlight\n";
492 }
493 }
494 }
495
496 // every material needs to terminate like this
497 exportStr += "endMaterial\n";
498
499 return exportStr;
500 }
501
431 this.buildUberShader = function(caps) 502 this.buildUberShader = function(caps)
432 { 503 {
433 var preproc = ""; 504 var preproc = "";