aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/material.js')
-rwxr-xr-xjs/lib/rdge/materials/material.js78
1 files changed, 6 insertions, 72 deletions
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index b96768b3..b9de9988 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -38,6 +38,11 @@ var Material = function GLMaterial( world ) {
38 this._shader = null; 38 this._shader = null;
39 this._materialNode = null; 39 this._materialNode = null;
40 40
41 // vertex deformation variables
42 this._hasVertexDeformation = false;
43 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
44 this._vertexDeformationTolerance = 0.02;
45
41 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
42 // Property Accessors 47 // Property Accessors
43 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
@@ -187,6 +192,7 @@ var Material = function GLMaterial( world ) {
187 rtnVal = ((valType == "object") && (value.length >= 3)); 192 rtnVal = ((valType == "object") && (value.length >= 3));
188 break; 193 break;
189 194
195 case "angle":
190 case "float": 196 case "float":
191 rtnVal = (valType == "number"); 197 rtnVal = (valType == "number");
192 break; 198 break;
@@ -256,78 +262,6 @@ var Material = function GLMaterial( world ) {
256 return tex; 262 return tex;
257 }; 263 };
258 264
259 /*
260 this.setRenderProperties = function( glContext, shaderProgram )
261 {
262 glContext.uniform1f( shaderProgram.materialShininessUniform, this._shininess );
263
264 if (this._texture)
265 this.prepareTextureForRender( 0 );
266 else
267 glContext.uniform1i( shaderProgram.useTextureUniform, false );
268
269 var amb = this._ambient, diff = this._diffuse, spec = this._specular;
270 glContext.uniform4f( shaderProgram.materialAmbientUniform, amb[0], amb[1], amb[2], amb[3]);
271 glContext.uniform4f( shaderProgram.materialDiffuseUniform, diff[0], diff[1], diff[2], diff[3]);
272 glContext.uniform4f( shaderProgram.materialSpecularUniform, spec[0], spec[1], spec[2], spec[3]);
273 }
274
275
276
277 this.prepareTextureForRender = function ( index )
278 {
279 // we will need to be able to handle multiple textures.
280 // currently only dealing with 1.
281 index = 0;
282 var texture = this._texture;
283
284 var gl = this.getWorld().getGLContext();
285 var shaderProgram = this.getWorld().getShaderProgram();
286
287 gl.activeTexture(gl.TEXTURE0);
288 gl.bindTexture(gl.TEXTURE_2D, texture);
289 gl.uniform1i(shaderProgram.samplerUniform, 0);
290 gl.uniform1i( shaderProgram.useTextureUniform, true );
291 }
292
293 this.textureLoadHandler = function (event)
294 {
295 var texture = this._texture;
296
297 var gl = this._world.getGLContext();
298 var shaderProgram = this._world.getShaderProgram();
299
300 gl.activeTexture(gl.TEXTURE0);
301 gl.bindTexture(gl.TEXTURE_2D, texture);
302 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
303 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
304 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
305 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
306
307// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
308// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
309 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
310 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
311
312 gl.bindTexture(gl.TEXTURE_2D, null);
313
314 this._material._texture = this._texture;
315 this._world.render();
316 }
317
318
319 this.loadTexture = function( path )
320 {
321 var gl = this.getWorld().getGLContext();
322 var tex = gl.createTexture();
323 tex.image = new Image();
324 tex.image._world = this._world;
325 tex.image._material = this;
326 tex.image._texture = tex;
327 tex.image.onload = this.textureLoadHandler;
328 tex.image.src = path;
329 }
330 */
331}; 265};
332 266
333if (typeof exports === "object") { 267if (typeof exports === "object") {