diff options
author | hwc487 | 2012-05-22 08:38:38 -0700 |
---|---|---|
committer | hwc487 | 2012-05-22 08:38:38 -0700 |
commit | cc3b66f817c9d72ca247d5ff789a08ec5b57a2b5 (patch) | |
tree | 229a3d92b2fa86c32b6d47134b843880e909bead /js/lib/rdge | |
parent | dc92188fef67d7a2032173d7746fbc16a951a366 (diff) | |
download | ninja-cc3b66f817c9d72ca247d5ff789a08ec5b57a2b5.tar.gz |
Editable material properties
Diffstat (limited to 'js/lib/rdge')
-rwxr-xr-x | js/lib/rdge/materials/bump-metal-material.js | 58 | ||||
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 1 |
2 files changed, 33 insertions, 26 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 4bc5dfe8..4d19c9c1 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js | |||
@@ -28,6 +28,8 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
28 | // keep the array of initialized textures | 28 | // keep the array of initialized textures |
29 | this._textures = []; | 29 | this._textures = []; |
30 | 30 | ||
31 | this._speed = 1.0; | ||
32 | |||
31 | /////////////////////////////////////////////////////////////////////// | 33 | /////////////////////////////////////////////////////////////////////// |
32 | // Property Accessors | 34 | // Property Accessors |
33 | /////////////////////////////////////////////////////////////////////// | 35 | /////////////////////////////////////////////////////////////////////// |
@@ -67,15 +69,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
67 | /////////////////////////////////////////////////////////////////////// | 69 | /////////////////////////////////////////////////////////////////////// |
68 | // Material Property Accessors | 70 | // Material Property Accessors |
69 | /////////////////////////////////////////////////////////////////////// | 71 | /////////////////////////////////////////////////////////////////////// |
70 | this._propNames = ["lightDiff", "diffuseTexture", "normalMap", "specularTexture"]; | 72 | this._propNames = ["lightDiff", "diffuseTexture", "normalMap" ]; |
71 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map"]; | 73 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map" ]; |
72 | this._propTypes = ["color", "file", "file", "file"]; | 74 | this._propTypes = ["color", "file", "file" ]; |
73 | this._propValues = []; | 75 | this._propValues = []; |
74 | 76 | ||
75 | this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); | 77 | this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); |
76 | this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); | 78 | this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); |
77 | this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); | 79 | this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); |
78 | this._propValues[ this._propNames[3] ] = this._specularTexture.slice(0); | ||
79 | 80 | ||
80 | // 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" |
81 | this.setProperty = function( prop, value ) | 82 | this.setProperty = function( prop, value ) |
@@ -127,7 +128,6 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
127 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); | 128 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); |
128 | this._materialNode.setShader(this._shader); | 129 | this._materialNode.setShader(this._shader); |
129 | 130 | ||
130 | // DEBUG CODE | ||
131 | this.initTextures(); | 131 | this.initTextures(); |
132 | }; | 132 | }; |
133 | 133 | ||
@@ -137,8 +137,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
137 | if (dstWorld) | 137 | if (dstWorld) |
138 | { | 138 | { |
139 | var texMapName = this._propValues[this._propNames[index]]; | 139 | var texMapName = this._propValues[this._propNames[index]]; |
140 | var texture = new Texture( dstWorld, texMapName ); | 140 | if (texMapName) |
141 | this._textures[index] = texture; | 141 | { |
142 | var texture = new Texture( dstWorld, texMapName ); | ||
143 | this._textures[index] = texture; | ||
144 | } | ||
145 | else | ||
146 | this._textures[index] = null; | ||
147 | |||
142 | this.updateTexture( index ); | 148 | this.updateTexture( index ); |
143 | } | 149 | } |
144 | } | 150 | } |
@@ -165,24 +171,25 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
165 | var renderer = RDGE.globals.engine.getContext().renderer; | 171 | var renderer = RDGE.globals.engine.getContext().renderer; |
166 | if (renderer && technique) | 172 | if (renderer && technique) |
167 | { | 173 | { |
168 | var glTex = this._textures[ index ]; | 174 | var glTex = this._textures[ index ]; |
169 | if (glTex) | 175 | var tex; |
170 | { | 176 | if (glTex) |
171 | if (glTex.isAnimated()) | 177 | { |
172 | glTex.render(); | 178 | if (glTex.isAnimated()) |
173 | 179 | glTex.render(); | |
174 | var tex = glTex.getTexture(); | 180 | |
175 | if (tex) | 181 | tex = glTex.getTexture(); |
176 | { | 182 | } |
177 | switch (index) | 183 | |
178 | { | 184 | { |
179 | case 1: technique.u_colMap.set( tex ); break; | 185 | switch (index) |
180 | case 2: technique.u_normalMap.set( tex ); break; | 186 | { |
181 | case 3: technique.u_glowMap.set( tex ); break; | 187 | case 1: technique.u_colMap.set( tex ); break; |
182 | default: console.log( "invalid map index in BumpMetalMaterial, " + index ); | 188 | case 2: technique.u_normalMap.set( tex ); break; |
183 | } | 189 | case 3: technique.u_glowMap.set( tex ); break; |
184 | } | 190 | default: console.log( "invalid map index in BumpMetalMaterial, " + index ); |
185 | } | 191 | } |
192 | } | ||
186 | } | 193 | } |
187 | } | 194 | } |
188 | }; | 195 | }; |
@@ -291,7 +298,6 @@ var bumpMetalMaterialDef = bumpMetalShaderDef = | |||
291 | 'params' : | 298 | 'params' : |
292 | { | 299 | { |
293 | 'u_light0Diff' : { 'type' : 'vec4' }, | 300 | 'u_light0Diff' : { 'type' : 'vec4' }, |
294 | //'u_matDiffuse' : { 'type' : 'vec4' } | ||
295 | 'u_colMap': { 'type' : 'tex2d' }, | 301 | 'u_colMap': { 'type' : 'tex2d' }, |
296 | 'u_normalMap': { 'type' : 'tex2d' }, | 302 | 'u_normalMap': { 'type' : 'tex2d' }, |
297 | 'u_glowMap': { 'type' : 'tex2d' } | 303 | 'u_glowMap': { 'type' : 'tex2d' } |
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 9d0cc564..6de74495 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js | |||
@@ -180,6 +180,7 @@ var UberMaterial = function UberMaterial() { | |||
180 | this.updateAmbientColor = function () { | 180 | this.updateAmbientColor = function () { |
181 | this._ambientColor = this._propValues['ambientColor'].slice(0); | 181 | this._ambientColor = this._propValues['ambientColor'].slice(0); |
182 | var material = this._materialNode; | 182 | var material = this._materialNode; |
183 | console.log( "ambient color: " + this._ambientColor ); | ||
183 | if (material) { | 184 | if (material) { |
184 | var technique = material.shaderProgram.defaultTechnique; | 185 | var technique = material.shaderProgram.defaultTechnique; |
185 | technique.u_ambientColor.set(this._ambientColor); | 186 | technique.u_ambientColor.set(this._ambientColor); |