diff options
Diffstat (limited to 'js/lib/rdge/materials')
25 files changed, 1585 insertions, 546 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 27d5793c..4d19c9c1 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js | |||
@@ -6,6 +6,8 @@ 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; | ||
10 | |||
9 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
10 | // Class GLMaterial | 12 | // Class GLMaterial |
11 | // RDGE representation of a material. | 13 | // RDGE representation of a material. |
@@ -18,10 +20,16 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
18 | this._shaderName = "bumpMetal"; | 20 | this._shaderName = "bumpMetal"; |
19 | 21 | ||
20 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; | 22 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; |
21 | this._diffuseTexture = "assets/images/metal.png"; | 23 | |
22 | this._specularTexture = "assets/images/silver.png"; | 24 | this._diffuseTexture = "assets/images/metal.png"; |
25 | this._specularTexture = "assets/images/silver.png"; | ||
23 | this._normalTexture = "assets/images/normalMap.png"; | 26 | this._normalTexture = "assets/images/normalMap.png"; |
24 | 27 | ||
28 | // keep the array of initialized textures | ||
29 | this._textures = []; | ||
30 | |||
31 | this._speed = 1.0; | ||
32 | |||
25 | /////////////////////////////////////////////////////////////////////// | 33 | /////////////////////////////////////////////////////////////////////// |
26 | // Property Accessors | 34 | // Property Accessors |
27 | /////////////////////////////////////////////////////////////////////// | 35 | /////////////////////////////////////////////////////////////////////// |
@@ -48,28 +56,27 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
48 | }; | 56 | }; |
49 | 57 | ||
50 | this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null }; | 58 | this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null }; |
51 | this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.updateTexture(1); }; | 59 | this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.initTexture(1); }; |
52 | 60 | ||
53 | this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null }; | 61 | this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null }; |
54 | this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.updateTexture(2); }; | 62 | this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.initTexture(2); }; |
55 | 63 | ||
56 | this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null }; | 64 | this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null }; |
57 | this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.updateTexture(3); }; | 65 | this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.initTexture(3); }; |
58 | 66 | ||
59 | this.isAnimated = function() { return true; }; | 67 | this.isAnimated = function() { return true; }; |
60 | 68 | ||
61 | /////////////////////////////////////////////////////////////////////// | 69 | /////////////////////////////////////////////////////////////////////// |
62 | // Material Property Accessors | 70 | // Material Property Accessors |
63 | /////////////////////////////////////////////////////////////////////// | 71 | /////////////////////////////////////////////////////////////////////// |
64 | this._propNames = ["lightDiff", "diffuseTexture", "normalMap", "specularTexture"]; | 72 | this._propNames = ["lightDiff", "diffuseTexture", "normalMap" ]; |
65 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map"]; | 73 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map" ]; |
66 | this._propTypes = ["color", "file", "file", "file"]; | 74 | this._propTypes = ["color", "file", "file" ]; |
67 | this._propValues = []; | 75 | this._propValues = []; |
68 | 76 | ||
69 | this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); | 77 | this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); |
70 | this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); | 78 | this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); |
71 | this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); | 79 | this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); |
72 | this._propValues[ this._propNames[3] ] = this._specularTexture.slice(0); | ||
73 | 80 | ||
74 | // TODO - shader techniques are not all named the same, i.e., FlatMaterial uses "colorMe" and BrickMaterial uses "default" | 81 | // TODO - shader techniques are not all named the same, i.e., FlatMaterial uses "colorMe" and BrickMaterial uses "default" |
75 | this.setProperty = function( prop, value ) | 82 | this.setProperty = function( prop, value ) |
@@ -108,8 +115,8 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
108 | { | 115 | { |
109 | // save the world | 116 | // save the world |
110 | if (world) { | 117 | if (world) { |
111 | this.setWorld( world ); | 118 | this.setWorld( world ); |
112 | } | 119 | } |
113 | 120 | ||
114 | // set up the shader | 121 | // set up the shader |
115 | this._shader = new RDGE.jshader(); | 122 | this._shader = new RDGE.jshader(); |
@@ -121,12 +128,40 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
121 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); | 128 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); |
122 | this._materialNode.setShader(this._shader); | 129 | this._materialNode.setShader(this._shader); |
123 | 130 | ||
124 | // set some image maps | 131 | this.initTextures(); |
125 | this.updateTexture(1); | ||
126 | this.updateTexture(2); | ||
127 | this.updateTexture(3); | ||
128 | }; | 132 | }; |
129 | 133 | ||
134 | this.initTexture = function( index ) | ||
135 | { | ||
136 | var dstWorld = this.getWorld(); | ||
137 | if (dstWorld) | ||
138 | { | ||
139 | var texMapName = this._propValues[this._propNames[index]]; | ||
140 | if (texMapName) | ||
141 | { | ||
142 | var texture = new Texture( dstWorld, texMapName ); | ||
143 | this._textures[index] = texture; | ||
144 | } | ||
145 | else | ||
146 | this._textures[index] = null; | ||
147 | |||
148 | this.updateTexture( index ); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | this.initTextures = function() | ||
153 | { | ||
154 | var dstWorld = this.getWorld(); | ||
155 | if (dstWorld) | ||
156 | { | ||
157 | // find the world with the given id | ||
158 | for (var i=1; i<=3; i++) | ||
159 | { | ||
160 | this.initTexture( i ); | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | |||
130 | this.updateTexture = function( index ) | 165 | this.updateTexture = function( index ) |
131 | { | 166 | { |
132 | var material = this._materialNode; | 167 | var material = this._materialNode; |
@@ -136,11 +171,16 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
136 | var renderer = RDGE.globals.engine.getContext().renderer; | 171 | var renderer = RDGE.globals.engine.getContext().renderer; |
137 | if (renderer && technique) | 172 | if (renderer && technique) |
138 | { | 173 | { |
139 | var texMapName = this._propValues[this._propNames[index]]; | 174 | var glTex = this._textures[ index ]; |
140 | var wrap = 'REPEAT', mips = true; | 175 | var tex; |
141 | var tex = this.loadTexture( texMapName, wrap, mips ); | 176 | if (glTex) |
177 | { | ||
178 | if (glTex.isAnimated()) | ||
179 | glTex.render(); | ||
180 | |||
181 | tex = glTex.getTexture(); | ||
182 | } | ||
142 | 183 | ||
143 | if (tex) | ||
144 | { | 184 | { |
145 | switch (index) | 185 | switch (index) |
146 | { | 186 | { |
@@ -258,7 +298,6 @@ var bumpMetalMaterialDef = bumpMetalShaderDef = | |||
258 | 'params' : | 298 | 'params' : |
259 | { | 299 | { |
260 | 'u_light0Diff' : { 'type' : 'vec4' }, | 300 | 'u_light0Diff' : { 'type' : 'vec4' }, |