diff options
Diffstat (limited to 'js/lib/rdge/materials/uber-material.js')
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index c1d1913c..4ff3676a 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js | |||
@@ -240,7 +240,7 @@ var UberMaterial = function UberMaterial() { | |||
240 | var material = this._materialNode; | 240 | var material = this._materialNode; |
241 | if (material) { | 241 | if (material) { |
242 | var technique = material.shaderProgram.defaultTechnique; | 242 | var technique = material.shaderProgram.defaultTechnique; |
243 | var renderer = g_Engine.getContext().renderer; | 243 | var renderer = RDGE.globals.engine.getContext().renderer; |
244 | if (renderer && technique) { | 244 | if (renderer && technique) { |
245 | var tex = renderer.getTextureByName(value, caps.environmentMap.wrap); | 245 | var tex = renderer.getTextureByName(value, caps.environmentMap.wrap); |
246 | this.registerTexture( tex ); | 246 | this.registerTexture( tex ); |
@@ -268,7 +268,7 @@ var UberMaterial = function UberMaterial() { | |||
268 | var material = this._materialNode; | 268 | var material = this._materialNode; |
269 | if (material) { | 269 | if (material) { |
270 | var technique = material.shaderProgram.defaultTechnique; | 270 | var technique = material.shaderProgram.defaultTechnique; |
271 | var renderer = g_Engine.getContext().renderer; | 271 | var renderer = RDGE.globals.engine.getContext().renderer; |
272 | if (renderer && technique) { | 272 | if (renderer && technique) { |
273 | var tex = renderer.getTextureByName(value, caps.diffuseMap.wrap); | 273 | var tex = renderer.getTextureByName(value, caps.diffuseMap.wrap); |
274 | this.registerTexture( tex ); | 274 | this.registerTexture( tex ); |
@@ -296,7 +296,7 @@ var UberMaterial = function UberMaterial() { | |||
296 | var material = this._materialNode; | 296 | var material = this._materialNode; |
297 | if (material) { | 297 | if (material) { |
298 | var technique = material.shaderProgram.defaultTechnique; | 298 | var technique = material.shaderProgram.defaultTechnique; |
299 | var renderer = g_Engine.getContext().renderer; | 299 | var renderer = RDGE.globals.engine.getContext().renderer; |
300 | if (renderer && technique) { | 300 | if (renderer && technique) { |
301 | var tex = renderer.getTextureByName(value, caps.specularMap.wrap); | 301 | var tex = renderer.getTextureByName(value, caps.specularMap.wrap); |
302 | this.registerTexture( tex ); | 302 | this.registerTexture( tex ); |
@@ -324,7 +324,7 @@ var UberMaterial = function UberMaterial() { | |||
324 | var material = this._materialNode; | 324 | var material = this._materialNode; |
325 | if (material) { | 325 | if (material) { |
326 | var technique = material.shaderProgram.defaultTechnique; | 326 | var technique = material.shaderProgram.defaultTechnique; |
327 | var renderer = g_Engine.getContext().renderer; | 327 | var renderer = RDGE.globals.engine.getContext().renderer; |
328 | if (renderer && technique) { | 328 | if (renderer && technique) { |
329 | var tex = renderer.getTextureByName(value, caps.normalMap.wrap); | 329 | var tex = renderer.getTextureByName(value, caps.normalMap.wrap); |
330 | this.registerTexture( tex ); | 330 | this.registerTexture( tex ); |
@@ -366,7 +366,7 @@ var UberMaterial = function UberMaterial() { | |||
366 | this._shader = this.buildUberShader( this._ubershaderCaps ); | 366 | this._shader = this.buildUberShader( this._ubershaderCaps ); |
367 | 367 | ||
368 | // set up the material node | 368 | // set up the material node |
369 | this._materialNode = createMaterialNode("uberMaterial" + "_" + world.generateUniqueNodeID()); | 369 | this._materialNode = RDGE.createMaterialNode("uberMaterial" + "_" + world.generateUniqueNodeID()); |
370 | this._materialNode.setShader(this._shader); | 370 | this._materialNode.setShader(this._shader); |
371 | }; | 371 | }; |
372 | 372 | ||
@@ -437,8 +437,9 @@ var UberMaterial = function UberMaterial() { | |||
437 | // push the light | 437 | // push the light |
438 | this._lights.push( light ); | 438 | this._lights.push( light ); |
439 | } | 439 | } |
440 | else | 440 | else { |
441 | this._lights[i] = 'undefined'; | 441 | this._lights[i] = 'undefined'; |
442 | } | ||
442 | 443 | ||
443 | // advance to the next light | 444 | // advance to the next light |
444 | var endLightKey = "endMaterial\n"; | 445 | var endLightKey = "endMaterial\n"; |
@@ -462,16 +463,19 @@ var UberMaterial = function UberMaterial() { | |||
462 | } | 463 | } |
463 | 464 | ||
464 | var diffuseMap = pu.nextValue( "diffuseMap: " ) | 465 | var diffuseMap = pu.nextValue( "diffuseMap: " ) |
465 | if(diffuseMap) | 466 | if(diffuseMap) { |
466 | this.setProperty( "diffuseMap", diffuseMap ); | 467 | this.setProperty( "diffuseMap", diffuseMap ); |
468 | } | ||
467 | 469 | ||
468 | var normalMap = pu.nextValue( "normalMap: " ); | 470 | var normalMap = pu.nextValue( "normalMap: " ); |
469 | if(normalMap) | 471 | if(normalMap) { |
470 | this.setProperty( "normalMap", normalMap ); | 472 | this.setProperty( "normalMap", normalMap ); |
473 | } | ||
471 | 474 | ||
472 | var specularMap = pu.nextValue( "specularMap: " ); | 475 | var specularMap = pu.nextValue( "specularMap: " ); |
473 | if(specularMap) | 476 | if(specularMap) { |
474 | this.setProperty( "specularMap", specularMap ); | 477 | this.setProperty( "specularMap", specularMap ); |
478 | } | ||
475 | 479 | ||
476 | var environmentMap = pu.nextValue( "environmentMap: " ); | 480 | var environmentMap = pu.nextValue( "environmentMap: " ); |
477 | if(environmentMap) | 481 | if(environmentMap) |
@@ -481,7 +485,7 @@ var UberMaterial = function UberMaterial() { | |||
481 | } | 485 | } |
482 | 486 | ||
483 | this.rebuildShader(); | 487 | this.rebuildShader(); |
484 | } | 488 | }; |
485 | 489 | ||
486 | this.importJSON = function( jObj ) | 490 | this.importJSON = function( jObj ) |
487 | { | 491 | { |
@@ -556,16 +560,19 @@ var UberMaterial = function UberMaterial() { | |||
556 | } | 560 | } |
557 | 561 | ||
558 | var diffuseMap = jObj['diffuseMap']; | 562 | var diffuseMap = jObj['diffuseMap']; |
559 | if(diffuseMap) | 563 | if(diffuseMap) { |
560 | this.setProperty( "diffuseMap", diffuseMap ); | 564 | this.setProperty( "diffuseMap", diffuseMap ); |
565 | } | ||
561 | 566 | ||
562 | var normalMap = jObj['normalMap']; | 567 | var normalMap = jObj['normalMap']; |
563 | if(normalMap) | 568 | if(normalMap) { |
564 | this.setProperty( "normalMap", normalMap ); | 569 | this.setProperty( "normalMap", normalMap ); |
570 | } | ||
565 | 571 | ||
566 | var specularMap = jObj['specularMap']; | 572 | var specularMap = jObj['specularMap']; |
567 | if(specularMap) | 573 | if(specularMap) { |
568 | this.setProperty( "specularMap", specularMap ); | 574 | this.setProperty( "specularMap", specularMap ); |
575 | } | ||
569 | 576 | ||
570 | var environmentMap = jObj['environmentMap']; | 577 | var environmentMap = jObj['environmentMap']; |
571 | if(environmentMap) | 578 | if(environmentMap) |
@@ -575,7 +582,7 @@ var UberMaterial = function UberMaterial() { | |||
575 | } | 582 | } |
576 | 583 | ||
577 | this.rebuildShader(); | 584 | this.rebuildShader(); |
578 | } | 585 | }; |
579 | 586 | ||
580 | this.exportJSON = function() | 587 | this.exportJSON = function() |
581 | { | 588 | { |
@@ -640,14 +647,17 @@ var UberMaterial = function UberMaterial() { | |||
640 | jObj.lights = lightArray; | 647 | jObj.lights = lightArray; |
641 | } | 648 | } |
642 | 649 | ||
643 | if(typeof caps.diffuseMap != 'undefined') | 650 | if(typeof caps.diffuseMap != 'undefined') { |
644 | jObj['diffuseMap'] = caps.diffuseMap.texture; | 651 | jObj['diffuseMap'] = caps.diffuseMap.texture; |
652 | } | ||
645 | 653 | ||
646 | if(typeof caps.normalMap != 'undefined') | 654 | if(typeof caps.normalMap != 'undefined') { |
647 | jObj['normalMap'] = caps.normalMap.texture; | 655 | jObj['normalMap'] = caps.normalMap.texture; |
656 | } | ||
648 | 657 | ||
649 | if(typeof caps.specularMap != 'undefined') | 658 | if(typeof caps.specularMap != 'undefined') { |
650 | jObj['specularMap'] = caps.specularMap.texture; | 659 | jObj['specularMap'] = caps.specularMap.texture; |
660 | } | ||
651 | 661 | ||
652 | if(typeof caps.environmentMap != 'undefined') | 662 | if(typeof caps.environmentMap != 'undefined') |
653 | { | 663 | { |
@@ -656,7 +666,7 @@ var UberMaterial = function UberMaterial() { | |||
656 | } | 666 | } |
657 | 667 | ||
658 | return jObj; | 668 | return jObj; |
659 | } | 669 | }; |
660 | 670 | ||
661 | 671 | ||
662 | this.export = function() | 672 | this.export = function() |
@@ -716,17 +726,21 @@ var UberMaterial = function UberMaterial() { | |||
716 | } | 726 | } |
717 | 727 | ||
718 | var world = this.getWorld(); | 728 | var world = this.getWorld(); |
719 | if (!world) | 729 | if (!world) { |
720 | throw new Error( "no world in material.export, " + this.getName() ); | 730 | throw new Error( "no world in material.export, " + this.getName() ); |
731 | } | ||
721 | 732 | ||
722 | if(typeof caps.diffuseMap != 'undefined') | 733 | if(typeof caps.diffuseMap != 'undefined') { |
723 | exportStr += "diffuseMap: " + caps.diffuseMap.texture + "\n"; | 734 | exportStr += "diffuseMap: " + caps.diffuseMap.texture + "\n"; |
735 | } | ||
724 | 736 | ||
725 | if(typeof caps.normalMap != 'undefined') | 737 | if(typeof caps.normalMap != 'undefined') { |
726 | exportStr += "normalMap: " + caps.normalMap.texture + "\n"; | 738 | exportStr += "normalMap: " + caps.normalMap.texture + "\n"; |
739 | } | ||
727 | 740 | ||
728 | if(typeof caps.specularMap != 'undefined') | 741 | if(typeof caps.specularMap != 'undefined') { |
729 | exportStr += "specularMap: " + caps.specularMap.texture + "\n"; | 742 | exportStr += "specularMap: " + caps.specularMap.texture + "\n"; |
743 | } | ||
730 | 744 | ||
731 | if(typeof caps.environme |