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.js120
1 files changed, 16 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..0eb13631 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,75 +13,39 @@ 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;
22 21
22 // array textures indexed by shader uniform name
23 this._glTextures = [];
24
23 /////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////
24 // Property Accessors 26 // Property Accessors
25 /////////////////////////////////////////////////////////////////////// 27 ///////////////////////////////////////////////////////////////////////
26 this.getName = function () { return this._name; }; 28 this.getName = function () { return this._name; };
27 this.getShaderName = function () { return this._shaderName; }; 29 this.getShaderName = function () { return this._shaderName; };
28 30 this.getShaderDef = function() { return radialBlurMaterialDef; };
29 this.getTextureMap = function () { return this._texMap.slice(0); }; 31 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 32
34 /////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////
35 // Material Property Accessors 34 // Material Property Accessors
36 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
37 this._propNames = ["texmap", "color"]; 36 this._propNames = ["u_tex0", "u_speed"];
38 this._propLabels = ["Texture map", "Color"]; 37 this._propLabels = ["Texture map", "Speed" ];
39 this._propTypes = ["file", "color"]; 38 this._propTypes = ["file", "float" ];
40 this._propValues = []; 39 this._propValues = [];
41 40
42 this._propValues[this._propNames[0]] = this._texMap.slice(0); 41 this._propValues[this._propNames[0]] = this._defaultTexMap.slice(0);
43 this._propValues[this._propNames[1]] = this._color.slice(0); 42 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 /////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////
66 44
67 45
68 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
69 // Methods 47 // Methods
70 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
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) { 49 this.init = function (world) {
87 // save the world 50 // save the world
88 if (world) this.setWorld(world); 51 if (world) this.setWorld(world);
@@ -99,31 +62,13 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
99 this._time = 0; 62 this._time = 0;
100 if (this._shader && this._shader['default']) 63 if (this._shader && this._shader['default'])
101 this._shader['default'].u_time.set([this._time]); 64 this._shader['default'].u_time.set([this._time]);
102 this.setProperty("color", [this._time, 0, 0, 1]);
103 65
104 // set the shader values in the shader 66 // set the shader values in the shader
105 this.updateTexture(); 67 this.setShaderValues();
106 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 68 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
107 this.update(0); 69 this.update(0);
108 }; 70 };
109 71
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 72
128 this.update = function () { 73 this.update = function () {
129 var material = this._materialNode; 74 var material = this._materialNode;
@@ -134,11 +79,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
134 if (this._shader && this._shader['default']) { 79 if (this._shader && this._shader['default']) {
135 this._shader['default'].u_time.set([this._time]); 80 this._shader['default'].u_time.set([this._time]);
136 } 81 }
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; 82 this._time += this._dTime;
143 } 83 }
144 } 84 }
@@ -154,34 +94,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() {
154 } 94 }
155 } 95 }
156 }; 96 };
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}; 97};
186 98
187/////////////////////////////////////////////////////////////////////////////////////// 99///////////////////////////////////////////////////////////////////////////////////////
@@ -213,8 +125,8 @@ var radialBlurMaterialDef =
213 { 125 {
214 'u_tex0': { 'type': 'tex2d' }, 126 'u_tex0': { 'type': 'tex2d' },
215 'u_time': { 'type': 'float' }, 127 'u_time': { 'type': 'float' },
128 'u_speed': { 'type': 'float' },
216 'u_resolution': { 'type': 'vec2' }, 129 'u_resolution': { 'type': 'vec2' },
217 'color': { 'type': 'vec4' }
218 }, 130 },
219 131
220 // render states 132 // render states