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