aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/water-material.js
diff options
context:
space:
mode:
authorJon Reid2012-04-05 16:36:22 -0700
committerJon Reid2012-04-05 16:36:22 -0700
commiteb694fa5d39733264bce7ba832aabbe9c3d6c81e (patch)
tree049aaa66a6621e9f54b33b9861f50c20667ba0e3 /js/lib/rdge/materials/water-material.js
parenta8ea8f377919c7f1a6af69311f55fd57727d9058 (diff)
parente186c49247689b5c2df6125037e2473636701d17 (diff)
downloadninja-eb694fa5d39733264bce7ba832aabbe9c3d6c81e.tar.gz
Merge remote-tracking branch 'ninja-jduran/TimelineUber' into timeline-local
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 b7413f55..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,203 +14,202 @@ 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 //this._texMap = 'assets/images/powderblue.png';
22 22
23 this._time = 0.0; 23 this._time = 0.0;
24 this._dTime = 0.01; 24 this._dTime = 0.01;
25 25
26 /////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////
27 // Properties 27 // Properties
28 /////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////
29 // all defined in parent PulseMaterial.js 29 // all defined in parent PulseMaterial.js
30 // load the local default value 30 // load the local default value
31 this._propValues = []; 31 this._propValues = [];
32 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 32 this._propValues[this._propNames[0]] = this._texMap.slice(0);
33 33
34 /////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////
35 // Methods 35 // Methods
36 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
37 // duplcate method requirde 37 // duplcate method requirde
38 this.dup = function( world ) { 38 this.dup = function (world) {
39 // allocate a new uber material 39 // allocate a new uber material
40 var newMat = new WaterMaterial(); 40 var newMat = new WaterMaterial();
41 41
42 // copy over the current values; 42 // copy over the current values;
43 var propNames = [], propValues = [], propTypes = [], propLabels = []; 43 var propNames = [], propValues = [], propTypes = [], propLabels = [];
44 this.getAllProperties( propNames, propValues, propTypes, propLabels); 44 this.getAllProperties(propNames, propValues, propTypes, propLabels);
45 var n = propNames.length; 45 var n = propNames.length;
46 for (var i=0; i<n; i++) 46 for (var i = 0; i < n; i++)
47 newMat.setProperty( propNames[i], propValues[i] ); 47 newMat.setProperty(propNames[i], propValues[i]);
48 48
49 return newMat; 49 return newMat;
50 }; 50 };
51 51
52 this.init = function( world ) { 52 this.init = function (world) {
53 // save the world 53 // save the world
54 if (world) this.setWorld( world ); 54 if (world) this.setWorld(world);
55 55
56 // set up the shader 56 // set up the shader
57 this._shader = new jshader(); 57 this._shader = new RDGE.jshader();
58 this._shader.def = waterMaterialDef; 58 this._shader.def = waterMaterialDef;
59 this._shader.init(); 59 this._shader.init();
60 60
61 // set up the material node 61 // set up the material node
62 this._materialNode = createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID()); 62 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID());
63 this._materialNode.setShader(this._shader); 63 this._materialNode.setShader(this._shader);
64 64
65 this._time = 0; 65 this._time = 0;
66 if (this._shader && this._shader['default']) { 66 if (this._shader && this._shader['default']) {
67 this._shader['default'].u_time.set( [this._time] ); 67 this._shader['default'].u_time.set([this._time]);
68 } 68 }
69 69
70 // set the shader values in the shader 70 // set the shader values in the shader
71 this.updateTexture(); 71 this.updateTexture();
72 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); 72 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
73 this.update( 0 ); 73 this.update(0);
74 } 74 };
75}; 75};
76 76
77/////////////////////////////////////////////////////////////////////////////////////// 77///////////////////////////////////////////////////////////////////////////////////////
78// RDGE shader 78// RDGE shader
79 79
80// 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)
81var waterMaterialDef = 81var waterMaterialDef =
82{'shaders': 82{ 'shaders':
83 { 83 {
84 'defaultVShader':"assets/shaders/Basic.vert.glsl", 84 'defaultVShader': "assets/shaders/Basic.vert.glsl",
85 'defaultFShader':"assets/shaders/Water2.frag.glsl" 85 'defaultFShader': "assets/shaders/Water2.frag.glsl"
86 }, 86 },
87 'techniques': 87 'techniques':
88 { 88 {
89 'default': 89 'default':
90 [ 90 [
91 { 91 {
92 'vshader' : 'defaultVShader', 92 'vshader': 'defaultVShader',
93 'fshader' : 'defaultFShader', 93 'fshader': 'defaultFShader',
94 // attributes 94 // attributes
95 'attributes' : 95 'attributes':
96 { 96 {
97 'vert' : { 'type' : 'vec3' }, 97 'vert': { 'type': 'vec3' },
98 'normal' : { 'type' : 'vec3' }, 98 'normal': { 'type': 'vec3' },
99 'texcoord' : { 'type' : 'vec2' } 99 'texcoord': { 'type': 'vec2' }
100 }, 100 },
101 // parameters 101 // parameters
102 'params' : 102 'params':
103 { 103 {
104 'u_tex0': { 'type' : 'tex2d' }, 104 'u_tex0': { 'type': 'tex2d' },
105 'u_time' : { 'type' : 'float' }, 105 'u_time': { 'type': 'float' },
106 'u_resolution' : { 'type' : 'vec2' } 106 'u_resolution': { 'type': 'vec2' }
107 }, 107 },
108 108
109 // render states 109 // render states
110 'states' : 110 'states':
111 { 111 {
112 'depthEnable' : true, 112 'depthEnable': true,
113 'offset':[1.0, 0.1] 113 'offset': [1.0, 0.1]
114 } 114 }
115 } 115 }
116 ] 116 ]
117 } 117 }
118}; 118};
119 119
120var ParisMaterial = function ParisMaterial() 120var ParisMaterial = function ParisMaterial() {
121{ 121 // initialize the inherited members
122 // initialize the inherited members 122 this.inheritedFrom = WaterMaterial;
123 this.inheritedFrom = WaterMaterial; 123 this.inheritedFrom();
124 this.inheritedFrom();
125 124
126 this._name = "ParisMaterial"; 125 this._name = "ParisMaterial";
127 this._shaderName = "paris"; 126 this._shaderName = "paris";
128 127
129 this._texMap = 'assets/images/paris.png'; 128 this._texMap = 'assets/images/paris.png';
130 this._propValues[ this._propNames[0] ] = this._texMap.slice(0); 129 this._propValues[this._propNames[0]] = this._texMap.slice(0);
131 130
132 this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; 131 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
133 this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); 132 this._propValues[this._propNames[1]] = this._diffuseColor.slice();
134 133
135 // duplcate method requirde 134 // duplcate method requirde