aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-material.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-06 11:05:00 -0800
committerValerio Virgillito2012-03-06 11:05:00 -0800
commit4540b5b4ea2065c3e0d67b46bba8b6764801fbea (patch)
tree4e1561530b1b90ea497bac8e41d193fa605e98b4 /js/lib/rdge/materials/twist-material.js
parent4e35725e6c9044c37bef28b8c8d36f4b5c89bfd9 (diff)
parent84332ab81c1b445195f1d9be8bbeae0725c8e758 (diff)
downloadninja-4540b5b4ea2065c3e0d67b46bba8b6764801fbea.tar.gz
Merge branch 'refs/heads/master' into panels
Diffstat (limited to 'js/lib/rdge/materials/twist-material.js')
-rw-r--r--js/lib/rdge/materials/twist-material.js139
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
8var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
9
10///////////////////////////////////////////////////////////////////////
11var 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)
92var 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
131TwistMaterial.prototype = new PulseMaterial();
132
133if (typeof exports === "object") {
134 exports.TwistMaterial = TwistMaterial;
135}
136
137
138
139