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.js310
1 files changed, 130 insertions, 180 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js
index 37836636..3e63ddb6 100644
--- a/js/lib/rdge/materials/water-material.js
+++ b/js/lib/rdge/materials/water-material.js
@@ -5,73 +5,76 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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;
8 9
9/////////////////////////////////////////////////////////////////////// 10///////////////////////////////////////////////////////////////////////
10// Class GLMaterial 11// Class GLMaterial
11// RDGE representation of a material. 12// RDGE representation of a material.
12/////////////////////////////////////////////////////////////////////// 13///////////////////////////////////////////////////////////////////////
13var WaterMaterial = function WaterMaterial() { 14var WaterMaterial = function WaterMaterial()
14 /////////////////////////////////////////////////////////////////////// 15{
15 // Instance variables 16 ///////////////////////////////////////////////////////////////////////
16 /////////////////////////////////////////////////////////////////////// 17 // Instance variables
17 this._name = "WaterMaterial"; 18 ///////////////////////////////////////////////////////////////////////
18 this._shaderName = "water"; 19 this._name = "WaterMaterial";
19 20 this._shaderName = "water";
20 this._texMap = 'assets/images/rocky-normal.jpg'; 21
21 //this._texMap = 'assets/images/powderblue.png'; 22 this._defaultTexMap = 'assets/images/rocky-normal.jpg';
22 23
23 this._time = 0.0; 24 this._time = 0.0;
24 this._dTime = 0.01; 25 this._dTime = 0.01;
25 26
26 /////////////////////////////////////////////////////////////////////// 27 this.isAnimated = function() { return true; };
27 // Properties 28 this.getShaderDef = function() { return waterMaterialDef; };
28 /////////////////////////////////////////////////////////////////////// 29
29 // all defined in parent PulseMaterial.js 30 ///////////////////////////////////////////////////////////////////////
30 // load the local default value 31 // Properties
31 this._propValues = []; 32 ///////////////////////////////////////////////////////////////////////
32 this._propValues[this._propNames[0]] = this._texMap.slice(0); 33 // all defined in parent PulseMaterial.js
33 34 // load the local default value
34 /////////////////////////////////////////////////////////////////////// 35 this._propNames = ["u_tex0", "u_emboss", "u_delta", "u_intensity", "u_speed"];
35 // Methods 36 this._propLabels = ["Texture map", "Emboss", "Delta", "Intensity", "Speed"];
36 /////////////////////////////////////////////////////////////////////// 37 this._propTypes = ["file", "float", "float", "float", "float"];
37 // duplcate method requirde 38
38 this.dup = function (world) { 39 var u_tex_index = 0,
39 // allocate a new uber material 40 u_emboss_index = 1,
40 var newMat = new WaterMaterial(); 41 u_delta_index = 2,
41 42 u_intensity_index = 3,
42 // copy over the current values; 43 u_speed_index = 4;
43 var propNames = [], propValues = [], propTypes = [], propLabels = []; 44
44 this.getAllProperties(propNames, propValues, propTypes, propLabels); 45 this._propValues = [];
45 var n = propNames.length; 46 this._propValues[ this._propNames[u_tex_index ] ] = this._defaultTexMap.slice(0);
46 for (var i = 0; i < n; i++) 47 this._propValues[ this._propNames[u_emboss_index ] ] = 0.3;
47 newMat.setProperty(propNames[i], propValues[i]); 48 this._propValues[ this._propNames[u_delta_index ] ] = 20.0;
48 49 this._propValues[ this._propNames[u_intensity_index ] ] = 3.0;
49 return newMat; 50 this._propValues[ this._propNames[u_speed_index ] ] = 0.2;
50 }; 51
51 52 ///////////////////////////////////////////////////////////////////////
52 this.init = function (world) { 53 // Methods
53 // save the world 54 ///////////////////////////////////////////////////////////////////////
54 if (world) this.setWorld(world); 55
55 56 this.init = function (world) {
56 // set up the shader 57 // save the world
57 this._shader = new RDGE.jshader(); 58 if (world) this.setWorld(world);
58 this._shader.def = waterMaterialDef; 59
59 this._shader.init(); 60 // set up the shader
60 61 this._shader = new RDGE.jshader();
61 // set up the material node 62 this._shader.def = waterMaterialDef;
62 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID()); 63 this._shader.init();
63 this._materialNode.setShader(this._shader); 64
64 65 // set up the material node
65 this._time = 0; 66 this._materialNode = RDGE.createMaterialNode("waterMaterial" + "_" + world.generateUniqueNodeID());
66 if (this._shader && this._shader['default']) { 67 this._materialNode.setShader(this._shader);
67 this._shader['default'].u_time.set([this._time]); 68
68 } 69 this._time = 0;
69 70 if (this._shader && this._shader['default'])
70 // set the shader values in the shader 71 this._shader['default'].u_time.set([this._time]);
71 this.updateTexture(); 72
72 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]); 73 // set the shader values in the shader
73 this.update(0); 74 this.setShaderValues();
74 }; 75 this.setResolution([world.getViewportWidth(), world.getViewportHeight()]);
76 this.update(0);
77 };
75}; 78};
76 79
77/////////////////////////////////////////////////////////////////////////////////////// 80///////////////////////////////////////////////////////////////////////////////////////
@@ -81,148 +84,95 @@ var WaterMaterial = function WaterMaterial() {
81var waterMaterialDef = 84var waterMaterialDef =
82{ 'shaders': 85{ 'shaders':
83 { 86 {
84 'defaultVShader': "assets/shaders/Basic.vert.glsl", 87 'defaultVShader': "assets/shaders/Basic.vert.glsl",
85 'defaultFShader': "assets/shaders/Water2.frag.glsl" 88 'defaultFShader': "assets/shaders/Water2.frag.glsl"
86 }, 89 },
87 'techniques': 90 'techniques':
88 { 91 {
89 'default': 92 'default':
90 [ 93 [
91 { 94 {
92 'vshader': 'defaultVShader', 95 'vshader': 'defaultVShader',
93 'fshader': 'defaultFShader', 96 'fshader': 'defaultFShader',
94 // attributes 97 // attributes
95 'attributes': 98 'attributes':
96 { 99 {
97 'vert': { 'type': 'vec3' }, 100 'vert': { 'type': 'vec3' },
98 'normal': { 'type': 'vec3' }, 101 'normal': { 'type': 'vec3' },
99 'texcoord': { 'type': 'vec2' } 102 'texcoord': { 'type': 'vec2' }
100 }, 103 },
101 // parameters 104 // parameters
102 'params': 105 'params':
103 { 106 {
104 'u_tex0': { 'type': 'tex2d' }, 107 'u_tex0': { 'type': 'tex2d' },
105 'u_time': { 'type': 'float' }, 108 'u_time': { 'type': 'float' },
106 'u_resolution': { 'type': 'vec2' } 109 'u_emboss': { 'type': 'float' },
110 'u_delta': { 'type': 'float' },
111 'u_speed': { 'type': 'float' },
112 'u_intensity': { 'type': 'float' },
113 'u_resolution': { 'type': 'vec2' }
107 }, 114 },
108 115
109 // render states 116 // render states
110 'states': 117 'states':
111 { 118 {
112 'depthEnable': true, 119 'depthEnable': true,
113 'offset': [1.0, 0.1] 120 'offset': [1.0, 0.1]
114 } 121 }
115 } 122 }
116 ] 123 ]
117 } 124 }
118}; 125};
119 126
120var ParisMaterial = function ParisMaterial() { 127var ParisMaterial = function ParisMaterial()
121 // initialize the inherited members 128{
122 this.inheritedFrom = WaterMaterial; 129 // initialize the inherited members
123 this.inheritedFrom(); 130 this.inheritedFrom = WaterMaterial;
124 131 this.inheritedFrom();
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