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.js306
1 files changed, 162 insertions, 144 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js
index 416cb980..3cf950f5 100755
--- a/js/lib/rdge/materials/uber-material.js
+++ b/js/lib/rdge/materials/uber-material.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -45,11 +46,11 @@ var UberMaterial = function UberMaterial() {
45 this._diffuseColor = [1.0, 1.0, 1.0, 1.0]; 46 this._diffuseColor = [1.0, 1.0, 1.0, 1.0];
46 this._specularColor = [1.0, 1.0, 1.0, 1.0]; 47 this._specularColor = [1.0, 1.0, 1.0, 1.0];
47 this._specularPower = 32.0; 48 this._specularPower = 32.0;
48 this._environmentAmount = 0.2; // 0 .. 1 49 this._environmentAmount = 0.2; // 0 .. 1
49 50
50 // set the default maps 51 // set the default maps
51 this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; 52 this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' };
52 //this._diffuseMapOb = { 'texture' : 'texture', 'wrap' : 'REPEAT' }; 53 //this._diffuseMapOb = { 'texture' : 'texture', 'wrap' : 'REPEAT' };
53 this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' }; 54 this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' };
54 this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' }; 55 this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' };
55 this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount }; 56 this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount };
@@ -86,6 +87,23 @@ var UberMaterial = function UberMaterial() {
86 this._propValues[this._propNames[7]] = this._environmentMapOb['texture']; 87 this._propValues[this._propNames[7]] = this._environmentMapOb['texture'];
87 this._propValues[this._propNames[8]] = this._environmentMapOb['envReflection']; 88 this._propValues[this._propNames[8]] = this._environmentMapOb['envReflection'];
88 89
90 this.resetToDefault = function()
91 {
92 this._propValues[this._propNames[0]] = this._ambientColor.slice(0);
93 this._propValues[this._propNames[1]] = this._diffuseColor.slice(0);
94 this._propValues[this._propNames[2]] = this._specularColor.slice(0);
95 this._propValues[this._propNames[3]] = this._specularPower;
96 this._propValues[this._propNames[4]] = this._diffuseMapOb['texture'];
97 this._propValues[this._propNames[5]] = this._normalMapOb['texture'];
98 this._propValues[this._propNames[6]] = this._specularMapOb['texture'];
99 this._propValues[this._propNames[7]] = this._environmentMapOb['texture'];
100 this._propValues[this._propNames[8]] = this._environmentMapOb['envReflection'];
101
102 var nProps = this._propNames.length;
103 for (var i=0; i<nProps; i++)
104 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
105 };
106
89 this.setProperty = function (prop, value) { 107 this.setProperty = function (prop, value) {
90 if (prop == "color") prop = "ambientColor"; 108 if (prop == "color") prop = "ambientColor";
91 var valid = this.validateProperty(prop, value); 109 var valid = this.validateProperty(prop, value);
@@ -140,86 +158,86 @@ var UberMaterial = function UberMaterial() {
140 // define the 4 lights 158 // define the 4 lights
141 this._lights = [ 159 this._lights = [
142 160
143 { 161 {
144 'type': 'point', // can be 'directional', 'point' or 'spot' 162 'type': 'point', // can be 'directional', 'point' or 'spot'
145 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity. 163 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity.
146 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit. 164 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit.
147 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights 165 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights
148 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights 166 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights
149 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic 167 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic
150 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color 168 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color
151 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color 169 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color
152 }, 170 },
153 { 171 {
154 'type': 'point', 172 'type': 'point',
155 'spotInnerCutoff': 9.0, 173 'spotInnerCutoff': 9.0,
156 'spotOuterCutoff': 20.0, 174 'spotOuterCutoff': 20.0,
157 'position': [-8.0, 2.0, 8.0], 175 'position': [-8.0, 2.0, 8.0],
158 'direction': [1.0, -1.0, -1.0], 176 'direction': [1.0, -1.0, -1.0],
159 'attenuation': [1.0, 0.025, 0.00125], 177 'attenuation': [1.0, 0.025, 0.00125],
160 'diffuseColor': [0.5, 1.0, 0.5, 1.0], 178 'diffuseColor': [0.5, 1.0, 0.5, 1.0],
161 'specularColor': [1.0, 1.0, 1.0, 1.0] 179 'specularColor': [1.0, 1.0, 1.0, 1.0]
162 }, 180 },
163 { 181 {
164 'type': 'point', 182 'type': 'point',
165 'spotInnerCutoff': 9.0, 183 'spotInnerCutoff': 9.0,
166 'spotOuterCutoff': 20.0, 184 'spotOuterCutoff': 20.0,
167 'position': [-8.0, 2.0, -8.0], 185 'position': [-8.0, 2.0, -8.0],
168 'direction': [1.0, -1.0, 1.0], 186 'direction': [1.0, -1.0, 1.0],
169 'attenuation': [1.0, 0.25, 0.0125], 187 'attenuation': [1.0, 0.25, 0.0125],
170 'diffuseColor': [0.5, 0.5, 1.0, 1.0], 188 'diffuseColor': [0.5, 0.5, 1.0, 1.0],
171 'specularColor': [1.0, 1.0, 1.0, 1.0] 189 'specularColor': [1.0, 1.0, 1.0, 1.0]
172 }, 190 },
173 { 191 {
174 'type': 'point', 192 'type': 'point',
175 'spotInnerCutoff': 9.0, 193 'spotInnerCutoff': 9.0,
176 'spotOuterCutoff': 20.0, 194 'spotOuterCutoff': 20.0,
177 'position': [8.0, 4.0, -8.0], 195 'position': [8.0, 4.0, -8.0],
178 'direction': [-1.0, -1.0, 1.0], 196 'direction': [-1.0, -1.0, 1.0],
179 'attenuation': [1.0, 0.25, 0.0125], 197 'attenuation': [1.0, 0.25, 0.0125],
180 'diffuseColor': [1.0, 1.0, 0.5, 1.0], 198 'diffuseColor': [1.0, 1.0, 0.5, 1.0],
181 'specularColor': [1.0, 1.0, 1.0, 1.0] 199 'specularColor': [1.0, 1.0, 1.0, 1.0]
182 } 200 }
183 ]; 201 ];
184 202
185 this._ubershaderCaps = 203 this._ubershaderCaps =
186 { 204 {
187 // ubershader material properties. 205 // ubershader material properties.
188 'material': { 206 'material': {
189 'ambientColor': this._ambientColor, // material ambient color 207 'ambientColor': this._ambientColor, // material ambient color
190 'diffuseColor': this._diffuseColor, // material diffuse color 208 'diffuseColor': this._diffuseColor, // material diffuse color
191 'specularColor': this._specularColor, // material specular color 209 'specularColor': this._specularColor, // material specular color
192 'specularPower': this._specularPower // material specular power (shininess) 210 'specularPower': this._specularPower // material specular power (shininess)
193 }, 211 },
194 212
195 // ubershader supports up to four lights. 213 // ubershader supports up to four lights.
196 'lighting': { 214 'lighting': {
197 'light0': this._lights[0], 215 'light0': this._lights[0],
198 'light1': this._lights[1], 216 'light1': this._lights[1],
199 'light2': this._lights[2], 217 'light2': this._lights[2],
200 'light3': this._lights[3] 218 'light3': this._lights[3]
201 }, 219 },
202 220
203 // uvTransform can be used to scale or offset the texture coordinates. 221 // uvTransform can be used to scale or offset the texture coordinates.
204 'uvTransform': [2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1], 222 'uvTransform': [2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1],
205 223
206 // optional diffuse map 224 // optional diffuse map
207 'diffuseMap': this._diffuseMapOb, 225 'diffuseMap': this._diffuseMapOb,
208 226
209 // optional normal map 227 // optional normal map
210 'normalMap': this._normalMapOb, 228 'normalMap': this._normalMapOb,
211 229
212 // optional specular map 230 // optional specular map
213 'specularMap': this._specularMapOb, 231 'specularMap': this._specularMapOb,
214 232
215 // optional environment map 233 // optional environment map
216 'environmentMap': this._environmentMapOb 234 'environmentMap': this._environmentMapOb
217 }; 235 };
218 236
219 this.updateAmbientColor = function () {