From fb0a659c9ca3479fd6799325498b11f074689936 Mon Sep 17 00:00:00 2001
From: John Mayhew
Date: Mon, 2 Apr 2012 14:57:31 -0700
Subject: -Namespaced all RDGE javascript.
-Removed the following unused files from the build script
/core/script/fx/blur.js
/core/script/fx/ssao.js
/core/script/animation.js
- Fully removed the following from the build and from source control as they are unused or no longer needed
/core/script/util/dbgpanel.js
/core/script/util/fpsTracker.js
/core/script/util/statTracker.js
/core/script/input.js
/core/script/TextureManager.js
/core/script/ubershader.js
---
js/lib/rdge/materials/uber-material.js | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
(limited to 'js/lib/rdge/materials/uber-material.js')
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js
index 6bc35d51..e2f86511 100755
--- a/js/lib/rdge/materials/uber-material.js
+++ b/js/lib/rdge/materials/uber-material.js
@@ -237,7 +237,7 @@ var UberMaterial = function UberMaterial() {
var material = this._materialNode;
if (material) {
var technique = material.shaderProgram.defaultTechnique;
- var renderer = g_Engine.getContext().renderer;
+ var renderer = RDGE.globals.engine.getContext().renderer;
if (renderer && technique) {
var tex = renderer.getTextureByName(value, caps.environmentMap.wrap);
this.registerTexture( tex );
@@ -265,7 +265,7 @@ var UberMaterial = function UberMaterial() {
var material = this._materialNode;
if (material) {
var technique = material.shaderProgram.defaultTechnique;
- var renderer = g_Engine.getContext().renderer;
+ var renderer = RDGE.globals.engine.getContext().renderer;
if (renderer && technique) {
var tex = renderer.getTextureByName(value, caps.diffuseMap.wrap);
this.registerTexture( tex );
@@ -293,7 +293,7 @@ var UberMaterial = function UberMaterial() {
var material = this._materialNode;
if (material) {
var technique = material.shaderProgram.defaultTechnique;
- var renderer = g_Engine.getContext().renderer;
+ var renderer = RDGE.globals.engine.getContext().renderer;
if (renderer && technique) {
var tex = renderer.getTextureByName(value, caps.specularMap.wrap);
this.registerTexture( tex );
@@ -321,7 +321,7 @@ var UberMaterial = function UberMaterial() {
var material = this._materialNode;
if (material) {
var technique = material.shaderProgram.defaultTechnique;
- var renderer = g_Engine.getContext().renderer;
+ var renderer = RDGE.globals.engine.getContext().renderer;
if (renderer && technique) {
var tex = renderer.getTextureByName(value, caps.normalMap.wrap);
this.registerTexture( tex );
@@ -363,7 +363,7 @@ var UberMaterial = function UberMaterial() {
this._shader = this.buildUberShader( this._ubershaderCaps );
// set up the material node
- this._materialNode = createMaterialNode("uberMaterial");
+ this._materialNode = RDGE.createMaterialNode("uberMaterial");
this._materialNode.setShader(this._shader);
};
@@ -450,7 +450,7 @@ var UberMaterial = function UberMaterial() {
var fshader = preproc + uberFShader;
// build output jshader
- var uberJShader = new jshader();
+ var uberJShader = new RDGE.jshader();
uberJShader.def = {
'shaders': {
'defaultVShader': vshader,
@@ -517,9 +517,9 @@ var UberMaterial = function UberMaterial() {
}
}
}
- technique.u_uvMatrix.set(caps.uvTransform || mat4.identity());
+ technique.u_uvMatrix.set(caps.uvTransform || RDGE.mat4.identity());
- var renderer = g_Engine.getContext().renderer;
+ var renderer = RDGE.globals.engine.getContext().renderer;
if(this._useDiffuseMap) {
var tex = renderer.getTextureByName(caps.diffuseMap.texture, caps.diffuseMap.wrap, caps.diffuseMap.mips);
this.registerTexture( tex );
--
cgit v1.2.3
From 8d1cc709340da845d76f84220fe92c11e6217ff3 Mon Sep 17 00:00:00 2001
From: John Mayhew
Date: Tue, 3 Apr 2012 09:36:14 -0700
Subject: Made use of semicolons consistent and updated new files to use the
new RDGE namespace
---
js/lib/rdge/materials/uber-material.js | 1721 ++++++++++++++++----------------
1 file changed, 841 insertions(+), 880 deletions(-)
(limited to 'js/lib/rdge/materials/uber-material.js')
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js
index 4ff3676a..da6ea9f4 100755
--- a/js/lib/rdge/materials/uber-material.js
+++ b/js/lib/rdge/materials/uber-material.js
@@ -1,8 +1,8 @@
/*
- This file contains proprietary software owned by Motorola Mobility, Inc.
- No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
- (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
- */
+This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
+ */
var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
var Material = require("js/lib/rdge/materials/material").Material;
@@ -11,987 +11,948 @@ var UberMaterial = function UberMaterial() {
///////////////////////////////////////////////////////////////////////
// Instance variables
///////////////////////////////////////////////////////////////////////
- this._name = "UberMaterial";
- this._shaderName = "uber";
- this.getShaderName = function() { return this._shaderName; };
-
- // set some default values
- this._ambientColor = [ 0.0, 0.0, 0.0, 1.0 ];
- this._diffuseColor = [ 1.0, 1.0, 1.0, 1.0 ];
- this._specularColor = [ 1.0, 1.0, 1.0, 1.0 ];
- this._specularPower = 32.0;
- this._environmentAmount = 0.2; // 0 .. 1
-
- // set the default maps
- this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' };
- this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' };
- this._specularMapOb = { 'texture' : 'assets/images/rocky-spec.jpg', 'wrap' : 'REPEAT' };
- this._environmentMapOb = { 'texture' : 'assets/images/silver.png', 'wrap' : 'CLAMP', 'envReflection' : this._environmentAmount };
-
- this._useDiffuseMap = true;
- this._useNormalMap = true;
- this._useSpecularMap = true;
- this._useEnvironmentMap = true;
- this._useLights = [true, true, true, true];
-
- this._MAX_LIGHTS = 4;
+ this._name = "UberMaterial";
+ this._shaderName = "uber";
+ this.getShaderName = function () { return this._shaderName; };
+
+ // set some default values
+ this._ambientColor = [0.0, 0.0, 0.0, 1.0];
+ this._diffuseColor = [1.0, 1.0, 1.0, 1.0];
+ this._specularColor = [1.0, 1.0, 1.0, 1.0];
+ this._specularPower = 32.0;
+ this._environmentAmount = 0.2; // 0 .. 1
+
+ // set the default maps
+ this._diffuseMapOb = { 'texture': 'assets/images/rocky-diffuse.jpg', 'wrap': 'REPEAT' };
+ this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' };
+ this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' };
+ this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount };
+
+ this._useDiffuseMap = true;
+ this._useNormalMap = true;
+ this._useSpecularMap = true;
+ this._useEnvironmentMap = true;
+ this._useLights = [true, true, true, true];
+
+ this._MAX_LIGHTS = 4;
///////////////////////////////////////////////////////////////////////
// Material Property Accessors
///////////////////////////////////////////////////////////////////////
- this._propNames = ["ambientColor", "diffuseColor", "specularColor", "specularPower" , "diffuseMap", "normalMap", "specularMap", "environmentMap", "environmentAmount" ];
- this._propLabels = ["Ambient Color", "Diffuse Color", "Specular Color", "Specular Power", "Texture Map", "Bump Map", "Specular Map", "Environment Map", "Environment Map Amount" ];
- this._propTypes = ["color", "color", "color", "float", "file", "file", "file", "file", "float" ];
- this._propValues = [];
-
- this._propValues[ this._propNames[0] ] = this._ambientColor.slice(0);
- this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(0);
- this._propValues[ this._propNames[2] ] = this._specularColor.slice(0);
- this._propValues[ this._propNames[3] ] = this._specularPower;
- this._propValues[ this._propNames[4] ] = this._diffuseMapOb['texture'];
- this._propValues[ this._propNames[5] ] = this._normalMapOb['texture'];
- this._propValues[ this._propNames[6] ] = this._specularMapOb['texture'];
- this._propValues[ this._propNames[7] ] = this._environmentMapOb['texture'];
- this._propValues[ this._propNames[8] ] = this._environmentMapOb['envReflection'];
-
- this.setProperty = function( prop, value ) {
- if (prop == "color") prop = "ambientColor";
- var valid = this.validateProperty( prop, value );
- if (valid) {
- this._propValues[prop] = value;
-
- switch (prop)
- {
- case "diffuseMap":
- this.updateDiffuseMap();
- break;
- case "normalMap":
- this.updateNormalMap();
- break;
- case "specularMap":
- this.updateSpecularMap();
- break;
- case "environmentMap":
- this.updateEnvironmentMap();
- break;
- case "environmentAmount":
- this.updateEnvironmentAmount( value );
- break;
- case "specularPower":
- this.updateSpecularPower( value );
- break;
- case "ambientColor":
- this.updateAmbientColor( value );
- break;
- case "diffuseColor":
- this.updateDiffuseColor( value );
- break;
- case "specularColor":
- this.updateSpecularColor( value );
- break;
- }
- }
- };
+ this._propNames = ["ambientColor", "diffuseColor", "specularColor", "specularPower", "diffuseMap", "normalMap", "specularMap", "environmentMap", "environmentAmount"];
+ this._propLabels = ["Ambient Color", "Diffuse Color", "Specular Color", "Specular Power", "Texture Map", "Bump Map", "Specular Map", "Environment Map", "Environment Map Amount"];
+ this._propTypes = ["color", "color", "color", "float", "file", "file", "file", "file", "float"];
+ this._propValues = [];
+
+ this._propValues[this._propNames[0]] = this._ambientColor.slice(0);
+ this._propValues[this._propNames[1]] = this._diffuseColor.slice(0);
+ this._propValues[this._propNames[2]] = this._specularColor.slice(0);
+ this._propValues[this._propNames[3]] = this._specularPower;
+ this._propValues[this._propNames[4]] = this._diffuseMapOb['texture'];
+ this._propValues[this._propNames[5]] = this._normalMapOb['texture'];
+ this._propValues[this._propNames[6]] = this._specularMapOb['texture'];
+ this._propValues[this._propNames[7]] = this._environmentMapOb['texture'];
+ this._propValues[this._propNames[8]] = this._environmentMapOb['envReflection'];
+
+ this.setProperty = function (prop, value) {
+ if (prop == "color") prop = "ambientColor";
+ var valid = this.validateProperty(prop, value);
+ if (valid) {
+ this._propValues[prop] = value;
+
+ switch (prop) {
+ case "diffuseMap":
+ this.updateDiffuseMap();
+ break;
+ case "normalMap":
+ this.updateNormalMap();
+ break;
+ case "specularMap":
+ this.updateSpecularMap();
+ break;
+ case "environmentMap":
+ this.updateEnvironmentMap();
+ break;
+ case "environmentAmount":
+ this.updateEnvironmentAmount(value);
+ break;
+ case "specularPower":
+ this.updateSpecularPower(value);
+ break;
+ case "ambientColor":
+ this.updateAmbientColor(value);
+ break;
+ case "diffuseColor":
+ this.updateDiffuseColor(value);
+ break;
+ case "specularColor":
+ this.updateSpecularColor(value);
+ break;
+ }
+ }
+ };
///////////////////////////////////////////////////////////////////////
- // define the 4 lights
- this._lights = [
+ // define the 4 lights
+ this._lights = [
{
- 'type' : 'point', // can be 'directional', 'point' or 'spot'
- 'spotInnerCutoff' : 14.0, // fragments in the inner cutoff 'cone' are full intensity.
- 'spotOuterCutoff' : 15.0, // fragments outside the outer cutoff 'cone' are unlit.
- 'position' : [ 8.0, 2.0, 8.0 ], // light position; ignored for directional lights
- 'direction' : [ -1.0, -1.0, -1.0 ], // light direction; ignored for point lights
- 'attenuation' : [ 1.0, 0.025, 0.00125 ], // light attenuation; constant, linear, quadratic
- 'diffuseColor' : [ 1.0, 0.5, 0.5, 1.0 ], // diffuse light color
- 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ] // specular light color
+ 'type': 'point', // can be 'directional', 'point' or 'spot'
+ 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity.
+ 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit.
+ 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights
+ 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights
+ 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic
+ 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color
+ 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color
},
{
- 'type' : 'point',
- 'spotInnerCutoff' : 9.0,
- 'spotOuterCutoff' : 20.0,
- 'position' : [ -8.0, 2.0, 8.0 ],
- 'direction' : [ 1.0, -1.0, -1.0 ],
- 'attenuation' : [ 1.0, 0.025, 0.00125 ],
- 'diffuseColor' : [ 0.5, 1.0, 0.5, 1.0 ],
- 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ]
+ 'type': 'point',
+ 'spotInnerCutoff': 9.0,
+ 'spotOuterCutoff': 20.0,
+ 'position': [-8.0, 2.0, 8.0],
+ 'direction': [1.0, -1.0, -1.0],
+ 'attenuation': [1.0, 0.025, 0.00125],
+ 'diffuseColor': [0.5, 1.0, 0.5, 1.0],
+ 'specularColor': [1.0, 1.0, 1.0, 1.0]
},
{
- 'type' : 'point',
- 'spotInnerCutoff' : 9.0,
- 'spotOuterCutoff' : 20.0,
- 'position' : [ -8.0, 2.0, -8.0 ],
- 'direction' : [ 1.0, -1.0, 1.0 ],
- 'attenuation' : [ 1.0, 0.25, 0.0125 ],
- 'diffuseColor' : [ 0.5, 0.5, 1.0, 1.0 ],
- 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ]
+ 'type': 'point',
+ 'spotInnerCutoff': 9.0,
+ 'spotOuterCutoff': 20.0,
+ 'position': [-8.0, 2.0, -8.0],
+ 'direction': [1.0, -1.0, 1.0],
+ 'attenuation': [1.0, 0.25, 0.0125],
+ 'diffuseColor': [0.5, 0.5, 1.0, 1.0],
+ 'specularColor': [1.0, 1.0, 1.0, 1.0]
},
{
- 'type' : 'point',
- 'spotInnerCutoff' : 9.0,
- 'spotOuterCutoff' : 20.0,
- 'position' : [ 8.0, 4.0, -8.0 ],
- 'direction' : [ -1.0, -1.0, 1.0 ],
- 'attenuation' : [ 1.0, 0.25, 0.0125 ],
- 'diffuseColor' : [ 1.0, 1.0, 0.5, 1.0 ],
- 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ]
+ 'type': 'point',
+ 'spotInnerCutoff': 9.0,
+ 'spotOuterCutoff': 20.0,
+ 'position': [8.0, 4.0, -8.0],
+ 'direction': [-1.0, -1.0, 1.0],
+ 'attenuation': [1.0, 0.25, 0.0125],
+ 'diffuseColor': [1.0, 1.0, 0.5, 1.0],
+ 'specularColor': [1.0, 1.0, 1.0, 1.0]
}
];
- this._ubershaderCaps =
+ this._ubershaderCaps =
{
- // ubershader material properties.
- 'material' : {
- 'ambientColor' : this._ambientColor, // material ambient color
- 'diffuseColor' : this._diffuseColor, // material diffuse color
- 'specularColor' : this._specularColor, // material specular color
- 'specularPower' : this._specularPower // material specular power (shininess)
- },
-
- // ubershader supports up to four lights.
- 'lighting' : {
- 'light0' : this._lights[0],
- 'light1' : this._lights[1],
- 'light2' : this._lights[2],
- 'light3' : this._lights[3]
- },
-
- // uvTransform can be used to scale or offset the texture coordinates.
- 'uvTransform' : [ 2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1],
-
- // optional diffuse map
- 'diffuseMap' : this._diffuseMapOb,
-
- // optional normal map
- 'normalMap' : this._normalMapOb,
-
- // optional specular map
- 'specularMap' : this._specularMapOb,
-
- // optional environment map
- 'environmentMap' : this._environmentMapOb
+ // ubershader material properties.
+ 'material': {
+ 'ambientColor': this._ambientColor, // material ambient color
+ 'diffuseColor': this._diffuseColor, // material diffuse color
+ 'specularColor': this._specularColor, // material specular color
+ 'specularPower': this._specularPower // material specular power (shininess)
+ },
+
+ // ubershader supports up to four lights.
+ 'lighting': {
+ 'light0': this._lights[0],
+ 'light1': this._lights[1],
+ 'light2': this._lights[2],
+ 'light3': this._lights[3]
+ },
+
+ // uvTransform can be used to scale or offset the texture coordinates.
+ 'uvTransform': [2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1],
+
+ // optional diffuse map
+ 'diffuseMap': this._diffuseMapOb,
+
+ // optional normal map
+ 'normalMap': this._normalMapOb,
+
+ // optional specular map
+ 'specularMap': this._specularMapOb,
+
+ // optional environment map
+ 'environmentMap': this._environmentMapOb
};
- this.updateAmbientColor = function() {
- this._ambientColor = this._propValues['ambientColor'].slice(0);
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- technique.u_ambientColor.set(this._ambientColor);
- }
- };
+ this.updateAmbientColor = function () {
+ this._ambientColor = this._propValues['ambientColor'].slice(0);
+ var material = this._materialNode;
+ if (material) {
+ var technique = material.shaderProgram.defaultTechnique;
+ technique.u_ambientColor.set(this._ambientColor);
+ }
+ };
- this.updateDiffuseColor = function() {
- this._diffuseColor = this._propValues['diffuseColor'].slice(0);
+ this.updateDiffuseColor = function () {
+ this._diffuseColor = this._propValues['diffuseColor'].slice(0);
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- technique.u_diffuseColor.set(this._diffuseColor);
- }
- };
+ var material = this._materialNode;
+ if (material) {
+ var technique = material.shaderProgram.defaultTechnique;
+ technique.u_diffuseColor.set(this._diffuseColor);
+ }
+ };
- this.updateSpecularColor = function( value ) {
- this._specularColor = this._propValues['specularColor'];
+ this.updateSpecularColor = function (value) {
+ this._specularColor = this._propValues['specularColor'];
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- technique.u_specularColor.set(this._specularColor);
- }
- };
+ var material = this._materialNode;
+ if (material) {
+ var technique = material.shaderProgram.defaultTechnique;
+ technique.u_specularColor.set(this._specularColor);
+ }
+ };
- this.updateSpecularPower = function( value) {
- this._specularPower = this._propValues['specularPower'];
+ this.updateSpecularPower = function (value) {
+ this._specularPower = this._propValues['specularPower'];
- var material = this._materialNode;
- if (material)
- {
- var technique = material.shaderProgram.defaultTechnique;
- technique.u_specularPower.set([this._specularPower]);
- }
- };
+ var material = this._materialNode;
+ if (material) {
+ var technique = material.shaderProgram.defaultTechnique;
+ technique.u_specularPower.set([this._specularPower]);
+ }
+ };
- this.updateEnvironmentAmount = function(value) {
- this._environmentMapOb.envReflectionAmount = value;
+ this.updateEnvironmentAmount = function (value) {
+ this._environmentMapOb.envReflectionAmount = value;
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- technique.u_envReflection.set([this._environmentMapOb.envReflection]);
- }
- };
+ var material = this._materialNode;
+ if (material) {
+ var technique = material.shaderProgram.defaultTechnique;
+ technique.u_envReflection.set([this._environmentMapOb.envReflection]);
+ }
+ };
- this.updateEnvironmentMap = function() {
- var value = this._propValues[ "environmentMap" ];
- this._environmentMapOb.texture = value;
-
- if ((value == null) || (value.length == 0)) {
- if (this._useEnvironmentMap) {
- this._useEnvironmentMap = false;
- this.rebuildShader();
- }
- } else {
- if (!this._useEnvironmentMap) {
- this._useEnvironmentMap = true;
- this.rebuildShader();
- } else {
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- var renderer = RDGE.globals.engine.getContext().renderer;
- if (renderer && technique) {
- var tex = renderer.getTextureByName(value, caps.environmentMap.wrap);
- this.registerTexture( tex );
- technique.s_environmentMap.set( tex );
- }
- }
- }
- }
- };
+ this.updateEnvironmentMap = function () {
+ var value = this._propValues["environmentMap"];
+ this._environmentMapOb.texture = value;
- this.updateDiffuseMap = function(value) {
- var value = this._propValues[ "diffuseMap" ];
- this._diffuseMapOb.texture = value;
-
- if ((value == null) || (value.length == 0)) {
- if (this._useDiffuseMap) {
- this._useDiffuseMap = false;
- this.rebuildShader();
- }
- } else {
- if (!this._useDiffuseMap) {
- this._useDiffuseMap = true;
- this.rebuildShader();
- } else {
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- var renderer = RDGE.globals.engine.getContext().renderer;
- if (renderer && technique) {
- var tex = renderer.getTextureByName(value, caps.diffuseMap.wrap);
- this.registerTexture( tex );
- technique.s_diffuseMap.set( tex );
- }
- }
- }
- }
- };
+ if ((value == null) || (value.length == 0)) {
+ if (this._useEnvironmentMap) {
+ this._useEnvironmentMap = false;
+ this.rebuildShader();
+ }
+ } else {
+ if (!this._useEnvironmentMap) {
+ this._useEnvironmentMap = true;
+ this.rebuildShader();
+ } else {
+ var material = this._materialNode;
+ if (material) {
+ var technique = material.shaderProgram.defaultTechnique;
+ var renderer = RDGE.globals.engine.getContext().renderer;
+ if (renderer && technique) {
+ var tex = renderer.getTextureByName(value, caps.environmentMap.wrap);
+ this.registerTexture(tex);
+ technique.s_environmentMap.set(tex);
+ }
+ }
+ }
+ }
+ };
- this.updateSpecularMap = function() {
- var value = this._propValues[ "specularMap" ];
- this._specularMapOb.texture = value;
-
- if ((value == null) || (value.length == 0)) {
- if (this._useSpecularMap) {
- this._useSpecularMap = false;
- this.rebuildShader();
- }
- } else {
- if (!this._useSpecularMap) {
- this._useSpecularMap = true;
- this.rebuildShader();
- } else {
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- var renderer = RDGE.globals.engine.getContext().renderer;
- if (renderer && technique) {
- var tex = renderer.getTextureByName(value, caps.specularMap.wrap);
- this.registerTexture( tex );
- technique.s_specularMap.set( tex );
- }
- }
- }
- }
- };
+ this.updateDiffuseMap = function (value) {
+ var value = this._propValues["diffuseMap"];
+ this._diffuseMapOb.texture = value;
- this.updateNormalMap = function(value) {
- var value = this._propValues[ "normalMap" ];
- this._normalMapOb.texture = value;
-
- if ((value == null) || (value.length == 0)) {
- if (this._useNormalMap) {
- this._useNormalMap = false;
- this.rebuildShader();
- }
- } else {
- if (!this._useNormalMap) {
- this._useNormalMap = true;
- this.rebuildShader();
- } else {
- var material = this._materialNode;
- if (material) {
- var technique = material.shaderProgram.defaultTechnique;
- var renderer = RDGE.globals.engine.getContext().renderer;
- if (renderer && technique) {
- var tex = renderer.getTextureByName(value, caps.normalMap.wrap);
- this.registerTexture( tex );
- technique.s_normalMap.set( tex );
- }
- }
- }
- }
- };
-
- // duplcate method requirde
- this.dup = function() {
- // allocate a new uber material
- var newMat = new UberMaterial();
-
- newMat._useDiffuseMap = this._useDiffuseMap;
- newMat._useEnvironmentMap = this._useEnvironmentMap;
- newMat._useLights = this._useLights;
- newMat._useNormalMap = this._useNormalMap;
- newMat._useSpecularMap = this._useSpecularMap;
- newMat.rebuildShader();
-
- // copy over the current values;
- var propNames = [], propValues = [], propTypes = [], propLabels = [];
- this.getAllProperties( propNames, propValues, propTypes, propLabels);
- var n = propNames.length;
- for (var i=0; i 0)
- {
- this._ubershaderCaps.lighting =
+ if (this._lights.length > 0) {
+ this._ubershaderCaps.lighting =
{
- 'light0' : this._lights[0],
- 'light1' : this._lights[1],
- 'light2' : this._lights[2],
- 'light3' : this._lights[3]
+ 'light0': this._lights[0],
+ 'light1': this._lights[1],
+ 'light2': this._lights[2],
+ 'light3': this._lights[3]
}
- }
- }
+ }
+ }
- var diffuseMap = pu.nextValue( "diffuseMap: " )
- if(diffuseMap) {
- this.setProperty( "diffuseMap", diffuseMap );
-}
+ var diffuseMap = pu.nextValue("diffuseMap: ")
+ if (diffuseMap) {
+ this.setProperty("diffuseMap", diffuseMap);
+ }
- var normalMap = pu.nextValue( "normalMap: " );
- if(normalMap) {
- this.setProperty( "normalMap", normalMap );
-}
+ var normalMap = pu.nextValue("normalMap: ");
+ if (normalMap) {
+ this.setProperty("normalMap", normalMap);
+ }
- var specularMap = pu.nextValue( "specularMap: " );
- if(specularMap) {
- this.setProperty( "specularMap", specularMap );
-}
+ var specularMap = pu.nextValue("specularMap: ");
+ if (specularMap) {
+ this.setProperty("specularMap", specularMap);
+ }
- var environmentMap = pu.nextValue( "environmentMap: " );
- if(environmentMap)
- {
- this.setProperty( "environmentMap", environmentMap );
- this.setProperty( "environmentAmount", Number( pu.nextValue( "environmentAmount" ) ) );
- }
+ var environmentMap = pu.nextValue("environmentMap: ");
+ if (environmentMap) {
+ this.setProperty("environmentMap", environmentMap);
+ this.setProperty("environmentAmount", Number(pu.nextValue("environmentAmount")));
+ }
- this.rebuildShader();
- };
+ this.rebuildShader();
+ };
- this.importJSON = function( jObj )
- {
- if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" );
- this.setName( jObj.name );
+ this.importJSON = function (jObj) {
+ if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
+ this.setName(jObj.name);
- if (jObj.materialProps)
- {
- var ambientColor = jObj.materialProps.ambientColor; this.setProperty( "ambientColor", ambientColor );
- var diffuseColor = jObj.materialProps.diffuseColor; this.setProperty( "diffuseColor", diffuseColor );
- var specularColor = jObj.materialProps.specularColor; this.setProperty( "specularColor", specularColor );
- var specularPower = jObj.materialProps.specularPower; this.setProperty( "specularPower", specularPower );
- }
+ if (jObj.materialProps) {
+ var ambientColor = jObj.materialProps.ambientColor; this.setProperty("ambientColor", ambientColor);
+ var diffuseColor = jObj.materialProps.diffuseColor; this.setProperty("diffuseColor", diffuseColor);
+ var specularColor = jObj.materialProps.specularColor; this.setProperty("specularColor", specularColor);
+ var specularPower = jObj.materialProps.specularPower; this.setProperty("specularPower", specularPower);
+ }
- var lightArray = jObj.lights;
- if (lightArray)
- {
- this._lights = [];
- for (var i=0; i 0)
- {
- this._ubershaderCaps.lighting =
+ if (this._lights.length > 0) {
+ this._ubershaderCaps.lighting =
{
- 'light0' : this._lights[0],
- 'light1' : this._lights[1],
- 'light2' : this._lights[2],
- 'light3' : this._lights[3]
+ 'light0': this._lights[0],
+ 'light1': this._lights[1],
+ 'light2': this._lights[2],
+ 'light3': this._lights[3]
}
- }
- }
+ }
+ }
- var diffuseMap = jObj['diffuseMap'];
- if(diffuseMap) {
- this.setProperty( "diffuseMap", diffuseMap );
-}
+ var diffuseMap = jObj['diffuseMap'];
+ if (diffuseMap) {
+ this.setProperty("diffuseMap", diffuseMap);
+ }
- var normalMap = jObj['normalMap'];
- if(normalMap) {
- this.setProperty( "normalMap", normalMap );
-}
+ var normalMap = jObj['normalMap'];
+ if (normalMap) {
+ this.setProperty("normalMap", normalMap);
+ }
- var specularMap = jObj['specularMap'];
- if(specularMap) {
- this.setProperty( "specularMap", specularMap );
-}
+ var specularMap = jObj['specularMap'];
+ if (specularMap) {
+ this.setProperty("specularMap", specularMap);
+ }
- var environmentMap = jObj['environmentMap'];
- if(environmentMap)
- {
- this.setProperty( "environmentMap", environmentMap );
- this.setProperty( "environmentAmount", jObj['environmentAmount'] );
- }
+ var environmentMap = jObj['environmentMap'];
+ if (environmentMap) {
+ this.setProperty("environmentMap", environmentMap);
+ this.setProperty("environmentAmount", jObj['environmentAmount']);
+ }
- this.rebuildShader();
- };
+ this.rebuildShader();
+ };
- this.exportJSON = function()
- {
- // every material needs the base type and instance name
- var caps = this._ubershaderCaps;
- var jObj =
+ this.exportJSON = function () {
+ // every material needs the base type and instance name
+ var caps = this._ubershaderCaps;
+ var jObj =
{
- 'material' : this.getShaderName(),
- 'name' : this.getName()
+ 'material': this.getShaderName(),
+ 'name': this.getName()
};
- // export the material properties
- if (typeof caps.material != 'undefined')
- {
- jObj.materialProps =
+ // export the material properties
+ if (typeof caps.material != 'undefined') {
+ jObj.materialProps =
{
- 'ambientColor' : this._ambientColor,
- 'diffuseColor' : this._diffuseColor,
- 'specularColor' : this._specularColor,
- 'specularPower' : this._specularPower
+ 'ambientColor': this._ambientColor,
+ 'diffuseColor': this._diffuseColor,
+ 'specularColor': this._specularColor,
+ 'specularPower': this._specularPower
};
-
- }
- if (typeof caps.lighting != 'undefined')
- {
- var lightArray = [];
- for (var i=0; i 0)
- jObj.lights = lightArray;
- }
+ if (typeof caps.lighting != 'undefined') {
+ var lightArray = [];
+ for (var i = 0; i < this._MAX_LIGHTS; i++) {
+ var light = caps.lighting["light" + i];
+ if (typeof light != "undefined") {
+ var lightObj = {}
+ lightObj['light' + i] = light.type;
+
+ // output the light secific data
+ if (light.type === 'directional') {
+ lightObj['light' + i + 'Dir'] = light['direction'];
+ }
+ else if (light.type === 'spot') {
+ lightObj['light' + i + 'Pos'] = light['position'];
+ lightObj['light' + i + 'SpotInnerCutoff'] = light['spotInnerCutoff'];
+ lightObj['light' + i + 'SpotOuterCutoff'] = light['spotOuterCutoff'];
+ }
+ else // light.type === 'point'
+ {
+ lightObj['light' + i + 'Pos'] = (light['position'] || [0, 0, 0]);
+ lightObj['light' + i + 'Attenuation'] = (light['attenuation'] || [1, 0, 0]);
+ }
+
+ // common to all lights
+ lightObj['light' + i + 'Color'] = (light['diffuseColor'] || [1, 1, 1, 1]);
+ lightObj['light' + i + 'SpecularColor'] = (light['specularColor'] || [1, 1, 1, 1]);
+
+ lightArray.push(lightObj);
+ }
+ }
- if(typeof caps.diffuseMap != 'undefined') {
- jObj['diffuseMap'] = caps.diffuseMap.texture;
-}
+ if (lightArray.length > 0)
+ jObj.lights = lightArray;
+ }
- if(typeof caps.normalMap != 'undefined') {
- jObj['normalMap'] = caps.normalMap.texture;
-}
+ if (typeof caps.diffuseMap != 'undefined') {
+ jObj['diffuseMap'] = caps.diffuseMap.texture;
+ }
- if(typeof caps.specularMap != 'undefined') {
- jObj['specularMap'] = caps.specularMap.texture;
-}
+ if (typeof caps.normalMap != 'undefined') {
+ jObj['normalMap'] = caps.normalMap.texture;
+ }
- if(typeof caps.environmentMap != 'undefined')
- {
- jObj['environmentMap'] = caps.environmentMap.texture;
- jObj['environmentAmount'] = caps.environmentMap.envReflection;
- }
+ if (typeof caps.specularMap != 'undefined') {
+ jObj['specularMap'] = caps.specularMap.texture;
+ }
- return jObj;
- };
+ if (typeof caps.environmentMap != 'undefined') {
+ jObj['environmentMap'] = caps.environmentMap.texture;
+ jObj['environmentAmount'] = caps.environmentMap.envReflection;
+ }
+ return jObj;
+ };
- this.export = function()
- {
- // every material needs the base type and instance name
- var exportStr = "material: " + this.getShaderName() + "\n";
- exportStr += "name: " + this.getName() + "\n";
-
- var caps = this._ubershaderCaps;
-
- // export the material properties
- if (typeof caps.material != 'undefined')
- {
- exportStr += "materialProps: true\n";
- exportStr += "ambientColor: " + this._ambientColor + "\n";
- exportStr += "diffuseColor: " + this._diffuseColor + "\n";
- exportStr += "specularColor: " + this._specularColor + "\n";
- exportStr += "specularPower: " + this._specularPower + "\n";
- }
- if (typeof caps.lighting != 'undefined')
- {
- exportStr += "lightProps: true\n";
+ this.export = function () {
+ // every material needs the base type and instance name
+ var exportStr = "material: " + this.getShaderName() + "\n";
+ exportStr += "name: " + this.getName() + "\n";
- var light = caps.lighting['light' + i];
- for (var i=0; i