diff options
Diffstat (limited to 'js/helper-classes/RDGE/Materials/UberMaterial.js')
-rwxr-xr-x | js/helper-classes/RDGE/Materials/UberMaterial.js | 744 |
1 files changed, 0 insertions, 744 deletions
diff --git a/js/helper-classes/RDGE/Materials/UberMaterial.js b/js/helper-classes/RDGE/Materials/UberMaterial.js deleted file mode 100755 index 1652b4c9..00000000 --- a/js/helper-classes/RDGE/Materials/UberMaterial.js +++ /dev/null | |||
@@ -1,744 +0,0 @@ | |||
1 | /* <copyright> | ||
2 | This 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/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | |||
8 | |||
9 | ///////////////////////////////////////////////////////////////////////// | ||
10 | //// Class UberMaterial | ||
11 | //// RDGE representation of a material. | ||
12 | ///////////////////////////////////////////////////////////////////////// | ||
13 | function UberMaterial() | ||
14 | { | ||
15 | // initialize the inherited members | ||
16 | this.inheritedFrom = GLMaterial; | ||
17 | this.inheritedFrom(); | ||
18 | |||
19 | /////////////////////////////////////////////////////////////////////// | ||
20 | // Instance variables | ||
21 | /////////////////////////////////////////////////////////////////////// | ||
22 | this._name = "UberMaterial"; | ||
23 | this._shaderName = "uber"; | ||
24 | this.getShaderName = function() { return this._shaderName; }; | ||
25 | |||
26 | // set some default values | ||
27 | this._ambientColor = [ 0.0, 0.0, 0.0, 1.0 ]; | ||
28 | this._diffuseColor = [ 1.0, 1.0, 1.0, 1.0 ]; | ||
29 | this._specularColor = [ 1.0, 1.0, 1.0, 1.0 ]; | ||
30 | this._specularPower = 32.0; | ||
31 | this._environmentAmount = 0.2; // 0 .. 1 | ||
32 | |||
33 | this._MAX_LIGHTS = 4; | ||
34 | |||
35 | // set the default maps | ||
36 | this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; | ||
37 | this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' }; | ||
38 | this._specularMapOb = { 'texture' : 'assets/images/rocky-spec.jpg', 'wrap' : 'REPEAT' }; | ||
39 | this._environmentMapOb = { 'texture' : 'assets/images/silver.png', 'wrap' : 'CLAMP', 'envReflection' : this._environmentAmount }; | ||
40 | |||
41 | this._useDiffuseMap = true; | ||
42 | this._useNormalMap = true; | ||
43 | this._useSpecularMap = true; | ||
44 | this._useEnvironmentMap = true; | ||
45 | this._useLights = [true, true, true, true]; | ||
46 | |||
47 | /////////////////////////////////////////////////////////////////////// | ||
48 | // Material Property Accessors | ||
49 | /////////////////////////////////////////////////////////////////////// | ||
50 | this._propNames = ["ambientColor", "diffuseColor", "specularColor", "specularPower" , "diffuseMap", "normalMap", "specularMap", "environmentMap", "environmentAmount" ]; | ||
51 | this._propLabels = ["Ambient Color", "Diffuse Color", "Specular Color", "Specular Power", "Texture Map", "Bump Map", "Specular Map", "Environment Map", "Environment Map Amount" ]; | ||
52 | this._propTypes = ["color", "color", "color", "float", "file", "file", "file", "file", "float" ]; | ||
53 | this._propValues = []; | ||
54 | |||
55 | this._propValues[ this._propNames[0] ] = this._ambientColor.slice(0); | ||
56 | this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(0); | ||
57 | this._propValues[ this._propNames[2] ] = this._specularColor.slice(0); | ||
58 | this._propValues[ this._propNames[3] ] = this._specularPower; | ||
59 | this._propValues[ this._propNames[4] ] = this._diffuseMapOb['texture']; | ||
60 | this._propValues[ this._propNames[5] ] = this._normalMapOb['texture']; | ||
61 | this._propValues[ this._propNames[6] ] = this._specularMapOb['texture']; | ||
62 | this._propValues[ this._propNames[7] ] = this._environmentMapOb['texture']; | ||
63 | this._propValues[ this._propNames[8] ] = this._environmentMapOb['envReflection']; | ||
64 | |||
65 | this.setProperty = function( prop, value ) | ||
66 | { | ||
67 | if (prop == "color") prop = "ambientColor"; | ||
68 | var valid = this.validateProperty( prop, value ); | ||
69 | if (valid) | ||
70 | { | ||
71 | this._propValues[prop] = value; | ||
72 | |||
73 | switch (prop) | ||
74 | { | ||
75 | case "diffuseMap": | ||
76 | this.updateDiffuseMap(); | ||
77 | break; | ||
78 | case "normalMap": | ||
79 | this.updateNormalMap(); | ||
80 | break; | ||
81 | case "specularMap": | ||
82 | this.updateSpecularMap(); | ||
83 | break; | ||
84 | case "environmentMap": | ||
85 | this.updateEnvironmentMap(); | ||
86 | break; | ||
87 | case "environmentAmount": | ||
88 | this.updateEnvironmentAmount( value ); | ||
89 | break; | ||
90 | case "specularPower": | ||
91 | this.updateSpecularPower( value ); | ||
92 | break; | ||
93 | case "ambientColor": | ||
94 | this.updateAmbientColor( value ); | ||
95 | break; | ||
96 | case "diffuseColor": | ||
97 | this.updateDiffuseColor( value ); | ||
98 | break; | ||
99 | case "specularColor": | ||
100 | this.updateSpecularColor( value ); | ||
101 | break; | ||
102 | } | ||
103 | } | ||
104 | }; | ||
105 | /////////////////////////////////////////////////////////////////////// | ||
106 | |||
107 | // define the 4 lights | ||
108 | this._lights = [ | ||
109 | |||
110 | { | ||
111 | 'type' : 'point', // can be 'directional', 'point' or 'spot' | ||
112 | 'spotInnerCutoff' : 14.0, // fragments in the inner cutoff 'cone' are full intensity. | ||
113 | 'spotOuterCutoff' : 15.0, // fragments outside the outer cutoff 'cone' are unlit. | ||
114 | 'position' : [ 8.0, 2.0, 8.0 ], // light position; ignored for directional lights | ||
115 | 'direction' : [ -1.0, -1.0, -1.0 ], // light direction; ignored for point lights | ||
116 | 'attenuation' : [ 1.0, 0.025, 0.00125 ], // light attenuation; constant, linear, quadratic | ||
117 | 'diffuseColor' : [ 1.0, 0.5, 0.5, 1.0 ], // diffuse light color | ||
118 | 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ] // specular light color | ||
119 | }, | ||
120 | { | ||
121 | 'type' : 'point', | ||
122 | 'spotInnerCutoff' : 9.0, | ||
123 | 'spotOuterCutoff' : 20.0, | ||
124 | 'position' : [ -8.0, 2.0, 8.0 ], | ||
125 | 'direction' : [ 1.0, -1.0, -1.0 ], | ||
126 | 'attenuation' : [ 1.0, 0.025, 0.00125 ], | ||
127 | 'diffuseColor' : [ 0.5, 1.0, 0.5, 1.0 ], | ||
128 | 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ] | ||
129 | }, | ||
130 | { | ||
131 | 'type' : 'point', | ||
132 | 'spotInnerCutoff' : 9.0, | ||
133 | 'spotOuterCutoff' : 20.0, | ||
134 | 'position' : [ -8.0, 2.0, -8.0 ], | ||
135 | 'direction' : [ 1.0, -1.0, 1.0 ], | ||
136 | 'attenuation' : [ 1.0, 0.25, 0.0125 ], | ||
137 | 'diffuseColor' : [ 0.5, 0.5, 1.0, 1.0 ], | ||
138 | 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ] | ||
139 | }, | ||
140 | { | ||
141 | 'type' : 'point', | ||
142 | 'spotInnerCutoff' : 9.0, | ||
143 | 'spotOuterCutoff' : 20.0, | ||
144 | 'position' : [ 8.0, 4.0, -8.0 ], | ||
145 | 'direction' : [ -1.0, -1.0, 1.0 ], | ||
146 | 'attenuation' : [ 1.0, 0.25, 0.0125 ], | ||
147 | 'diffuseColor' : [ 1.0, 1.0, 0.5, 1.0 ], | ||
148 | 'specularColor' : [ 1.0, 1.0, 1.0, 1.0 ] | ||
149 | } | ||
150 | ]; | ||
151 | |||
152 | this._ubershaderCaps = | ||
153 | { | ||
154 | // ubershader material properties. | ||
155 | 'material' : { | ||
156 | 'ambientColor' : this._ambientColor, // material ambient color | ||
157 | 'diffuseColor' : this._diffuseColor, // material diffuse color | ||
158 | 'specularColor' : this._specularColor, // material specular color | ||
159 | 'specularPower' : this._specularPower // material specular power (shininess) | ||
160 | }, | ||
161 | |||
162 | // ubershader supports up to four lights. | ||
163 | 'lighting' : { | ||
164 | 'light0' : this._lights[0], | ||
165 | 'light1' : this._lights[1], | ||
166 | 'light2' : this._lights[2], | ||
167 | 'light3' : this._lights[3] | ||
168 | }, | ||
169 | |||
170 | // uvTransform can be used to scale or offset the texture coordinates. | ||
171 | 'uvTransform' : [ 2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1], | ||
172 | |||
173 | // optional diffuse map | ||
174 | 'diffuseMap' : this._diffuseMapOb, | ||
175 | |||
176 | // optional normal map | ||
177 | 'normalMap' : this._normalMapOb, | ||
178 | |||
179 | // optional specular map | ||
180 | 'specularMap' : this._specularMapOb, | ||
181 | |||
182 | // optional environment map | ||
183 | 'environmentMap' : this._environmentMapOb | ||
184 | }; | ||
185 | |||
186 | this.updateAmbientColor = function() | ||
187 | { | ||
188 | this._ambientColor = this._propValues['ambientColor'].slice(0); | ||
189 | var material = this._materialNode; | ||
190 | if (material) | ||
191 | { | ||
192 | var technique = material.shaderProgram.defaultTechnique; | ||
193 | technique.u_ambientColor.set(this._ambientColor); | ||
194 | } | ||
195 | }; | ||
196 | |||
197 | this.updateDiffuseColor = function() | ||
198 | { | ||
199 | this._diffuseColor = this._propValues['diffuseColor'].slice(0); | ||
200 | |||
201 | var material = this._materialNode; | ||
202 | if (material) | ||
203 | { | ||
204 | var technique = material.shaderProgram.defaultTechnique; | ||
205 | technique.u_diffuseColor.set(this._diffuseColor); | ||
206 | } | ||
207 | }; | ||