diff options
author | Jon Reid | 2012-03-06 14:14:01 -0800 |
---|---|---|
committer | Jon Reid | 2012-03-06 14:14:01 -0800 |
commit | 60bba95eaffa8b5c741c6c85fb84b327cd75d6c3 (patch) | |
tree | 0087ad093418638ff1d0b4362715bd7b2d147eba /js/lib/rdge/materials/keleidoscope-material.js | |
parent | d64f8c9fc1dd5fb15ad78ad61bed1ef3736321bb (diff) | |
parent | 342fb451bd251358068a0dcb10e9dc218b79a176 (diff) | |
download | ninja-60bba95eaffa8b5c741c6c85fb84b327cd75d6c3.tar.gz |
Merge remote-tracking branch 'ninja-jduran/TimelineUber' into Timeline-uber
Diffstat (limited to 'js/lib/rdge/materials/keleidoscope-material.js')
-rw-r--r-- | js/lib/rdge/materials/keleidoscope-material.js | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js new file mode 100644 index 00000000..3ef5d613 --- /dev/null +++ b/js/lib/rdge/materials/keleidoscope-material.js | |||
@@ -0,0 +1,144 @@ | |||
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 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | ||
8 | |||
9 | var KeleidoscopeMaterial = function KeleidoscopeMaterial() { | ||
10 | /////////////////////////////////////////////////////////////////////// | ||
11 | // Instance variables | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | this._name = "KeleidoscopeMaterial"; | ||
14 | this._shaderName = "keleidoscope"; | ||
15 | |||
16 | this._texMap = 'assets/images/rocky-normal.jpg'; | ||
17 | |||
18 | this._time = 0.0; | ||
19 | this._dTime = 0.01; | ||
20 | |||
21 | /////////////////////////////////////////////////////////////////////// | ||
22 | // Properties | ||
23 | /////////////////////////////////////////////////////////////////////// | ||
24 | // all defined in parent PulseMaterial.js | ||
25 | // load the local default value | ||
26 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | ||
27 | |||
28 | /////////////////////////////////////////////////////////////////////// | ||
29 | // Material Property Accessors | ||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | |||
32 | /////////////////////////////////////////////////////////////////////// | ||
33 | |||
34 | |||
35 | /////////////////////////////////////////////////////////////////////// | ||
36 | // Methods | ||
37 | /////////////////////////////////////////////////////////////////////// | ||
38 | // duplcate method requirde | ||
39 | this.dup = function( world ) { | ||
40 | // allocate a new uber material | ||
41 | var newMat = new KeleidoscopeMaterial(); | ||
42 | |||
43 | // copy over the current values; | ||
44 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
45 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
46 | var n = propNames.length; | ||
47 | for (var i=0; i<n; i++) | ||
48 | newMat.setProperty( propNames[i], propValues[i] ); | ||
49 | |||
50 | return newMat; | ||
51 | }; | ||
52 | |||
53 | this.init = function( world ) { | ||
54 | // save the world | ||
55 | if (world) this.setWorld( world ); | ||
56 | |||
57 | // set up the shader | ||
58 | this._shader = new jshader(); | ||
59 | this._shader.def = keleidoscopeMaterialDef; | ||
60 | this._shader.init(); | ||
61 | |||
62 | // set up the material node | ||
63 | this._materialNode = createMaterialNode("keleidoscopeMaterial"); | ||
64 | this._materialNode.setShader(this._shader); | ||
65 | |||
66 | this._time = 0; | ||
67 | if (this._shader && this._shader['default']) { | ||
68 | this._shader['default'].u_time.set( [this._time] ); | ||
69 | } | ||
70 | |||
71 | // set the shader values in the shader | ||
72 | this.updateTexture(); | ||
73 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | ||
74 | this.update( 0 ); | ||
75 | }; | ||
76 | |||
77 | this.update = function( time ) | ||
78 | { | ||
79 | var material = this._materialNode; | ||
80 | if (material) | ||
81 | { | ||
82 | var technique = material.shaderProgram['default']; | ||
83 | var renderer = g_Engine.getContext().renderer; | ||
84 | if (renderer && technique) | ||
85 | { | ||
86 | if (this._shader && this._shader['default']) { | ||
87 | this._shader['default'].u_time.set( [this._time] ); | ||
88 | } | ||
89 | |||
90 | this._time = time; | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | }; | ||
95 | |||
96 | /////////////////////////////////////////////////////////////////////////////////////// | ||
97 | // RDGE shader | ||
98 | |||
99 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
100 | var keleidoscopeMaterialDef = | ||
101 | {'shaders': | ||
102 | { | ||
103 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
104 | 'defaultFShader':"assets/shaders/Keleidoscope.frag.glsl" | ||
105 | }, | ||
106 | 'techniques': | ||
107 | { | ||
108 | 'default': | ||
109 | [ | ||
110 | { | ||
111 | 'vshader' : 'defaultVShader', | ||
112 | 'fshader' : 'defaultFShader', | ||
113 | // attributes | ||
114 | 'attributes' : | ||
115 | { | ||
116 | 'vert' : { 'type' : 'vec3' }, | ||
117 | 'normal' : { 'type' : 'vec3' }, | ||
118 | 'texcoord' : { 'type' : 'vec2' } | ||
119 | }, | ||
120 | // parameters | ||
121 | 'params' : | ||
122 | { | ||
123 | 'u_tex0': { 'type' : 'tex2d' }, | ||
124 | 'u_time' : { 'type' : 'float' }, | ||
125 | 'u_resolution' : { 'type' : 'vec2' }, | ||
126 | }, | ||
127 | |||
128 | // render states | ||
129 | 'states' : | ||
130 | { | ||
131 | 'depthEnable' : true, | ||
132 | 'offset':[1.0, 0.1] | ||
133 | } | ||
134 | } | ||
135 | ] | ||
136 | } | ||
137 | }; | ||
138 | |||
139 | KeleidoscopeMaterial.prototype = new PulseMaterial(); | ||
140 | |||
141 | if (typeof exports === "object") { | ||
142 | exports.KeleidoscopeMaterial = KeleidoscopeMaterial; | ||
143 | } | ||
144 | |||