diff options
Diffstat (limited to 'js/lib/rdge/materials/radial-blur-material.js')
-rw-r--r-- | js/lib/rdge/materials/radial-blur-material.js | 119 |
1 files changed, 13 insertions, 106 deletions
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 | |||
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 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | ||
8 | var Material = require("js/lib/rdge/materials/material").Material; | 7 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | 8 | ||
10 | var RadialBlurMaterial = function RadialBlurMaterial() { | 9 | var 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,68 +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 | // get the current values; | ||
74 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
75 | this.getAllProperties(propNames, propValues, propTypes, propLabels); | ||
76 | |||
77 | // allocate a new material | ||
78 | var newMat = new RadialBlurMaterial(); | ||
79 | |||
80 | // copy over the current values; | ||
81 | var n = propNames.length; | ||
82 | for (var i = 0; i < n; i++) | ||
83 | newMat.setProperty(propNames[i], propValues[i]); | ||
84 | |||
85 | return newMat; | ||
86 | }; | ||
87 | |||
88 | this.init = function (world) { | 46 | this.init = function (world) { |
89 | // save the world | 47 | // save the world |
90 | if (world) this.setWorld(world); | 48 | if (world) this.setWorld(world); |
@@ -101,31 +59,13 @@ var RadialBlurMaterial = function RadialBlurMaterial() { | |||
101 | this._time = 0; | 59 | this._time = 0; |
102 | if (this._shader && this._shader['default']) | 60 | if (this._shader && this._shader['default']) |
103 | this._shader['default'].u_time.set([this._time]); | 61 | this._shader['default'].u_time.set([this._time]); |
104 | this.setProperty("color", [this._time, 0, 0, 1]); | ||
105 | 62 | ||
106 | // set the shader values in the shader | 63 | // set the shader values in the shader |
107 | this.updateTexture(); | 64 | this.setShaderValues(); |
108 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); | 65 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); |
109 | this.update(0); | 66 | this.update(0); |
110 | }; | 67 | }; |
111 | 68 | ||
112 | this.updateTexture = function () { | ||
113 | var material = this._materialNode; | ||
114 | if (material) { | ||
115 | var technique = material.shaderProgram['default']; | ||
116 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
117 | if (renderer && technique) { | ||
118 | var texMapName = this._propValues[this._propNames[0]]; | ||
119 | var tex = renderer.getTextureByName(texMapName, 'REPEAT'); | ||
120 | // if (tex) | ||
121 | // { | ||
122 | // var res = [tex.image.naturalWidth, tex.image.naturalHeight]; | ||
123 | // this.setResoloution( res ); | ||
124 | // } | ||
125 | technique.u_tex0.set(tex); | ||
126 | } | ||
127 | } | ||
128 | }; | ||
129 | 69 | ||
130 | this.update = function () { | 70 | this.update = function () { |
131 | var material = this._materialNode; | 71 | var material = this._materialNode; |
@@ -136,11 +76,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() { | |||
136 | if (this._shader && this._shader['default']) { | 76 | if (this._shader && this._shader['default']) { |
137 | this._shader['default'].u_time.set([this._time]); | 77 | this._shader['default'].u_time.set([this._time]); |
138 | } | 78 | } |
139 | |||
140 | var color = this.getProperty("color"); | ||
141 | color[0] = this._time; | ||
142 | this.setProperty("color", color); | ||
143 | //console.log( "update color to: " + color ); | ||
144 | this._time += this._dTime; | 79 | this._time += this._dTime; |
145 | } | 80 | } |
146 | } | 81 | } |
@@ -156,34 +91,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() { | |||
156 | } | 91 | } |
157 | } | 92 | } |
158 | }; | 93 | }; |
159 | |||
160 | this.exportJSON = function () { | ||
161 | var jObj = | ||
162 | { | ||
163 | 'material': this.getShaderName(), | ||
164 | 'name': this.getName(), | ||
165 | 'color': this._propValues["color"], | ||
166 | 'texture': this._propValues[this._propNames[0]] | ||
167 | }; | ||
168 | |||
169 | return jObj; | ||
170 | }; | ||
171 | |||
172 | this.importJSON = function (jObj) { | ||
173 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); | ||
174 | this.setName(jObj.name); | ||
175 | |||
176 | var rtnStr; | ||
177 | try { | ||
178 | this._propValues[this._propNames[0]] = jObj.texture; | ||
179 | this.updateTexture(); | ||
180 | } | ||
181 | catch (e) { | ||
182 | throw new Error("could not import material: " + importStr); | ||
183 | } | ||
184 | |||
185 | return rtnStr; | ||
186 | }; | ||
187 | }; | 94 | }; |
188 | 95 | ||
189 | /////////////////////////////////////////////////////////////////////////////////////// | 96 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -215,8 +122,8 @@ var radialBlurMaterialDef = | |||
215 | { | 122 | { |
216 | 'u_tex0': { 'type': 'tex2d' }, | 123 | 'u_tex0': { 'type': 'tex2d' }, |
217 | 'u_time': { 'type': 'float' }, | 124 | 'u_time': { 'type': 'float' }, |
125 | 'u_speed': { 'type': 'float' }, | ||
218 | 'u_resolution': { 'type': 'vec2' }, | 126 | 'u_resolution': { 'type': 'vec2' }, |
219 | 'color': { 'type': 'vec4' } | ||
220 | }, | 127 | }, |
221 | 128 | ||
222 | // render states | 129 | // render states |