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