diff options
Diffstat (limited to 'js/lib/rdge/materials/uber-material.js')
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 266 |
1 files changed, 133 insertions, 133 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index d242f8f5..7c7dced4 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js | |||
@@ -45,11 +45,11 @@ var UberMaterial = function UberMaterial() { | |||
45 | this._diffuseColor = [1.0, 1.0, 1.0, 1.0]; | 45 | this._diffuseColor = [1.0, 1.0, 1.0, 1.0]; |
46 | this._specularColor = [1.0, 1.0, 1.0, 1.0]; | 46 | this._specularColor = [1.0, 1.0, 1.0, 1.0]; |
47 | this._specularPower = 32.0; | 47 | this._specularPower = 32.0; |
48 | this._environmentAmount = 0.2; // 0 .. 1 | 48 | this._environmentAmount = 0.2; // 0 .. 1 |
49 | 49 | ||
50 | // set the default maps | 50 | // set the default maps |
51 | this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; | 51 | this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; |
52 | //this._diffuseMapOb = { 'texture' : 'texture', 'wrap' : 'REPEAT' }; | 52 | //this._diffuseMapOb = { 'texture' : 'texture', 'wrap' : 'REPEAT' }; |
53 | this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' }; | 53 | this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' }; |
54 | this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' }; | 54 | this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' }; |
55 | this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount }; | 55 | this._environmentMapOb = { 'texture': 'assets/images/silver.png', 'wrap': 'CLAMP', 'envReflection': this._environmentAmount }; |
@@ -157,86 +157,86 @@ var UberMaterial = function UberMaterial() { | |||
157 | // define the 4 lights | 157 | // define the 4 lights |
158 | this._lights = [ | 158 | this._lights = [ |
159 | 159 | ||
160 | { | 160 | { |
161 | 'type': 'point', // can be 'directional', 'point' or 'spot' | 161 | 'type': 'point', // can be 'directional', 'point' or 'spot' |
162 | 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity. | 162 | 'spotInnerCutoff': 14.0, // fragments in the inner cutoff 'cone' are full intensity. |
163 | 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit. | 163 | 'spotOuterCutoff': 15.0, // fragments outside the outer cutoff 'cone' are unlit. |
164 | 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights | 164 | 'position': [8.0, 2.0, 8.0], // light position; ignored for directional lights |
165 | 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights | 165 | 'direction': [-1.0, -1.0, -1.0], // light direction; ignored for point lights |
166 | 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic | 166 | 'attenuation': [1.0, 0.025, 0.00125], // light attenuation; constant, linear, quadratic |
167 | 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color | 167 | 'diffuseColor': [1.0, 0.5, 0.5, 1.0], // diffuse light color |
168 | 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color | 168 | 'specularColor': [1.0, 1.0, 1.0, 1.0] // specular light color |
169 | }, | 169 | }, |
170 | { | 170 | { |
171 | 'type': 'point', | 171 | 'type': 'point', |
172 | 'spotInnerCutoff': 9.0, | 172 | 'spotInnerCutoff': 9.0, |
173 | 'spotOuterCutoff': 20.0, | 173 | 'spotOuterCutoff': 20.0, |
174 | 'position': [-8.0, 2.0, 8.0], | 174 | 'position': [-8.0, 2.0, 8.0], |
175 | 'direction': [1.0, -1.0, -1.0], | 175 | 'direction': [1.0, -1.0, -1.0], |
176 | 'attenuation': [1.0, 0.025, 0.00125], | 176 | 'attenuation': [1.0, 0.025, 0.00125], |
177 | 'diffuseColor': [0.5, 1.0, 0.5, 1.0], | 177 | 'diffuseColor': [0.5, 1.0, 0.5, 1.0], |
178 | 'specularColor': [1.0, 1.0, 1.0, 1.0] | 178 | 'specularColor': [1.0, 1.0, 1.0, 1.0] |
179 | }, | 179 | }, |
180 | { | 180 | { |
181 | 'type': 'point', | 181 | 'type': 'point', |
182 | 'spotInnerCutoff': 9.0, | 182 | 'spotInnerCutoff': 9.0, |
183 | 'spotOuterCutoff': 20.0, | 183 | 'spotOuterCutoff': 20.0, |
184 | 'position': [-8.0, 2.0, -8.0], | 184 | 'position': [-8.0, 2.0, -8.0], |
185 | 'direction': [1.0, -1.0, 1.0], | 185 | 'direction': [1.0, -1.0, 1.0], |
186 | 'attenuation': [1.0, 0.25, 0.0125], | 186 | 'attenuation': [1.0, 0.25, 0.0125], |
187 | 'diffuseColor': [0.5, 0.5, 1.0, 1.0], | 187 | 'diffuseColor': [0.5, 0.5, 1.0, 1.0], |
188 | 'specularColor': [1.0, 1.0, 1.0, 1.0] | 188 | 'specularColor': [1.0, 1.0, 1.0, 1.0] |
189 | }, | 189 | }, |
190 | { | 190 | { |
191 | 'type': 'point', | 191 | 'type': 'point', |
192 | 'spotInnerCutoff': 9.0, | 192 | 'spotInnerCutoff': 9.0, |
193 | 'spotOuterCutoff': 20.0, | 193 | 'spotOuterCutoff': 20.0, |
194 | 'position': [8.0, 4.0, -8.0], | 194 | 'position': [8.0, 4.0, -8.0], |
195 | 'direction': [-1.0, -1.0, 1.0], | 195 | 'direction': [-1.0, -1.0, 1.0], |
196 | 'attenuation': [1.0, 0.25, 0.0125], | 196 | 'attenuation': [1.0, 0.25, 0.0125], |
197 | 'diffuseColor': [1.0, 1.0, 0.5, 1.0], | 197 | 'diffuseColor': [1.0, 1.0, 0.5, 1.0], |
198 | 'specularColor': [1.0, 1.0, 1.0, 1.0] | 198 | 'specularColor': [1.0, 1.0, 1.0, 1.0] |
199 | } | 199 | } |
200 | ]; | 200 | ]; |
201 | 201 | ||
202 | this._ubershaderCaps = | 202 | this._ubershaderCaps = |
203 | { | 203 | { |
204 | // ubershader material properties. | 204 | // ubershader material properties. |
205 | 'material': { | 205 | 'material': { |
206 | 'ambientColor': this._ambientColor, // material ambient color | 206 | 'ambientColor': this._ambientColor, // material ambient color |
207 | 'diffuseColor': this._diffuseColor, // material diffuse color | 207 | 'diffuseColor': this._diffuseColor, // material diffuse color |
208 | 'specularColor': this._specularColor, // material specular color | 208 | 'specularColor': this._specularColor, // material specular color |
209 | 'specularPower': this._specularPower // material specular power (shininess) | 209 | 'specularPower': this._specularPower // material specular power (shininess) |
210 | }, | 210 | }, |
211 | 211 | ||
212 | // ubershader supports up to four lights. | 212 | // ubershader supports up to four lights. |
213 | 'lighting': { | 213 | 'lighting': { |
214 | 'light0': this._lights[0], | 214 | 'light0': this._lights[0], |
215 | 'light1': this._lights[1], | 215 | 'light1': this._lights[1], |
216 | 'light2': this._lights[2], | 216 | 'light2': this._lights[2], |
217 | 'light3': this._lights[3] | 217 | 'light3': this._lights[3] |
218 | }, | 218 | }, |
219 | 219 | ||
220 | // uvTransform can be used to scale or offset the texture coordinates. | 220 | // uvTransform can be used to scale or offset the texture coordinates. |
221 | 'uvTransform': [2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1], | 221 | 'uvTransform': [2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1], |
222 | 222 | ||
223 | // optional diffuse map | 223 | // optional diffuse map |
224 | 'diffuseMap': this._diffuseMapOb, | 224 | 'diffuseMap': this._diffuseMapOb, |
225 | 225 | ||
226 | // optional normal map | 226 | // optional normal map |
227 | 'normalMap': this._normalMapOb, | 227 | 'normalMap': this._normalMapOb, |
228 | 228 | ||
229 | // optional specular map | 229 | // optional specular map |
230 | 'specularMap': this._specularMapOb, | 230 | 'specularMap': this._specularMapOb, |
231 | 231 | ||
232 | // optional environment map | 232 | // optional environment map |
233 | 'environmentMap': this._environmentMapOb | 233 | 'environmentMap': this._environmentMapOb |
234 | }; | 234 | }; |
235 | 235 | ||
236 | this.updateAmbientColor = function () { | 236 | this.updateAmbientColor = function () { |
237 | this._ambientColor = this._propValues['ambientColor'].slice(0); | 237 | this._ambientColor = this._propValues['ambientColor'].slice(0); |
238 | var material = this._materialNode; | 238 | var material = this._materialNode; |
239 | //console.log( "ambient color: " + this._ambientColor ); | 239 | //console.log( "ambient color: " + this._ambientColor ); |
240 | if (material) { | 240 | if (material) { |
241 | var technique = material.shaderProgram.defaultTechnique; | 241 | var technique = material.shaderProgram.defaultTechnique; |
242 | technique.u_ambientColor.set(this._ambientColor); | 242 | technique.u_ambientColor.set(this._ambientColor); |
@@ -312,34 +312,34 @@ var UberMaterial = function UberMaterial() { | |||
312 | } | 312 | } |
313 | }; | 313 | }; |
314 | 314 | ||
315 | this.updateDiffuseMap = function(value) { | 315 | this.updateDiffuseMap = function(value) { |
316 | var value = this._propValues[ "diffuseMap" ]; | 316 | var value = this._propValues[ "diffuseMap" ]; |
317 | this._diffuseMapOb.texture = value; | 317 | this._diffuseMapOb.texture = value; |
318 | 318 | ||
319 | if ((value == null) || (value.length == 0)) { | 319 | if ((value == null) || (value.length == 0)) { |
320 | if (this._useDiffuseMap) { | 320 | if (this._useDiffuseMap) { |
321 | this._useDiffuseMap = false; | 321 | this._useDiffuseMap = false; |
322 | this._diffuseTexture = undefined; | 322 | this._diffuseTexture = undefined; |
323 | this.rebuildShader(); | 323 | this.rebuildShader(); |
324 | } | 324 | } |
325 | } else { | 325 | } else { |
326 | if (!this._useDiffuseMap) { | 326 | if (!this._useDiffuseMap) { |
327 | this._useDiffuseMap = true; | 327 | this._useDiffuseMap = true; |
328 | this.rebuildShader(); | 328 | this.rebuildShader(); |
329 | } else { | 329 | } else { |
330 | var material = this._materialNode; | 330 | var material = this._materialNode; |
331 | if (material) { | 331 | if (material) { |
332 | var technique = material.shaderProgram.defaultTechnique; | 332 | var technique = material.shaderProgram.defaultTechnique; |
333 | var renderer = RDGE.globals.engine.getContext().renderer; | 333 | var renderer = RDGE.globals.engine.getContext().renderer; |
334 | if (renderer && technique) { | 334 | if (renderer && technique) { |
335 | this._diffuseTexture = new Texture( this.getWorld(), value, this._ubershaderCaps.diffuseMap.wrap ); | 335 | this._diffuseTexture = new Texture( this.getWorld(), value, this._ubershaderCaps.diffuseMap.wrap ); |
336 | var tex = this._diffuseTexture.getTexture(); | 336 | var tex = this._diffuseTexture.getTexture(); |
337 | technique.s_diffuseMap.set( tex ); | 337 | technique.s_diffuseMap.set( tex ); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | } | 340 | } |
341 | } | 341 | } |
342 | }; | 342 | }; |
343 | 343 | ||
344 | this.updateSpecularMap = function () { | 344 | this.updateSpecularMap = function () { |
345 | var value = this._propValues["specularMap"]; | 345 | var value = this._propValues["specularMap"]; |
@@ -403,7 +403,7 @@ var UberMaterial = function UberMaterial() { | |||
403 | // get the current values; | 403 | // get the current values; |
< |