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.js77
1 files changed, 5 insertions, 72 deletions
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index 276c7687..77220bf7 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 ///////////////////////////////////////////////////////////////////////
@@ -252,78 +257,6 @@ var Material = function GLMaterial( world ) {
252 return tex; 257 return tex;
253 }; 258 };
254 259
255 /*
256 this.setRenderProperties = function( glContext, shaderProgram )
257 {
258 glContext.uniform1f( shaderProgram.materialShininessUniform, this._shininess );
259
260 if (this._texture)
261 this.prepareTextureForRender( 0 );
262 else
263 glContext.uniform1i( shaderProgram.useTextureUniform, false );
264
265 var amb = this._ambient, diff = this._diffuse, spec = this._specular;
266 glContext.uniform4f( shaderProgram.materialAmbientUniform, amb[0], amb[1], amb[2], amb[3]);
267 glContext.uniform4f( shaderProgram.materialDiffuseUniform, diff[0], diff[1], diff[2], diff[3]);
268 glContext.uniform4f( shaderProgram.materialSpecularUniform, spec[0], spec[1], spec[2], spec[3]);
269 }
270
271
272
273 this.prepareTextureForRender = function ( index )
274 {
275 // we will need to be able to handle multiple textures.
276 // currently only dealing with 1.
277 index = 0;
278 var texture = this._texture;
279
280 var gl = this.getWorld().getGLContext();
281 var shaderProgram = this.getWorld().getShaderProgram();
282
283 gl.activeTexture(gl.TEXTURE0);
284 gl.bindTexture(gl.TEXTURE_2D, texture);
285 gl.uniform1i(shaderProgram.samplerUniform, 0);
286 gl.uniform1i( shaderProgram.useTextureUniform, true );
287 }
288
289 this.textureLoadHandler = function (event)
290 {
291 var texture = this._texture;
292
293 var gl = this._world.getGLContext();
294 var shaderProgram = this._world.getShaderProgram();
295
296 gl.activeTexture(gl.TEXTURE0);
297 gl.bindTexture(gl.TEXTURE_2D, texture);
298 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
299 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
300 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
301 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
302
303// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
304// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
305 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
306 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
307
308 gl.bindTexture(gl.TEXTURE_2D, null);
309
310 this._material._texture = this._texture;
311 this._world.render();
312 }
313
314
315 this.loadTexture = function( path )
316 {
317 var gl = this.getWorld().getGLContext();
318 var tex = gl.createTexture();
319 tex.image = new Image();
320 tex.image._world = this._world;
321 tex.image._material = this;
322 tex.image._texture = tex;
323 tex.image.onload = this.textureLoadHandler;
324 tex.image.src = path;
325 }
326 */
327}; 260};
328 261
329if (typeof exports === "object") { 262if (typeof exports === "object") {