aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/water-material.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 17:08:55 -0800
committerJonathan Duran2012-03-06 17:08:55 -0800
commitbb6a1d82b2884b410f5859cc0c2cafd380acbe6a (patch)
tree6ec3e960a0c38ce8fd88c9bc17f5227d072ebe76 /js/lib/rdge/materials/water-material.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
parent2e3943a8f751ec572066f168b58464c24b9f29e5 (diff)
downloadninja-bb6a1d82b2884b410f5859cc0c2cafd380acbe6a.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/lib/rdge/materials/water-material.js')
-rw-r--r--js/lib/rdge/materials/water-material.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js
new file mode 100644
index 00000000..92b96b18
--- /dev/null
+++ b/js/lib/rdge/materials/water-material.js
@@ -0,0 +1,126 @@
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
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13var WaterMaterial = function WaterMaterial() {
14 ///////////////////////////////////////////////////////////////////////
15 // Instance variables
16 ///////////////////////////////////////////////////////////////////////
17 this._name = "WaterMaterial";
18 this._shaderName = "water";
19
20 this._texMap = 'assets/images/rocky-normal.jpg';
21
22 this._time = 0.0;
23 this._dTime = 0.01;
24
25 ///////////////////////////////////////////////////////////////////////
26 // Properties
27 ///////////////////////////////////////////////////////////////////////
28 // all defined in parent PulseMaterial.js
29 // load the local default value
30 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
31
32 ///////////////////////////////////////////////////////////////////////
33 // Methods
34 ///////////////////////////////////////////////////////////////////////
35 // duplcate method requirde
36 this.dup = function( world ) {
37 // allocate a new uber material
38 var newMat = new WaterMaterial();
39
40 // copy over the current values;
41 var propNames = [], propValues = [], propTypes = [], propLabels = [];
42 this.getAllProperties( propNames, propValues, propTypes, propLabels);
43 var n = propNames.length;
44 for (var i=0; i<n; i++)
45 newMat.setProperty( propNames[i], propValues[i] );
46
47 return newMat;
48 };
49
50 this.init = function( world ) {
51 // save the world
52 if (world) this.setWorld( world );
53
54 // set up the shader
55 this._shader = new jshader();
56 this._shader.def = waterMaterialDef;
57 this._shader.init();
58
59 // set up the material node
60 this._materialNode = createMaterialNode("waterMaterial");
61 this._materialNode.setShader(this._shader);
62
63 this._time = 0;
64 if (this._shader && this._shader['default']) {
65 this._shader['default'].u_time.set( [this._time] );
66 }
67
68 // set the shader values in the shader
69 this.updateTexture();
70 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
71 this.update( 0 );
72 }
73};
74
75///////////////////////////////////////////////////////////////////////////////////////
76// RDGE shader
77
78// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
79var waterMaterialDef =
80{'shaders':
81 {
82 'defaultVShader':"assets/shaders/Basic.vert.glsl",
83 'defaultFShader':"assets/shaders/Water2.frag.glsl"
84 },
85 'techniques':
86 {
87 'default':
88 [
89 {
90 'vshader' : 'defaultVShader',
91 'fshader' : 'defaultFShader',
92 // attributes
93 'attributes' :
94 {
95 'vert' : { 'type' : 'vec3' },
96 'normal' : { 'type' : 'vec3' },
97 'texcoord' : { 'type' : 'vec2' }
98 },
99 // parameters
100 'params' :
101 {
102 'u_tex0': { 'type' : 'tex2d' },
103 'u_time' : { 'type' : 'float' },
104 'u_resolution' : { 'type' : 'vec2' }
105 },
106
107 // render states
108 'states' :
109 {
110 'depthEnable' : true,
111 'offset':[1.0, 0.1]
112 }
113 }
114 ]
115 }
116};
117
118WaterMaterial.prototype = new PulseMaterial();
119
120if (typeof exports === "object") {
121 exports.WaterMaterial = WaterMaterial;
122}
123
124
125
126