diff options
Diffstat (limited to 'js/lib/rdge/materials/radial-blur-material.js')
-rw-r--r-- | js/lib/rdge/materials/radial-blur-material.js | 414 |
1 files changed, 183 insertions, 231 deletions
diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index fee02a1d..6e1c024b 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js | |||
@@ -1,8 +1,8 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 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/> | 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. | 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; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
@@ -11,263 +11,217 @@ var RadialBlurMaterial = function RadialBlurMaterial() { | |||
11 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
12 | // Instance variables | 12 | // Instance variables |
13 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
14 | this._name = "RadialBlurMaterial"; | 14 | this._name = "RadialBlurMaterial"; |
15 | this._shaderName = "radialBlur"; | 15 | this._shaderName = "radialBlur"; |
16 | 16 | ||
17 | this._texMap = 'assets/images/cubelight.png'; | 17 | this._texMap = 'assets/images/cubelight.png'; |
18 | this._color = [1,0,0,1]; | 18 | this._color = [1, 0, 0, 1]; |
19 | 19 | ||
20 | this._time = 0.0; | 20 | this._time = 0.0; |
21 | this._dTime = 0.01; | 21 | this._dTime = 0.01; |
22 | 22 | ||
23 | /////////////////////////////////////////////////////////////////////// | 23 | /////////////////////////////////////////////////////////////////////// |
24 | // Property Accessors | 24 | // Property Accessors |
25 | /////////////////////////////////////////////////////////////////////// | 25 | /////////////////////////////////////////////////////////////////////// |
26 | this.getName = function() { return this._name; }; | 26 | this.getName = function () { return this._name; }; |
27 | this.getShaderName = function() { return this._shaderName; }; | 27 | this.getShaderName = function () { return this._shaderName; }; |
28 | 28 | ||
29 | this.getTextureMap = function() { return this._texMap.slice(0); }; | 29 | this.getTextureMap = function () { return this._texMap.slice(0); }; |
30 | this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m.slice(0); this.updateTexture(); }; | 30 | this.setTextureMap = function (m) { this._propValues[this._propNames[0]] = m.slice(0); this.updateTexture(); }; |
31 | 31 | ||
32 | this.isAnimated = function() { return true; }; | 32 | this.isAnimated = function () { return true; }; |
33 | 33 | ||
34 | /////////////////////////////////////////////////////////////////////// | 34 | /////////////////////////////////////////////////////////////////////// |
35 | // Material Property Accessors | 35 | // Material Property Accessors |
36 | /////////////////////////////////////////////////////////////////////// | 36 | /////////////////////////////////////////////////////////////////////// |
37 | this._propNames = ["texmap", "color"]; | 37 | this._propNames = ["texmap", "color"]; |
38 | this._propLabels = ["Texture map", "Color"]; | 38 | this._propLabels = ["Texture map", "Color"]; |
39 | this._propTypes = ["file", "color"]; | 39 | this._propTypes = ["file", "color"]; |
40 | this._propValues = []; | 40 | this._propValues = []; |
41 | 41 | ||
42 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | 42 | this._propValues[this._propNames[0]] = this._texMap.slice(0); |
43 | this._propValues[ this._propNames[1] ] = this._color.slice(0); | 43 | this._propValues[this._propNames[1]] = this._color.slice(0); |
44 | 44 | ||
45 | this.setProperty = function( prop, value ) { | 45 | this.setProperty = function (prop, value) { |
46 | // make sure we have legitimate imput | 46 | // make sure we have legitimate imput |
47 | var ok = this.validateProperty( prop, value ); | 47 | var ok = this.validateProperty(prop, value); |
48 | if (!ok) { | 48 | if (!ok) { |
49 | console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value ); | 49 | console.log("invalid property in Radial Gradient Material:" + prop + " : " + value); |
50 | } | 50 | } |
51 | 51 | ||
52 | switch (prop) | 52 | switch (prop) { |
53 | { | 53 | case "texmap": |
54 | case "texmap": | 54 | this.setTextureMap(value); |
55 | this.setTextureMap(value); | 55 | break; |
56 | break; | 56 | |
57 | 57 | case "color": | |
58 | case "color": | 58 | this._propValues[prop] = value.slice(0); |
59 | this._propValues[prop] = value.slice(0); | 59 | if (this._shader && this._shader['default']) { |
60 | if (this._shader && this._shader['default']) { | 60 | this._shader['default'][prop].set(value); |
61 | this._shader['default'][prop].set(value); | ||
62 | } | 61 | } |
63 | break; | 62 | break; |
64 | } | 63 | } |
65 | }; | 64 | }; |
66 | /////////////////////////////////////////////////////////////////////// | 65 | /////////////////////////////////////////////////////////////////////// |
67 | 66 | ||
68 | 67 | ||
69 | /////////////////////////////////////////////////////////////////////// | 68 | /////////////////////////////////////////////////////////////////////// |
70 | // Methods | 69 | // Methods |
71 | /////////////////////////////////////////////////////////////////////// | 70 | /////////////////////////////////////////////////////////////////////// |
72 | // duplcate method requirde | 71 | // duplicate method required |
73 | this.dup = function( ) { | 72 | this.dup = function () { |
74 | // allocate a new uber material | 73 | // allocate a new uber material |
75 | var newMat = new RadialBlurMaterial(); | 74 | var newMat = new RadialBlurMaterial(); |
76 | 75 | ||
77 | // copy over the current values; | 76 | // copy over the current values; |
78 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | 77 | var propNames = [], propValues = [], propTypes = [], propLabels = []; |
79 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | 78 | this.getAllProperties(propNames, propValues, propTypes, propLabels); |
80 | var n = propNames.length; | 79 | var n = propNames.length; |
81 | for (var i=0; i<n; i++) | 80 | for (var i = 0; i < n; i++) |
82 | newMat.setProperty( propNames[i], propValues[i] ); | 81 | newMat.setProperty(propNames[i], propValues[i]); |
83 | 82 | ||
84 | return newMat; | 83 | return newMat; |
85 | }; | 84 | }; |
86 | 85 | ||
87 | this.init = function( world ) { | 86 | this.init = function (world) { |
88 | // save the world | 87 | // save the world |
89 | if (world) this.setWorld( world ); | 88 | if (world) this.setWorld(world); |
90 | 89 | ||
91 | // set up the shader | 90 | // set up the shader |
92 | this._shader = new jshader(); | 91 | this._shader = new RDGE.jshader(); |
93 | this._shader.def = radialBlurMaterialDef; | 92 | this._shader.def = radialBlurMaterialDef; |
94 | this._shader.init(); | 93 | this._shader.init(); |
95 | 94 | ||
96 | // set up the material node | 95 | // set up the material node |
97 | this._materialNode = createMaterialNode("radialBlurMaterial" + "_" + world.generateUniqueNodeID()); | 96 | this._materialNode = RDGE.createMaterialNode("radialBlurMaterial" + "_" + world.generateUniqueNodeID()); |
98 | this._materialNode.setShader(this._shader); | 97 | this._materialNode.setShader(this._shader); |
99 | 98 | ||
100 | this._time = 0; | 99 | this._time = 0; |
101 | if (this._shader && this._shader['default']) | 100 | if (this._shader && this._shader['default']) |
102 | this._shader['default'].u_time.set( [this._time] ); | 101 | this._shader['default'].u_time.set([this._time]); |
103 | this.setProperty( "color", [this._time, 0, 0, 1] ); | 102 | this.setProperty("color", [this._time, 0, 0, 1]); |
104 | 103 | ||
105 | // set the shader values in the shader | 104 | // set the shader values in the shader |
106 | this.updateTexture(); | 105 | this.updateTexture(); |
107 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | 106 | this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); |
108 | this.update( 0 ); | 107 | this.update(0); |
109 | }; | 108 | }; |
110 | 109 | ||
111 | this.updateTexture = function() { | 110 | this.updateTexture = function () { |
112 | var material = this._materialNode; | 111 | var material = this._materialNode; |
113 | if (material) { | 112 | if (material) { |
114 | var technique = material.shaderProgram['default']; | 113 | var technique = material.shaderProgram['default']; |
115 | var renderer = g_Engine.getContext().renderer; | 114 | var renderer = RDGE.globals.engine.getContext().renderer; |
116 | if (renderer && technique) { | 115 | if (renderer && technique) { |
117 | var texMapName = this._propValues[this._propNames[0]]; | 116 | var texMapName = this._propValues[this._propNames[0]]; |
118 | var tex = renderer.getTextureByName(texMapName, 'REPEAT'); | 117 | var tex = renderer.getTextureByName(texMapName, 'REPEAT'); |
119 | // if (tex) | 118 | // if (tex) |
120 | // { | 119 | // { |
121 | // var res = [tex.image.naturalWidth, tex.image.naturalHeight]; | 120 | // var res = [tex.image.naturalWidth, tex.image.naturalHeight]; |
122 | // this.setResoloution( res ); | 121 | // this.setResoloution( res ); |
123 | // } | 122 | // } |
124 | technique.u_tex0.set( tex ); | 123 | technique.u_tex0.set(tex); |
125 | } | 124 | } |
126 | } | 125 | } |
127 | }; | 126 |