aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/radial-blur-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/radial-blur-material.js')
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js117
1 files changed, 13 insertions, 104 deletions
diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js
index 6e1c024b..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
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material; 7var Material = require("js/lib/rdge/materials/material").Material;
9 8
10var RadialBlurMaterial = function RadialBlurMaterial() { 9var RadialBlurMaterial = function RadialBlurMaterial() {
@@ -14,8 +13,8 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
14 this._name = "RadialBlurMaterial"; 13 this._name = "RadialBlurMaterial";
15 this._shaderName = "radialBlur"; 14 this._shaderName = "radialBlur";
16 15
17 this._texMap = 'assets/images/cubelight.png'; 16 this._defaultTexMap = 'assets/images/cubelight.png';
18 this._color = [1, 0, 0, 1]; 17 this._defaultColor = [1, 0, 0, 1];
19 18
20 this._time = 0.0; 19 this._time = 0.0;
21 this._dTime = 0.01; 20 this._dTime = 0.01;
@@ -23,66 +22,27 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
23 /////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////
24 // Property Accessors 23 // Property Accessors
25 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
26 this.getName = function () { return this._name; }; 25 this.getName = function () { return this._name; };
27 this.getShaderName = function () { return this._shaderName; }; 26 this.getShaderName = function () { return this._shaderName; };
28 27 this.getShaderDef = function() { return radialBlurMaterialDef; };
29 this.getTextureMap = function () { return this._texMap.slice(0); }; 28 this.isAnimated = function () { return true; };
30 this.setTextureMap = function (m) { this._propValues[this._propNames[0]] = m.slice(0); this.updateTexture(); };
31
32 this.isAnimated = function () { return true; };
33 29
34 /////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////
35 // Material Property Accessors 31 // Material Property Accessors
36 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
37 this._propNames = ["texmap", "color"]; 33 this._propNames = ["u_tex0", "u_speed"];
38 this._propLabels = ["Texture map", "Color"]; 34 this._propLabels = ["Texture map", "Speed" ];
39 this._propTypes = ["file", "color"]; 35 this._propTypes = ["file", "float" ];
40 this._propValues = []; 36 this._propValues = [];
41 37
42 this._propValues[this._propNames[0]] = this._texMap.slice(0); 38 this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0);
43 this._propValues[this._propNames[1]] = this._color.slice(0); 39 this._propValues[this._propNames[1]] = 1.0;
44
45 this.setProperty = function (prop, value) {
46 // make sure we have legitimate imput
47 var ok = this.validateProperty(prop, value);
48 if (!ok) {
49 console.log("invalid property in Radial Gradient Material:" + prop + " : " + value);
50 }
51
52 switch (prop) {
53 case "texmap":
54 this.setTextureMap(value);
55 break;
56
57 case "color":
58 this._propValues[prop] = value.slice(0);
59 if (this._shader && this._shader['default']) {
60 this._shader['default'][prop].set(value);
61 }
62 break;
63 }
64 };
65 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
66 41
67 42
68 /////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////
69 // Methods 44 // Methods
70 /////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////
71 // duplicate method required
72 this.dup = function () {
73 // allocate a new uber material
74 var newMat = new RadialBlurMaterial();
75
76 // copy over the current values;
77 var propNames = [], propValues = [], propTypes = [], propLabels = [];
78 this.getAllProperties(propNames, propValues, propTypes, propLabels);
79 var n = propNames.length;
80 for (var i = 0; i < n; i++)
81 newMat.setProperty(propNames[i], propValues[i]);
82
83 return newMat;
84 };
85
86 this.init = function (world) { 46 this.init = function (world) {
87 // save the world 47 // save the world
88 if (world) this.setWorld(world); 48 if (world) this.setWorld(world);
@@ -99,31 +59,13 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
99 this._time = 0; 59 this._time = 0;
100 if (this._shader && this._shader['default']) 60 if (this._shader && this._shader['default'])
101 this._shader['default'].u_time.set([this._time]); 61 this._shader['default'].u_time.set([this._time]);
102 this.setProperty("color", [this._time, 0, 0, 1]);
103 62
104 // set the shader values in the shader 63 // set the shader values in the shader
105 this.updateTexture(); 64 this.setShaderValues();
106 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 65 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
107 this.update(0); 66 this.update(0);
108 }; 67 };
109 68
110 this.updateTexture = function () {
111 var material = this._materialNode;
112 if (material) {
113 var technique = material.shaderProgram['default'];
114 var renderer = RDGE.globals.engine.getContext().renderer;
115 if (renderer && technique) {
116 var texMapName = this._propValues[this._propNames[0]];
117 var tex = renderer.getTextureByName(texMapName, 'REPEAT');
118 // if (tex)
119 // {
120 // var res = [tex.image.naturalWidth, tex.image.naturalHeight];
121 // this.setResoloution( res );
122 // }
123 technique.u_tex0.set(tex);
124 }
125 }
126 };
127 69
128 this.update = function () { 70 this.update = function () {
129 var material = this._materialNode; 71 var material = this._materialNode;
@@ -134,11 +76,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
134 if (this._shader && this._shader['default']) { 76 if (this._shader && this._shader['default']) {
135 this._shader['default'].u_time.set([this._time]); 77 this._shader['default'].u_time.set([this._time]);
136 } 78 }
137
138 var color = this.getProperty("color");
139 color[0] = this._time;
140 this.setProperty("color", color);
141 //console.log( "update color to: " + color );
142 this._time += this._dTime; 79 this._time += this._dTime;
143 } 80 }
144 } 81 }
@@ -154,34 +91,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
154 } 91 }
155 } 92 }
156 }; 93 };
157
158 this.exportJSON = function () {
159 var jObj =
160 {
161 'material': this.getShaderName(),
162 'name': this.getName(),
163 'color': this._propValues["color"],
164 'texture': this._propValues[this._propNames[0]]
165 };
166
167 return jObj;
168 };
169
170 this.importJSON = function (jObj) {
171 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
172 this.setName(jObj.name);
173
174 var rtnStr;
175 try {
176 this._propValues[this._propNames[0]] = jObj.texture;
177 this.updateTexture();
178 }
179 catch (e) {
180 throw new Error("could not import material: " + importStr);
181 }
182
183 return rtnStr;
184 };
185}; 94};
186 95
187/////////////////////////////////////////////////////////////////////////////////////// 96///////////////////////////////////////////////////////////////////////////////////////
@@ -213,8 +122,8 @@ var radialBlurMaterialDef =
213 { 122 {
214 'u_tex0': { 'type': 'tex2d' }, 123 'u_tex0': { 'type': 'tex2d' },
215 'u_time': { 'type': 'float' }, 124 'u_time': { 'type': 'float' },
125 'u_speed': { 'type': 'float' },
216 'u_resolution': { 'type': 'vec2' }, 126 'u_resolution': { 'type': 'vec2' },
217 'color': { 'type': 'vec4' }
218 }, 127 },
219 128
220 // render states 129 // render states