aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/square-tunnel-material.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-06 14:09:44 -0800
committerNivesh Rajbhandari2012-03-06 14:09:44 -0800
commit792793cd3991032b4840ade67f98ae8eae2d30a0 (patch)
tree69d3df003d2bb58fa1ab562fbd1058ff91851f01 /js/lib/rdge/materials/square-tunnel-material.js
parent2346d8ab9db06573d8672c64988c46b6c672e015 (diff)
parent1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f (diff)
downloadninja-792793cd3991032b4840ade67f98ae8eae2d30a0.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/lib/rdge/materials/square-tunnel-material.js')
-rw-r--r--js/lib/rdge/materials/square-tunnel-material.js120
1 files changed, 120 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/square-tunnel-material.js b/js/lib/rdge/materials/square-tunnel-material.js
new file mode 100644
index 00000000..b5cbff30
--- /dev/null
+++ b/js/lib/rdge/materials/square-tunnel-material.js
@@ -0,0 +1,120 @@
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
7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
8
9var SquareTunnelMaterial = function SquareTunnelMaterial() {
10 ///////////////////////////////////////////////////////////////////////
11 // Instance variables
12 ///////////////////////////////////////////////////////////////////////
13 this._name = "SquareTunnelMaterial";
14 this._shaderName = "squareTunnel";
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 // Methods
30 ///////////////////////////////////////////////////////////////////////
31 // duplcate method requirde
32 this.dup = function( world ) {
33 // allocate a new uber material
34 var newMat = new SquareTunnelMaterial();
35
36 // copy over the current values;
37 var propNames = [], propValues = [], propTypes = [], propLabels = [];
38 this.getAllProperties( propNames, propValues, propTypes, propLabels);
39 var n = propNames.length;
40 for (var i=0; i<n; i++) {
41 newMat.setProperty( propNames[i], propValues[i] );
42 }
43
44 return newMat;
45 };
46
47 this.init = function( world )
48 {
49 // save the world
50 if (world) this.setWorld( world );
51
52 // set up the shader
53 this._shader = new jshader();
54 this._shader.def = squareTunnelMaterialDef;
55 this._shader.init();
56
57 // set up the material node
58 this._materialNode = createMaterialNode("squareTunnelMaterial");
59 this._materialNode.setShader(this._shader);
60
61 this._time = 0;
62 if (this._shader && this._shader['default']) {
63 this._shader['default'].u_time.set( [this._time] );
64 }
65
66 // set the shader values in the shader
67 this.updateTexture();
68 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
69 this.update( 0 );
70 }
71};
72
73///////////////////////////////////////////////////////////////////////////////////////
74// RDGE shader
75
76// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
77var squareTunnelMaterialDef =
78{'shaders':
79 {
80 'defaultVShader':"assets/shaders/Basic.vert.glsl",
81 'defaultFShader':"assets/shaders/SquareTunnel.frag.glsl"
82 },
83 'techniques':
84 {
85 'default':
86 [
87 {
88 'vshader' : 'defaultVShader',
89 'fshader' : 'defaultFShader',
90 // attributes
91 'attributes' :
92 {
93 'vert' : { 'type' : 'vec3' },
94 'normal' : { 'type' : 'vec3' },
95 'texcoord' : { 'type' : 'vec2' }
96 },
97 // parameters
98 'params' :
99 {
100 'u_tex0': { 'type' : 'tex2d' },
101 'u_time' : { 'type' : 'float' },
102 'u_resolution' : { 'type' : 'vec2' }
103 },
104
105 // render states
106 'states' :
107 {
108 'depthEnable' : true,
109 'offset':[1.0, 0.1]
110 }
111 }
112 ]
113 }
114};
115
116SquareTunnelMaterial.prototype = new PulseMaterial();
117
118if (typeof exports === "object") {
119 exports.SquareTunnelMaterial = SquareTunnelMaterial;
120}