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.js1560
1 files changed, 674 insertions, 886 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js
index c1d1913c..e94458cc 100755
--- a/js/lib/rdge/materials/uber-material.js
+++ b/js/lib/rdge/materials/uber-material.js
@@ -1,8 +1,8 @@
1/* <copyright> 1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> 3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
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;
@@ -11,973 +11,761 @@ var UberMaterial = function UberMaterial() {
11 /////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////
12 // Instance variables 12 // Instance variables
13 /////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////
14 this._name = "UberMaterial"; 14 this._name = "UberMaterial";
15 this._shaderName = "uber"; 15 this._shaderName = "uber";
16 this.getShaderName = function() { return this._shaderName; }; 16 this.getShaderName = function () { return this._shaderName; };
17 17
18 // set some default values 18 // set some default values
19 this._ambientColor = [ 0.0, 0.0, 0.0, 1.0 ]; 19 this._ambientColor = [0.0, 0.0, 0.0, 1.0];
20 this._diffuseColor = [ 1.0, 1.0, 1.0, 1.0 ]; 20 this._diffuseColor = [1.0, 1.0, 1.0, 1.0];
21 this._specularColor = [ 1.0, 1.0, 1.0, 1.0 ]; 21 this._specularColor = [1.0, 1.0, 1.0, 1.0];
22 this._specularPower = 32.0; 22 this._specularPower = 32.0;
23 this._environmentAmount = 0.2; // 0 .. 1 23 this._environmentAmount = 0.2; // 0 .. 1
24 24
25 // set the default maps 25 // set the default maps
26 this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; 26 this._diffuseMapOb = { 'texture': 'assets/images/rocky-diffuse.jpg', 'wrap': 'REPEAT' };
27 this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' }; 27 this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' };
28 this._specularMapOb = { 'texture' : 'assets/images/rocky-spec.jpg', 'wrap' : 'REPEAT' }; 28 this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' };
29 this._environmentMapOb = { 'texture' : 'assets/images/silver.png', 'wrap' : 'CLAMP', 'envReflection' : this._environmentAmount }; 29 this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount };
30 30
31 this._useDiffuseMap = true; 31 this._useDiffuseMap = true;
32 this._useNormalMap = true; 32 this._useNormalMap = true;
33 this._useSpecularMap = true; 33 this._useSpecularMap = true;
34 this._useEnvironmentMap = true; 34 this._useEnvironmentMap = true;
35 this._useLights = [true, true, true, true]; 35 this._useLights = [true, true, true, true];
36 36
37 this._MAX_LIGHTS = 4; 37 this._MAX_LIGHTS = 4;
38 38
39 /////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////
40 // Material Property Accessors 40 // Material Property Accessors
41 /////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////
42 this._propNames = ["ambientColor", "diffuseColor", "specularColor", "specularPower" , "diffuseMap", "normalMap", "specularMap", "environmentMap", "environmentAmount" ]; 42 this._propNames = ["ambientColor", "diffuseColor", "specularColor", "specularPower", "diffuseMap", "normalMap", "specularMap", "environmentMap", "environmentAmount"];
43 this._propLabels = ["Ambient Color", "Diffuse Color", "Specular Color", "Specular Power", "Texture Map", "Bump Map", "Specular Map", "Environment Map", "Environment Map Amount" ]; 43 this._propLabels = ["Ambient Color", "Diffuse Color", "Specular Color", "Specular Power", "Texture Map", "Bump Map", "Specular Map", "Environment Map", "Environment Map Amount"];
44 this._propTypes = ["color", "color", "color", "float", "file", "file", "file", "file", "float" ]; 44 this._propTypes = ["color", "color", "color", "float", "file", "file", "file", "file", "float"];
45 this._propValues = []; 45 this._propValues = [];
46 46
47 this._propValues[ this._propNames[0] ] = this._ambientColor.slice(0); 47 this._propValues[this._propNames[0]] = this._ambientColor.slice(0);
48 this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(0); 48 this._propValues[this._propNames[1]] = this._diffuseColor.slice(0);
49 this._propValues[ this._propNames[2] ] = this._specularColor.slice(0); 49 this._propValues[this._propNames[2]] = this._specularColor.slice(0);
50 this._propValues[ this._propNames[3] ] = this._specularPower; 50 this._propValues[this._propNames[3]] = this._specularPower;
51 this._propValues[ this._propNames[4] ] = this._diffuseMapOb['texture']; 51 this._propValues[this._propNames[4]] = this._diffuseMapOb['texture'];
52 this._propValues[ this._propNames[5] ] = this._normalMapOb['texture']; 52 this._propValues[this._propNames[5]] = this._normalMapOb['texture'];
53 this._propValues[ this._propNames[6] ] = this._specularMapOb['texture']; 53 this._propValues[this._propNames[6]] = this._specularMapOb['texture'];
54 this._propValues[ this._propNames[7] ] = this._environmentMapOb['texture']; 54 this._propValues[this._propNames[7]] = this._environmentMapOb['texture'];
55 this._propValues[ this._propNames[8] ] = this._environmentMapOb['envReflection']; 55 this._propValues[this._propNames[8]] = this._environmentMapOb['envReflection'];
56 56
57 this.setProperty = function( prop, value ) { 57 this.setProperty = function (prop, value) {
58 if (prop == "color") prop = "ambientColor"; 58 if (prop == "color") prop = "ambientColor";
59 var valid = this.validateProperty( prop, value ); 59 var valid = this.validateProperty(prop, value);
60 if (valid) { 60 if (valid) {
61 this._propValues[prop] = value; 61 this._propValues[prop] = value;
62 62
63 switch (prop) 63 switch (prop) {
64 { 64 case "diffuseMap":
65 case "diffuseMap": 65 this.updateDiffuseMap();
66 this.updateDiffuseMap(); 66 break;
67 break; 67 case "normalMap":
68 case "normalMap": 68 this.updateNormalMap();
69 this.updateNormalMap(); 69 break;
70 break; 70 case "specularMap":
71 case "specularMap": 71 this.updateSpecularMap();
72 this.updateSpecularMap(); 72 break;
73 break; 73 case "environmentMap":
74 case "environmentMap": 74 this.updateEnvironmentMap();
75 this.updateEnvironmentMap(); 75 break;
76 break; 76 case "environmentAmount":
77 case "environmentAmount": 77 this.updateEnvironmentAmount(value);
78 this.updateEnvironmentAmount( value ); 78 break;
79 break; 79 case "specularPower":
80 case "specularPower": 80 this.updateSpecularPower(value);
81 this.updateSpecularPower( value ); 81 break;
82 break; 82 case "ambientColor":
83 case "ambientColor": 83 this.updateAmbientColor(value);
84 this.updateAmbientColor( value ); 84 break;
85 break; 85 case "diffuseColor":
86 case "diffuseColor": 86 this.updateDiffuseColor(value);
87 this.updateDiffuseColor( value ); 87 break;
88 break; 88 case "specularColor":
89 case "specularColor": 89 this.updateSpecularColor(value);
90 this.updateSpecularColor( value ); 90 break;
91 break; 91 }
92 } 92 }
93 } 93 };
94 };
95 /////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////
96 95
97 // define the 4 lights 96 // define the 4 lights
98 this._lights = [ 97 this._lights = [
99 98
100 { 99 {
101 'type' : 'point', // can be 'directional', 'point' or 'spot' 100 'type': 'point', // can be 'directional', 'point' or 'spot'
102 'spotInnerCutoff' : 14.0, // fragments in the inner cutoff 'cone' are full intensity. 101 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity.
103 'spotOuterCutoff' : 15.0, // fragments outside the outer cutoff 'cone' are unlit. 102 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit.
104 'position' : [ 8.0, 2.0, 8.0 ], // light position; ignored for directional lights 103 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights
105 'direction' : [ -1.0, -1.0, -1.0 ], // light direction; ignored for point lights 104 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights
106 'attenuation' : [ 1.0, 0.025, 0.00125 ], // light attenuation; constant, linear, quadratic 105 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic
107 'diffuseColor' : [ 1.0, 0.5, 0.5, 1.0 ], // diffuse light color 106 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color
108 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ] // specular light color 107 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color
109 }, 108 },
110 { 109 {
111 'type' : 'point', 110 'type': 'point',
112 'spotInnerCutoff' : 9.0, 111 'spotInnerCutoff': 9.0,
113 'spotOuterCutoff' : 20.0, 112 'spotOuterCutoff': 20.0,
114 'position' : [ -8.0, 2.0, 8.0 ], 113 'position': [-8.0, 2.0, 8.0],
115 'direction' : [ 1.0, -1.0, -1.0 ], 114 'direction': [1.0, -1.0, -1.0],
116 'attenuation' : [ 1.0, 0.025, 0.00125 ], 115 'attenuation': [1.0, 0.025, 0.00125],
117 'diffuseColor' : [ 0.5, 1.0, 0.5, 1.0 ], 116 'diffuseColor': [0.5, 1.0, 0.5, 1.0],
118 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ] 117 'specularColor': [1.0, 1.0, 1.0, 1.0]
119 }, 118 },
120 { 119 {
121 'type' : 'point', 120 'type': 'point',
122 'spotInnerCutoff' : 9.0, 121 'spotInnerCutoff': 9.0,
123 'spotOuterCutoff' : 20.0, 122 'spotOuterCutoff': 20.0,
124 'position' : [ -8.0, 2.0, -8.0 ], 123 'position': [-8.0, 2.0, -8.0],
125 'direction' : [ 1.0, -1.0, 1.0 ], 124 'direction': [1.0, -1.0, 1.0],
126 'attenuation' : [ 1.0, 0.25, 0.0125 ], 125 'attenuation': [1.0, 0.25, 0.0125],
127 'diffuseColor'