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/relief-tunnel-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/relief-tunnel-material.js')
-rw-r--r-- | js/lib/rdge/materials/relief-tunnel-material.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/relief-tunnel-material.js b/js/lib/rdge/materials/relief-tunnel-material.js new file mode 100644 index 00000000..20290895 --- /dev/null +++ b/js/lib/rdge/materials/relief-tunnel-material.js | |||
@@ -0,0 +1,122 @@ | |||
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 | var ReliefTunnelMaterial = function ReliefTunnelMaterial() { | ||
11 | /////////////////////////////////////////////////////////////////////// | ||
12 | // Instance variables | ||
13 | /////////////////////////////////////////////////////////////////////// | ||
14 | this._name = "ReliefTunnelMaterial"; | ||
15 | this._shaderName = "reliefTunnel"; | ||
16 | |||
17 | this._texMap = 'assets/images/rocky-normal.jpg'; | ||
18 | |||
19 | this._time = 0.0; | ||
20 | this._dTime = 0.01; | ||
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 | // Methods | ||
30 | /////////////////////////////////////////////////////////////////////// | ||
31 | // duplcate method requirde | ||
32 | this.dup = function( world ) { | ||
33 | // allocate a new uber material | ||
34 | var newMat = new ReliefTunnelMaterial(); | ||
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 | // save the world | ||
49 | if (world) this.setWorld( world ); | ||
50 | |||
51 | // set up the shader | ||
52 | this._shader = new jshader(); | ||
53 | this._shader.def = reliefTunnelMaterialDef; | ||
54 | this._shader.init(); | ||
55 | |||
56 | // set up the material node | ||
57 | this._materialNode = createMaterialNode("reliefTunnelMaterial"); | ||
58 | this._materialNode.setShader(this._shader); | ||
59 | |||
60 | this._time = 0; | ||
61 | if (this._shader && this._shader['default']) { | ||
62 | this._shader['default'].u_time.set( [this._time] ); | ||
63 | } | ||
64 | |||
65 | // set the shader values in the shader | ||
66 | this.updateTexture(); | ||
67 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | ||
68 | this.update( 0 ); | ||
69 | } | ||
70 | }; | ||
71 | |||
72 | /////////////////////////////////////////////////////////////////////////////////////// | ||
73 | // RDGE shader | ||
74 | |||
75 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
76 | var reliefTunnelMaterialDef = | ||
77 | {'shaders': | ||
78 | { | ||
79 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
80 | 'defaultFShader':"assets/shaders/ReliefTunnel.frag.glsl" | ||
81 | }, | ||
82 | 'techniques': | ||
83 | { | ||
84 | 'default': | ||
85 | [ | ||
86 | { | ||
87 | 'vshader' : 'defaultVShader', | ||
88 | 'fshader' : 'defaultFShader', | ||
89 | // attributes | ||
90 | 'attributes' : | ||
91 | { | ||
92 | 'vert' : { 'type' : 'vec3' }, | ||
93 | 'normal' : { 'type' : 'vec3' }, | ||
94 | 'texcoord' : { 'type' : 'vec2' } | ||
95 | }, | ||
96 | // parameters | ||
97 | 'params' : | ||
98 | { | ||
99 | 'u_tex0': { 'type' : 'tex2d' }, | ||
100 | 'u_time' : { 'type' : 'float' }, | ||
101 | 'u_resolution' : { 'type' : 'vec2' } | ||
102 | }, | ||
103 | |||
104 | // render states | ||
105 | 'states' : | ||
106 | { | ||
107 | 'depthEnable' : true, | ||
108 | 'offset':[1.0, 0.1] | ||
109 | } | ||
110 | } | ||
111 | ] | ||
112 | } | ||
113 | }; | ||
114 | |||
115 | ReliefTunnelMaterial.prototype = new PulseMaterial(); | ||
116 | |||
117 | if (typeof exports === "object") { | ||
118 | exports.ReliefTunnelMaterial = ReliefTunnelMaterial; | ||
119 | } | ||
120 | |||
121 | |||
122 | |||