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.js244
1 files changed, 0 insertions, 244 deletions
diff --git a/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js b/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js
deleted file mode 100644
index 9acb4213..00000000
--- a/js/helper-classes/RDGE/Materials/RadialBlurMaterial.js
+++ /dev/null
@@ -1,244 +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 ///////////////////////////////////////////////////////////////////////
41 // Material Property Accessors
42 ///////////////////////////////////////////////////////////////////////
43 this._propNames = ["texmap", "color"];
44 this._propLabels = ["Texture map", "Color"];
45 this._propTypes = ["file", "color"];
46 this._propValues = [];
47
48 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
49 this._propValues[ this._propNames[1] ] = this._color.slice(0);
50
51 this.setProperty = function( prop, value )
52 {
53 // make sure we have legitimate imput
54 var ok = this.validateProperty( prop, value );
55 if (!ok)
56 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
57
58 switch (prop)
59 {
60 case "texmap":
61 this.setTextureMap(value);
62 break;
63
64 case "color":
65 this._propValues[prop] = value.slice(0);
66 if (this._shader && this._shader.default)
67 this._shader.default[prop].set(value);
68 break;
69 }
70 }
71 ///////////////////////////////////////////////////////////////////////
72
73
74 ///////////////////////////////////////////////////////////////////////
75 // Methods
76 ///////////////////////////////////////////////////////////////////////
77 // duplcate method requirde
78 this.dup = function( world )
79 {
80 // allocate a new uber material
81 var newMat = new RadialBlurMaterial();
82
83 // copy over the current values;
84 var propNames = [], propValues = [], propTypes = [], propLabels = [];
85 this.getAllProperties( propNames, propValues, propTypes, propLabels);
86 var n = propNames.length;
87 for (var i=0; i<n; i++)
88 newMat.setProperty( propNames[i], propValues[i] );
89
90 return newMat;
91 }
92
93 this.init = function( world )
94 {
95 // save the world
96 if (world) this.setWorld( world );
97
98 // set up the shader
99 this._shader = new jshader();
100 this._shader.def = radialBlurMaterialDef;
101 this._shader.init();
102
103 // set up the material node
104 this._materialNode = createMaterialNode("radialBlurMaterial");
105 this._materialNode.setShader(this._shader);
106
107 this._time = 0;
108 if (this._shader && this._shader.default)
109 this._shader.default.u_time.set( [this._time] );
110 this.setProperty( "color", [this._time, 0, 0, 1] );
111
112 // set the shader values in the shader
113 this.updateTexture();
114 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
115 this.update( 0 );
116 }
117
118 this.updateTexture = function()
119 {
120 var material = this._materialNode;
121 if (material)
122 {
123 var technique = material.shaderProgram.default;
124 var renderer = g_Engine.getContext().renderer;
125 if (renderer && technique)
126 {
127 var texMapName = this._propValues[this._propNames[0]];
128 var tex = renderer.getTextureByName(texMapName, 'REPEAT');
129// if (tex)
130// {
131// var res = [tex.image.naturalWidth, tex.image.naturalHeight];
132// this.setResoloution( res );
133// }
134 technique.u_tex0.set( tex );
135 }
136 }
137 }
138
139 this.update = function( time )
140 {
141 var material = this._materialNode;
142 if (material)
143 {
144 var technique = material.shaderProgram.default;
145 var renderer = g_Engine.getContext().renderer;
146 if (renderer && technique)
147 {
148 if (this._shader && this._shader.default)
149 this._shader.default.u_time.set( [this._time] );
150 var color = this.getProperty( "color" );
151 color[0] = this._time;
152 this.setProperty( "color", color );
153 //console.log( "update color to: " + color );
154 this._time += this._dTime;
155 }
156 }
157 }
158
159 this.setResolution = function( res )
160 {
161 var material = this._materialNode;
162 if (material)
163 {
164 var technique = material.shaderProgram.default;
165 var renderer = g_Engine.getContext().renderer;
166 if (renderer && technique)
167 {
168 technique.u_resolution.set( res );
169 }
170 }
171 }
172
173 this.export = function()
174 {
175 // every material needs the base type and instance name
176 var exportStr = "material: " + this.getShaderName() + "\n";
177 exportStr += "name: " + this.getName() + "\n";
178
179 // every material needs to terminate like this
180 exportStr += "endMaterial\n";
181
182 return exportStr;
183 }
184
185 this.import = function( importStr )
186 {
187 var pu = new ParseUtils( importStr );
188 var material = pu.nextValue( "material: " );
189 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
190 this.setName( pu.nextValue( "name: ") );
191
192 var rtnStr;
193
194 return rtnStr;
195 }
196}
197
198///////////////////////////////////////////////////////////////////////////////////////
199// RDGE shader
200
201// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
202var radialBlurMaterialDef =
203{'shaders':
204 {
205 'defaultVShader':"assets/shaders/Basic.vert.glsl",
206 'defaultFShader':"assets/shaders/radialBlur.frag.glsl"
207 },
208 'techniques':
209 {
210 'default':
211 [
212 {
213 'vshader' : 'defaultVShader',
214