aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/Materials/RadialBlurMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/RadialBlurMaterial.js257
1 files changed, 0 insertions, 257 deletions
diff --git a/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js b/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js
deleted file mode 100644
index a5fb134c..00000000
--- a/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js
+++ /dev/null
@@ -1,257 +0,0 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
7
8
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13function RadialBlurMaterial()
14{
15 // initialize the inherited members
16 this.inheritedFrom = GLMaterial;
17 this.inheritedFrom();
18
19 ///////////////////////////////////////////////////////////////////////
20 // Instance variables
21 ///////////////////////////////////////////////////////////////////////
22 this._name = "RadialBlurMaterial";
23 this._shaderName = "radialBlur";
24
25 this._texMap = 'assets/images/cubelight.png';
26 this._color = [1,0,0,1];
27
28 this._time = 0.0;
29 this._dTime = 0.01;
30
31 ///////////////////////////////////////////////////////////////////////
32 // Property Accessors
33 ///////////////////////////////////////////////////////////////////////
34 this.getName = function() { return this._name; }
35 this.getShaderName = function() { return this._shaderName; }
36
37 this.getTextureMap = function() { return this._texMap.slice(0); }
38 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m.slice(0); this.updateTexture(); }
39
40 this.isAnimated = function() { return true; }
41
42 ///////////////////////////////////////////////////////////////////////
43 // Material Property Accessors
44 ///////////////////////////////////////////////////////////////////////
45 this._propNames = ["texmap", "color"];
46 this._propLabels = ["Texture map", "Color"];
47 this._propTypes = ["file", "color"];
48 this._propValues = [];
49
50 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
51 this._propValues[ this._propNames[1] ] = this._color.slice(0);
52
53 this.setProperty = function( prop, value )
54 {
55 // make sure we have legitimate imput
56 var ok = this.validateProperty( prop, value );
57 if (!ok)
58 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
59
60 switch (prop)
61 {
62 case "texmap":
63 this.setTextureMap(value);
64 break;
65
66 case "color":
67 this._propValues[prop] = value.slice(0);
68 if (this._shader && this._shader.default)
69 this._shader.default[prop].set(value);
70 break;
71 }
72 }
73 ///////////////////////////////////////////////////////////////////////
74
75
76 ///////////////////////////////////////////////////////////////////////
77 // Methods
78 ///////////////////////////////////////////////////////////////////////
79 // duplcate method requirde
80 this.dup = function( world )
81 {
82 // allocate a new uber material
83 var newMat = new RadialBlurMaterial();
84
85 // copy over the current values;
86 var propNames = [], propValues = [], propTypes = [], propLabels = [];
87 this.getAllProperties( propNames, propValues, propTypes, propLabels);
88 var n = propNames.length;
89 for (var i=0; i<n; i++)
90 newMat.setProperty( propNames[i], propValues[i] );
91
92 return newMat;
93 }
94
95 this.init = function( world )
96 {
97 // save the world
98 if (world) this.setWorld( world );
99
100 // set up the shader
101 this._shader = new jshader();
102 this._shader.def = radialBlurMaterialDef;
103 this._shader.init();
104
105 // set up the material node
106 this._materialNode = createMaterialNode("radialBlurMaterial");
107 this._materialNode.setShader(this._shader);
108
109 this._time = 0;
110 if (this._shader && this._shader.default)
111 this._shader.default.u_time.set( [this._time] );
112 this.setProperty( "color", [this._time, 0, 0, 1] );
113
114 // set the shader values in the shader
115 this.updateTexture();
116 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
117 this.update( 0 );
118 }
119
120 this.updateTexture = function()
121 {
122 var material = this._materialNode;
123 if (material)
124 {
125 var technique = material.shaderProgram.default;
126 var renderer = g_Engine.getContext().renderer;
127 if (renderer && technique)
128 {
129 var texMapName = this._propValues[this._propNames[0]];
130 var tex = renderer.getTextureByName(texMapName, 'REPEAT');
131// if (tex)
132// {
133// var res = [tex.image.naturalWidth, tex.image.naturalHeight];
134// this.setResoloution( res );
135// }
136 technique.u_tex0.set( tex );
137 }
138 }
139 }
140
141 this.update = function( time )
142 {
143 var material = this._materialNode;
144 if (material)
145 {
146 var technique = material.shaderProgram.default;
147 var renderer = g_Engine.getContext().renderer;
148 if (renderer && technique)
149 {
150 if (this._shader && this._shader.default)
151 this._shader.default.u_time.set( [this._time] );
152 var color = this.getProperty( "color" );
153 color[0] = this._time;
154 this.setProperty( "color", color );
155 //console.log( "update color to: " + color );
156 this._time += this._dTime;
157 }
158 }
159 }
160
161 this.setResolution = function( res )
162 {
163 var material = this._materialNode;
164 if (material)
165 {
166 var technique = material.shaderProgram.default;
167 var renderer = g_Engine.getContext().renderer;
168 if (renderer && technique)
169 {
170 technique.u_resolution.set( res );
171 }
172 }
173 }
174
175 this.export = function()
176 {
177 // every material needs the base type and instance name
178 var exportStr = "material: " + this.getShaderName() + "\n";
179 exportStr += "name: " + this.getName() + "\n";
180
181 // every material needs to terminate like this
182 exportStr += "endMaterial\n";
183
184 return exportStr;
185 }
186
187 this.import = function( importStr )
188 {
189 var pu = new ParseUtils( importStr );
190 var material = pu.nextValue( "material: " );
191 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
192 this.setName( pu.nextValue( "name: ") );
193
194 var rtnStr;
195 try
196 {
197 var endKey = "endMaterial\n";
198 var index = importStr.indexOf( endKey );
199 index += endKey.length;
200 rtnStr = importStr.substr( index );
201 }
202 catch (e)
203 {
204 throw new Error( "could not import material: " + importStr );
205 }
206
207 return rtnStr;
208 }
209}
210
211///////////////////////////////////////////////////////////////////////////////////////
212// RDGE shader