From 5a1965bf2ed9a54601ca16fd67555335c510ce08 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 26 Apr 2012 16:40:05 -0700 Subject: Update materials to the new texture model. Create local world for deleted source canvases --- js/lib/rdge/materials/radial-blur-material.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'js/lib/rdge/materials/radial-blur-material.js') diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 6e1c024b..61ae0017 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -70,12 +70,14 @@ var RadialBlurMaterial = function RadialBlurMaterial() { /////////////////////////////////////////////////////////////////////// // duplicate method required this.dup = function () { - // allocate a new uber material - var newMat = new RadialBlurMaterial(); - - // copy over the current values; + // get the current values; var propNames = [], propValues = [], propTypes = [], propLabels = []; this.getAllProperties(propNames, propValues, propTypes, propLabels); + + // allocate a new material + var newMat = new RadialBlurMaterial(); + + // copy over the current values; var n = propNames.length; for (var i = 0; i < n; i++) newMat.setProperty(propNames[i], propValues[i]); -- cgit v1.2.3 From d4ca478ad313c6c20834e410ba14ad3a5e7b20bf Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 12 Jun 2012 10:28:26 -0700 Subject: Material cleanup & bug fixes. --- js/lib/rdge/materials/radial-blur-material.js | 119 +++----------------------- 1 file changed, 13 insertions(+), 106 deletions(-) (limited to 'js/lib/rdge/materials/radial-blur-material.js') diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 61ae0017..57f4a6e0 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -4,7 +4,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; var Material = require("js/lib/rdge/materials/material").Material; var RadialBlurMaterial = function RadialBlurMaterial() { @@ -14,8 +13,8 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this._name = "RadialBlurMaterial"; this._shaderName = "radialBlur"; - this._texMap = 'assets/images/cubelight.png'; - this._color = [1, 0, 0, 1]; + this._defaultTexMap = 'assets/images/cubelight.png'; + this._defaultColor = [1, 0, 0, 1]; this._time = 0.0; this._dTime = 0.01; @@ -23,68 +22,27 @@ var RadialBlurMaterial = function RadialBlurMaterial() { /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// - this.getName = function () { return this._name; }; - this.getShaderName = function () { return this._shaderName; }; - - this.getTextureMap = function () { return this._texMap.slice(0); }; - this.setTextureMap = function (m) { this._propValues[this._propNames[0]] = m.slice(0); this.updateTexture(); }; - - this.isAnimated = function () { return true; }; + this.getName = function () { return this._name; }; + this.getShaderName = function () { return this._shaderName; }; + this.getShaderDef = function() { return radialBlurMaterialDef; }; + this.isAnimated = function () { return true; }; /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["texmap", "color"]; - this._propLabels = ["Texture map", "Color"]; - this._propTypes = ["file", "color"]; + this._propNames = ["u_tex0", "u_speed"]; + this._propLabels = ["Texture map", "Speed" ]; + this._propTypes = ["file", "float" ]; this._propValues = []; - this._propValues[this._propNames[0]] = this._texMap.slice(0); - this._propValues[this._propNames[1]] = this._color.slice(0); - - this.setProperty = function (prop, value) { - // make sure we have legitimate imput - var ok = this.validateProperty(prop, value); - if (!ok) { - console.log("invalid property in Radial Gradient Material:" + prop + " : " + value); - } - - switch (prop) { - case "texmap": - this.setTextureMap(value); - break; - - case "color": - this._propValues[prop] = value.slice(0); - if (this._shader && this._shader['default']) { - this._shader['default'][prop].set(value); - } - break; - } - }; + this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0); + this._propValues[this._propNames[1]] = 1.0; /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// - // duplicate method required - this.dup = function () { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new RadialBlurMaterial(); - - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); - - return newMat; - }; - this.init = function (world) { // save the world if (world) this.setWorld(world); @@ -101,31 +59,13 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this._time = 0; if (this._shader && this._shader['default']) this._shader['default'].u_time.set([this._time]); - this.setProperty("color", [this._time, 0, 0, 1]); // set the shader values in the shader - this.updateTexture(); + this.setShaderValues(); this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); this.update(0); }; - this.updateTexture = function () { - var material = this._materialNode; - if (material) { - var technique = material.shaderProgram['default']; - var renderer = RDGE.globals.engine.getContext().renderer; - if (renderer && technique) { - var texMapName = this._propValues[this._propNames[0]]; - var tex = renderer.getTextureByName(texMapName, 'REPEAT'); - // if (tex) - // { - // var res = [tex.image.naturalWidth, tex.image.naturalHeight]; - // this.setResoloution( res ); - // } - technique.u_tex0.set(tex); - } - } - }; this.update = function () { var material = this._materialNode; @@ -136,11 +76,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() { if (this._shader && this._shader['default']) { this._shader['default'].u_time.set([this._time]); } - - var color = this.getProperty("color"); - color[0] = this._time; - this.setProperty("color", color); - //console.log( "update color to: " + color ); this._time += this._dTime; } } @@ -156,34 +91,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() { } } }; - - this.exportJSON = function () { - var jObj = - { - 'material': this.getShaderName(), - 'name': this.getName(), - 'color': this._propValues["color"], - 'texture': this._propValues[this._propNames[0]] - }; - - return jObj; - }; - - this.importJSON = function (jObj) { - if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); - this.setName(jObj.name); - - var rtnStr; - try { - this._propValues[this._propNames[0]] = jObj.texture; - this.updateTexture(); - } - catch (e) { - throw new Error("could not import material: " + importStr); - } - - return rtnStr; - }; }; /////////////////////////////////////////////////////////////////////////////////////// @@ -215,8 +122,8 @@ var radialBlurMaterialDef = { 'u_tex0': { 'type': 'tex2d' }, 'u_time': { 'type': 'float' }, + 'u_speed': { 'type': 'float' }, 'u_resolution': { 'type': 'vec2' }, - 'color': { 'type': 'vec4' } }, // render states -- cgit v1.2.3 From a7aa51e6b91623772eef54b827616432838b560e Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 13 Jun 2012 13:56:10 -0700 Subject: Material bug fixes - reset texture array. --- js/lib/rdge/materials/radial-blur-material.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'js/lib/rdge/materials/radial-blur-material.js') diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 57f4a6e0..0eb13631 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -19,6 +19,9 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this._time = 0.0; this._dTime = 0.01; + // array textures indexed by shader uniform name + this._glTextures = []; + /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From f0fc7a5678093cce986bd99fef2c5c88add19b68 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 14 Jun 2012 16:09:31 -0700 Subject: Fix for line color. Name change for all materials --- js/lib/rdge/materials/radial-blur-material.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/lib/rdge/materials/radial-blur-material.js') diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 0eb13631..c130544f 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -10,7 +10,7 @@ var RadialBlurMaterial = function RadialBlurMaterial() { /////////////////////////////////////////////////////////////////////// // Instance variables /////////////////////////////////////////////////////////////////////// - this._name = "RadialBlurMaterial"; + this._name = "Radial Blur"; this._shaderName = "radialBlur"; this._defaultTexMap = 'assets/images/cubelight.png'; @@ -146,7 +146,7 @@ var RaidersMaterial = function RaidersMaterial() { this.inheritedFrom = RadialBlurMaterial; this.inheritedFrom(); - this._name = "RaidersMaterial"; + this._name = "Raiders Material"; this._shaderName = "raiders"; this._texMap = 'assets/images/raiders.png'; -- cgit v1.2.3 From 043ab3f0aa5099f88a32dc377e9de1011b79611f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 15 Jun 2012 11:36:35 -0700 Subject: Re-added Raiders material --- js/lib/rdge/materials/radial-blur-material.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/lib/rdge/materials/radial-blur-material.js') diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index c130544f..68a92b0f 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -146,7 +146,7 @@ var RaidersMaterial = function RaidersMaterial() { this.inheritedFrom = RadialBlurMaterial; this.inheritedFrom(); - this._name = "Raiders Material"; + this._name = "Raiders"; this._shaderName = "raiders"; this._texMap = 'assets/images/raiders.png'; -- cgit v1.2.3