aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/tunnel-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/tunnel-material.js')
-rw-r--r--js/lib/rdge/materials/tunnel-material.js125
1 files changed, 125 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/tunnel-material.js b/js/lib/rdge/materials/tunnel-material.js
new file mode 100644
index 00000000..fe787d16
--- /dev/null
+++ b/js/lib/rdge/materials/tunnel-material.js
@@ -0,0 +1,125 @@
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
10var TunnelMaterial = function TunnelMaterial() {
11 ///////////////////////////////////////////////////////////////////////
12 // Instance variables
13 ///////////////////////////////////////////////////////////////////////
14 this._name = "TunnelMaterial";
15 this._shaderName = "tunnel";
16
17 this._texMap = 'assets/images/rocky-normal.jpg';
18
19 this._time = 0.0;
20 this._dTime = 0.001;
21
22 ///////////////////////////////////////////////////////////////////////
23 // Properties
24 ///////////////////////////////////////////////////////////////////////
25 // all defined in parent PulseMaterial.js
26 // load the local default value
27 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
28
29 ///////////////////////////////////////////////////////////////////////
30 // Methods
31 ///////////////////////////////////////////////////////////////////////
32 // duplcate method requirde
33 this.dup = function( world ) {
34 // allocate a new uber material
35 var newMat = new TunnelMaterial();
36
37 // copy over the current values;
38 var propNames = [], propValues = [], propTypes = [], propLabels = [];
39 this.getAllProperties( propNames, propValues, propTypes, propLabels);
40 var n = propNames.length;
41 for (var i=0; i<n; i++) {
42 newMat.setProperty( propNames[i], propValues[i] );
43 }
44
45 return newMat;
46 };
47
48 this.init = function( world )
49 {
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 = tunnelMaterialDef;
56 this._shader.init();
57
58 // set up the material node
59 this._materialNode = createMaterialNode("tunnelMaterial");
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
74///////////////////////////////////////////////////////////////////////////////////////
75// RDGE shader
76
77// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
78var tunnelMaterialDef =
79{'shaders':
80 {
81 'defaultVShader':"assets/shaders/Basic.vert.glsl",
82 'defaultFShader':"assets/shaders/Tunnel.frag.glsl"
83 },
84 'techniques':
85 {
86 'default':
87 [
88 {
89 'vshader' : 'defaultVShader',
90 'fshader' : 'defaultFShader',
91 // attributes
92 'attributes' :
93 {
94 'vert' : { 'type' : 'vec3' },
95 'normal' : { 'type' : 'vec3' },
96 'texcoord' : { 'type' : 'vec2' }
97 },
98 // parameters
99 'params' :
100 {
101 'u_tex0': { 'type' : 'tex2d' },
102 'u_time' : { 'type' : 'float' },
103 'u_resolution' : { 'type' : 'vec2' }
104 },
105
106 // render states
107 'states' :
108 {
109 'depthEnable' : true,
110 'offset':[1.0, 0.1]
111 }
112 }
113 ]
114 }
115};
116
117TunnelMaterial.prototype = new PulseMaterial();
118
119if (typeof exports === "object") {
120 exports.TunnelMaterial = TunnelMaterial;
121}
122
123
124
125