diff options
Diffstat (limited to 'js/lib/rdge/materials/uber-material.js')
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index e94458cc..d7bc2a87 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js | |||
@@ -6,6 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var Texture = require("js/lib/rdge/texture").Texture; | ||
9 | 10 | ||
10 | var UberMaterial = function UberMaterial() { | 11 | var UberMaterial = function UberMaterial() { |
11 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
@@ -23,7 +24,8 @@ var UberMaterial = function UberMaterial() { | |||
23 | this._environmentAmount = 0.2; // 0 .. 1 | 24 | this._environmentAmount = 0.2; // 0 .. 1 |
24 | 25 | ||
25 | // set the default maps | 26 | // set the default maps |
26 | 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' }; | ||
27 | this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' }; | 29 | this._normalMapOb = { 'texture': 'assets/images/rocky-normal.jpg', 'wrap': 'REPEAT' }; |
28 | this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' }; | 30 | this._specularMapOb = { 'texture': 'assets/images/rocky-spec.jpg', 'wrap': 'REPEAT' }; |
29 | 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 }; |
@@ -34,6 +36,9 @@ var UberMaterial = function UberMaterial() { | |||
34 | this._useEnvironmentMap = true; | 36 | this._useEnvironmentMap = true; |
35 | this._useLights = [true, true, true, true]; | 37 | this._useLights = [true, true, true, true]; |
36 | 38 | ||
39 | // these are the abstracted texture objects - defined where they are set | ||
40 | this._diffuseTexture; | ||
41 | |||
37 | this._MAX_LIGHTS = 4; | 42 | this._MAX_LIGHTS = 4; |
38 | 43 | ||
39 | /////////////////////////////////////////////////////////////////////// | 44 | /////////////////////////////////////////////////////////////////////// |
@@ -188,6 +193,7 @@ var UberMaterial = function UberMaterial() { | |||
188 | if (material) { | 193 | if (material) { |
189 | var technique = material.shaderProgram.defaultTechnique; | 194 | var technique = material.shaderProgram.defaultTechnique; |
190 | technique.u_diffuseColor.set(this._diffuseColor); | 195 | technique.u_diffuseColor.set(this._diffuseColor); |
196 | this.getWorld().restartRenderLoop(); | ||
191 | } | 197 | } |
192 | }; | 198 | }; |
193 | 199 | ||
@@ -256,6 +262,7 @@ var UberMaterial = function UberMaterial() { | |||
256 | if ((value == null) || (value.length == 0)) { | 262 | if ((value == null) || (value.length == 0)) { |
257 | if (this._useDiffuseMap) { | 263 | if (this._useDiffuseMap) { |
258 | this._useDiffuseMap = false; | 264 | this._useDiffuseMap = false; |
265 | this._diffuseTexture = undefined; | ||
259 | this.rebuildShader(); | 266 | this.rebuildShader(); |
260 | } | 267 | } |
261 | } else { | 268 | } else { |
@@ -277,6 +284,30 @@ var UberMaterial = function UberMaterial() { | |||
277 | } | 284 | } |
278 | }; | 285 | }; |
279 | 286 | ||
287 | |||
288 | this.updateTextures = function() | ||
289 | { | ||
290 | var material = this._materialNode; | ||
291 | if (material) | ||
292 | { | ||
293 | var technique = material.shaderProgram.defaultTechnique; | ||
294 | var renderer = RDGE_globals.engine.getContext().renderer; | ||
295 | if (renderer && technique) | ||
296 | { | ||
297 | if (this._diffuseTexture) | ||
298 | { | ||
299 | if (!this._diffuseTexture.isAnimated()) | ||
300 | { | ||
301 | this._diffuseTexture.render(); | ||
302 | var tex = this._diffuseTexture.getTexture(); | ||
303 | technique.s_diffuseMap.set( tex ); | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | |||
310 | |||
280 | this.updateSpecularMap = function () { | 311 | this.updateSpecularMap = function () { |
281 | var value = this._propValues["specularMap"]; | 312 | var value = this._propValues["specularMap"]; |
282 | this._specularMapOb.texture = value; | 313 | this._specularMapOb.texture = value; |
@@ -367,7 +398,32 @@ var UberMaterial = function UberMaterial() { | |||
367 | this._materialNode.setShader(this._shader); | 398 | this._materialNode.setShader(this._shader); |
368 | }; | 399 | }; |
369 | 400 | ||
370 | this.importJSON = function (jObj) { | 401 | this.update = function() |
402 | { | ||
403 | var material = this._materialNode; | ||
404 | if (material) | ||
405 | { | ||
406 | var technique = material.shaderProgram.defaultTechnique; | ||
407 | var renderer = g_Engine.getContext().renderer; | ||
408 | if (renderer && technique) | ||
409 | { | ||
410 | if (this._diffuseTexture && this._diffuseTexture.isAnimated()) | ||
411 | { | ||
412 | this._diffuseTexture.render(); | ||
413 | technique.s_diffuseMap.set( this._diffuseTexture.getTexture() ); | ||
414 | } | ||
415 | } | ||
416 | } | ||
417 | } | ||
418 | |||
419 | this.isAnimated = function() | ||
420 | { | ||
421 | var anim = (this._diffuseTexture && this._diffuseTexture.isAnimated()); | ||
422 | return anim; | ||
423 | } | ||
424 | |||
425 | this.importJSON = function (jObj) | ||
426 | { | ||
371 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); | 427 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); |
372 | this.setName(jObj.name); | 428 | this.setName(jObj.name); |
373 | 429 | ||