diff options
Diffstat (limited to 'js/lib/rdge/materials/water-material.js')
-rw-r--r-- | js/lib/rdge/materials/water-material.js | 105 |
1 files changed, 104 insertions, 1 deletions
diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js index 0c7badf5..ebc54119 100644 --- a/js/lib/rdge/materials/water-material.js +++ b/js/lib/rdge/materials/water-material.js | |||
@@ -18,6 +18,7 @@ var WaterMaterial = function 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; |
@@ -27,6 +28,7 @@ var WaterMaterial = function WaterMaterial() { | |||
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 |
31 | this._propValues = []; | ||
30 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | 32 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); |
31 | 33 | ||
32 | /////////////////////////////////////////////////////////////////////// | 34 | /////////////////////////////////////////////////////////////////////// |
@@ -57,7 +59,7 @@ var WaterMaterial = function WaterMaterial() { | |||
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 = RDGE.createMaterialNode("waterMaterial"); | 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; |
@@ -115,6 +117,107 @@ var waterMaterialDef = | |||
115 | } | 117 | } |
116 | }; | 118 | }; |
117 | 119 | ||
120 | var ParisMaterial = function ParisMaterial() | ||
121 | { | ||
122 | // initialize the inherited members | ||
123 | this.inheritedFrom = WaterMaterial; | ||
124 | this.inheritedFrom(); | ||
125 | |||
126 | this._name = "ParisMaterial"; | ||
127 | this._shaderName = "paris"; | ||
128 | |||
129 | this._texMap = 'assets/images/paris.png'; | ||
130 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | ||
131 | |||
132 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; | ||
133 | this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); | ||
134 | |||
135 | // duplcate method requirde | ||
136 | this.dup = function( world ) { | ||
137 | // allocate a new uber material | ||
138 | var newMat = new ParisMaterial(); | ||
139 | |||
140 | // copy over the current values; | ||
141 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
142 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
143 | var n = propNames.length; | ||
144 | for (var i=0; i<n; i++) | ||
145 | newMat.setProperty( propNames[i], propValues[i] ); | ||
146 | |||
147 | return newMat; | ||
148 | }; | ||
149 | |||
150 | this.init = function( world ) { | ||
151 | // save the world | ||
152 | if (world) this.setWorld( world ); | ||
153 | |||
154 | // set up the shader | ||
155 | this._shader = new jshader(); | ||
156 | this._shader.def = parisMaterialDef; | ||
157 | this._shader.init(); | ||
158 | |||
159 | // set up the material node | ||
160 | this._materialNode = createMaterialNode("parisMaterial" + "_" + world.generateUniqueNodeID()); | ||
161 | this._materialNode.setShader(this._shader); | ||
162 | |||
163 | this._time = 0; | ||
164 | if (this._shader && this._shader['default']) { | ||
165 | this._shader['default'].u_time.set( [this._time] ); | ||
166 | } | ||
167 | |||
168 | // set the shader values in the shader | ||
169 | this.updateTexture(); | ||
170 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | ||
171 | this.update( 0 ); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | ParisMaterial.prototype = new PulseMaterial(); | ||
176 | if (typeof exports === "object") { | ||
177 | exports.ParisMaterial = ParisMaterial; | ||
178 | } | ||
179 | |||
180 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
181 | var parisMaterialDef = | ||
182 | {'shaders': | ||
183 | { | ||
184 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
185 | 'defaultFShader':"assets/shaders/Paris.frag.glsl" | ||
186 | }, | ||
187 | 'techniques': | ||
188 | { | ||
189 | 'default': | ||
190 | [ | ||
191 | { | ||
192 | 'vshader' : 'defaultVShader', | ||
193 | 'fshader' : 'defaultFShader', | ||
194 | // attributes | ||
195 | 'attributes' : | ||
196 | { | ||
197 | 'vert' : { 'type' : 'vec3' }, | ||
198 | 'normal' : { 'type' : 'vec3' }, | ||
199 | 'texcoord' : { 'type' : 'vec2' } | ||
200 | }, | ||
201 | // parameters | ||
202 | 'params' : | ||
203 | { | ||
204 | 'u_tex0': { 'type' : 'tex2d' }, | ||
205 | 'u_time' : { 'type' : 'float' }, | ||
206 | 'u_resolution' : { 'type' : 'vec2' } | ||
207 | }, | ||
208 | |||
209 | // render states | ||
210 | 'states' : | ||
211 | { | ||
212 | 'depthEnable' : true, | ||
213 | 'offset':[1.0, 0.1] | ||
214 | } | ||
215 | } | ||
216 | ] | ||
217 | } | ||
218 | }; | ||
219 | |||
220 | |||
118 | WaterMaterial.prototype = new PulseMaterial(); | 221 | WaterMaterial.prototype = new PulseMaterial(); |
119 | 222 | ||
120 | if (typeof exports === "object") { | 223 | if (typeof exports === "object") { |