diff options
author | Nivesh Rajbhandari | 2012-03-12 16:25:28 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-12 16:25:28 -0700 |
commit | 5fb358d9e80a364d5f300d60b7a9fe0f773741e7 (patch) | |
tree | 2c4d5292b19c91697dffb542f369ec9dcb340f77 /js/lib/rdge/materials/water-material.js | |
parent | 5f9b67be3b8bdb391d021103c6bcee6be2f6cdf4 (diff) | |
parent | 69d90467865a1384725b2301901be2180c5a841f (diff) | |
download | ninja-5fb358d9e80a364d5f300d60b7a9fe0f773741e7.tar.gz |
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'js/lib/rdge/materials/water-material.js')
-rw-r--r-- | js/lib/rdge/materials/water-material.js | 126 |
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 | |||
7 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | ||
8 | |||
9 | /////////////////////////////////////////////////////////////////////// | ||
10 | // Class GLMaterial | ||
11 | // RDGE representation of a material. | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | var 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) | ||
79 | var 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 | |||
118 | WaterMaterial.prototype = new PulseMaterial(); | ||
119 | |||
120 | if (typeof exports === "object") { | ||
121 | exports.WaterMaterial = WaterMaterial; | ||
122 | } | ||
123 | |||
124 | |||
125 | |||
126 | |||