aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/water-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/water-material.js')
-rw-r--r--js/lib/rdge/materials/water-material.js244
1 files changed, 173 insertions, 71 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js
index cac5a249..37836636 100644
--- a/js/lib/rdge/materials/water-material.js
+++ b/js/lib/rdge/materials/water-material.js
@@ -1,8 +1,8 @@
1/* <copyright> 1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2This 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/> 3No 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. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ 5</copyright> */
6 6
7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; 7var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
8 8
@@ -14,107 +14,209 @@ var WaterMaterial = function WaterMaterial() {
14 /////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////
15 // Instance variables 15 // Instance variables
16 /////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////
17 this._name = "WaterMaterial"; 17 this._name = "WaterMaterial";
18 this._shaderName = "water"; 18 this._shaderName = "water";
19 19
20 this._texMap = 'assets/images/rocky-normal.jpg'; 20 this._texMap = 'assets/images/rocky-normal.jpg';
21 //this._texMap = 'assets/images/powderblue.png';
21 22
22 this._time = 0.0; 23 this._time = 0.0;
23 this._dTime = 0.01; 24 this._dTime = 0.01;
24 25
25 /////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////
26 // Properties 27 // Properties
27 /////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////
28 // all defined in parent PulseMaterial.js 29 // all defined in parent PulseMaterial.js
29 // load the local default value 30 // load the local default value
30 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 31 this._propValues = [];
32 this._propValues[this._propNames[0]] = this._texMap.slice(0);
31 33
32 /////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////
33 // Methods 35 // Methods
34 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
35 // duplcate method requirde 37 // duplcate method requirde
36 this.dup = function( world ) { 38 this.dup = function (world) {
37 // allocate a new uber material 39 // allocate a new uber material
38 var newMat = new WaterMaterial(); 40 var newMat = new WaterMaterial();
39 41
40 // copy over the current values; 42 // copy over the current values;
41 var propNames = [], propValues = [], propTypes = [], propLabels = []; 43 var propNames = [], propValues = [], propTypes = [], propLabels = [];
42 this.getAllProperties( propNames, propValues, propTypes, propLabels); 44 this.getAllProperties(propNames, propValues, propTypes, propLabels);
43 var n = propNames.length; 45 var n = propNames.length;
44 for (var i=0; i<n; i++) 46 for (var i = 0; i < n; i++)
45 newMat.setProperty( propNames[i], propValues[i] ); 47 newMat.setProperty(propNames[i], propValues[i]);
46 48
47 return newMat; 49 return newMat;
48 }; 50 };
49 51
50 this.init = function( world ) { 52 this.init = function (world) {
51 // save the world 53 // save the world
52 if (world) this.setWorld( world ); 54 if (world) this.setWorld(world);
53 55
54 // set up the shader 56 // set up the shader
55 this._shader = new jshader(); 57 this._shader = new RDGE.jshader();
56 this._shader.def = waterMaterialDef; 58 this._shader.def = waterMaterialDef;
57 this._shader.init(); 59 this._shader.init();
58 60
59 // set up the material node 61 // set up the material node
60 this._materialNode = createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID()); 62 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID());
61 this._materialNode.setShader(this._shader); 63 this._materialNode.setShader(this._shader);
62 64
63 this._time = 0; 65 this._time = 0;
64 if (this._shader && this._shader['default']) { 66 if (this._shader && this._shader['default']) {
65 this._shader['default'].u_time.set( [this._time] ); 67 this._shader['default'].u_time.set([this._time]);
66 } 68 }
67 69
68 // set the shader values in the shader 70 // set the shader values in the shader
69 this.updateTexture(); 71 this.updateTexture();
70 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 72 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
71 this.update( 0 ); 73 this.update(0);
72 } 74 };
73}; 75};
74 76
75/////////////////////////////////////////////////////////////////////////////////////// 77///////////////////////////////////////////////////////////////////////////////////////
76// RDGE shader 78// RDGE shader
77 79
78// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 80// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
79var waterMaterialDef = 81var waterMaterialDef =
80{'shaders': 82{ 'shaders':
81 { 83 {
82 'defaultVShader':"assets/shaders/Basic.vert.glsl", 84 'defaultVShader': "assets/shaders/Basic.vert.glsl",
83 'defaultFShader':"assets/shaders/Water2.frag.glsl" 85 'defaultFShader': "assets/shaders/Water2.frag.glsl"
84 }, 86 },
85 'techniques': 87 'techniques':
86 { 88 {
87 'default': 89 'default':
88 [ 90 [
89 { 91 {
90 'vshader' : 'defaultVShader', 92 'vshader': 'defaultVShader',
91 'fshader' : 'defaultFShader', 93 'fshader': 'defaultFShader',
92 // attributes 94 // attributes
93 'attributes' : 95 'attributes':
94 { 96 {
95 'vert' : { 'type' : 'vec3' }, 97 'vert': { 'type': 'vec3' },
96 'normal' : { 'type' : 'vec3' }, 98 'normal': { 'type': 'vec3' },
97 'texcoord' : { 'type' : 'vec2' } 99 'texcoord': { 'type': 'vec2' }
98 }, 100 },
99 // parameters 101 // parameters
100 'params' : 102 'params':
101 { 103 {
102 'u_tex0': { 'type' : 'tex2d' }, 104 'u_tex0': { 'type': 'tex2d' },
103 'u_time' : { 'type' : 'float' }, 105 'u_time': { 'type': 'float' },
104 'u_resolution' : { 'type' : 'vec2' } 106 'u_resolution': { 'type': 'vec2' }
105 }, 107 },
106 108
107 // render states 109 // render states
108 'states' : 110 'states':
109 { 111 {
110 'depthEnable' : true, 112 'depthEnable': true,
111 'offset':[1.0, 0.1] 113 'offset': [1.0, 0.1]
112 } 114 }
113 } 115 }
114 ] 116 ]
115 } 117 }
116}; 118};
117 119
120var ParisMaterial = function ParisMaterial() {
121 // initialize the inherited members
122 this.inheritedFrom = WaterMaterial;
123 this.inheritedFrom();
124
125 this._name = "ParisMaterial";
126 this._shaderName = "paris";
127
128 this._texMap = 'assets/images/paris.png';
129 this._propValues[this._propNames[0]] = this._texMap.slice(0);
130
131 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
132 this._propValues[this._propNames[1]] = this._diffuseColor.slice();
133
134 // duplcate method requirde
135 this.dup = function (world) {
136 // allocate a new uber material
137 var newMat = new ParisMaterial();
138
139 // copy over the current values;
140 var propNames = [], propValues = [], propTypes = [], propLabels = [];
141 this.getAllProperties(propNames, propValues, propTypes, propLabels);
142 var n = propNames.length;
143 for (var i = 0; i < n; i++)
144 newMat.setProperty(propNames[i], propValues[i]);
145
146 return newMat;
147 };
148
149 this.init = function (world) {
150 // save the world
151 if (world) this.setWorld(world);
152
153 // set up the shader
154 this._shader = new RDGE.jshader();
155 this._shader.def = parisMaterialDef;
156 this._shader.init();