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