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