diff options
Diffstat (limited to 'js/helper-classes/RDGE/runtime/RuntimeMaterial.js')
-rw-r--r-- | js/helper-classes/RDGE/runtime/RuntimeMaterial.js | 103 |
1 files changed, 94 insertions, 9 deletions
diff --git a/js/helper-classes/RDGE/runtime/RuntimeMaterial.js b/js/helper-classes/RDGE/runtime/RuntimeMaterial.js index 5fe29f93..ceabbaa5 100644 --- a/js/helper-classes/RDGE/runtime/RuntimeMaterial.js +++ b/js/helper-classes/RDGE/runtime/RuntimeMaterial.js | |||
@@ -144,11 +144,14 @@ function RuntimeRadialGradientMaterial() | |||
144 | this.inheritedFrom = RuntimeMaterial; | 144 | this.inheritedFrom = RuntimeMaterial; |
145 | this.inheritedFrom(); | 145 | this.inheritedFrom(); |
146 | 146 | ||
147 | this._name = "RadialGradientMaterial"; | ||
148 | this._shaderName = "radialGradient"; | ||
149 | |||
147 | // setup default values | 150 | // setup default values |
148 | this._color1 = [0.25,0,0,1]; this._colorStop1 = 0.0; | 151 | this._color1 = [1,0,0,1]; this._colorStop1 = 0.0; |
149 | this._color2 = [0,0.25,0,1]; this._colorStop2 = 0.3; | 152 | this._color2 = [0,1,0,1]; this._colorStop2 = 0.3; |
150 | this._color3 = [0,0.25,0,1]; this._colorStop3 = 0.6; | 153 | this._color3 = [0,1,0,1]; this._colorStop3 = 0.6; |
151 | this._color4 = [0,0.25,0,1]; this._colorStop4 = 1.0; | 154 | this._color4 = [0,1,0,1]; this._colorStop4 = 1.0; |
152 | 155 | ||
153 | this.init = function() | 156 | this.init = function() |
154 | { | 157 | { |
@@ -171,7 +174,7 @@ function RuntimeRadialGradientMaterial() | |||
171 | this._shader.default.u_colorStop3.set( [this._colorStop3] ); | 174 | this._shader.default.u_colorStop3.set( [this._colorStop3] ); |
172 | this._shader.default.u_colorStop4.set( [this._colorStop4] ); | 175 | this._shader.default.u_colorStop4.set( [this._colorStop4] ); |
173 | 176 | ||
174 | if (this._angle) | 177 | if (this._angle !== undefined) |
175 | this._shader.default.u_cos_sin_angle.set([Math.cos(this._angle), Math.sin(this._angle)]); | 178 | this._shader.default.u_cos_sin_angle.set([Math.cos(this._angle), Math.sin(this._angle)]); |
176 | } | 179 | } |
177 | } | 180 | } |
@@ -191,11 +194,11 @@ function RuntimeRadialGradientMaterial() | |||
191 | this._color4 = eval( "[" + colorStr + "]" ); | 194 | this._color4 = eval( "[" + colorStr + "]" ); |
192 | 195 | ||
193 | this._colorStop1 = Number( getPropertyFromString( "colorStop1: ", importStr ) ); | 196 | this._colorStop1 = Number( getPropertyFromString( "colorStop1: ", importStr ) ); |
194 | this._colorStop1 = Number( getPropertyFromString( "colorStop2: ", importStr ) ); | 197 | this._colorStop2 = Number( getPropertyFromString( "colorStop2: ", importStr ) ); |
195 | this._colorStop1 = Number( getPropertyFromString( "colorStop3: ", importStr ) ); | 198 | this._colorStop3 = Number( getPropertyFromString( "colorStop3: ", importStr ) ); |
196 | this._colorStop1 = Number( getPropertyFromString( "colorStop4: ", importStr ) ); | 199 | this._colorStop4 = Number( getPropertyFromString( "colorStop4: ", importStr ) ); |
197 | 200 | ||
198 | if (this._angle) | 201 | if (this._angle !== undefined) |
199 | this._angle = getPropertyFromString( "angle: ", importStr ); | 202 | this._angle = getPropertyFromString( "angle: ", importStr ); |
200 | } | 203 | } |
201 | 204 | ||
@@ -207,8 +210,90 @@ function RuntimeLinearGradientMaterial() | |||
207 | this.inheritedFrom = RuntimeRadialGradientMaterial; | 210 | this.inheritedFrom = RuntimeRadialGradientMaterial; |
208 | this.inheritedFrom(); | 211 | this.inheritedFrom(); |
209 | 212 | ||
213 | this._name = "LinearGradientMaterial"; | ||
214 | this._shaderName = "linearGradient"; | ||
215 | |||
210 | // the only difference between linear & radial gradient is the existance of an angle for linear. | 216 | // the only difference between linear & radial gradient is the existance of an angle for linear. |
211 | this._angle = 0.0; | 217 | this._angle = 0.0; |
212 | } | 218 | } |
213 | 219 | ||
220 | function RuntimeBumpMetalMaterial() | ||
221 | { | ||
222 | // inherit the members of RuntimeMaterial | ||
223 | this.inheritedFrom = RuntimeMaterial; | ||
224 | this.inheritedFrom(); | ||
225 | |||
226 | this._name = "BumpMetalMaterial"; | ||
227 | this._shaderName = "bumpMetal"; | ||
228 | |||
229 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; | ||
230 | this._diffuseTexture = "assets/images/metal.png"; | ||
231 | this._specularTexture = "assets/images/silver.png"; | ||
232 | this._normalTexture = "assets/images/normalMap.png"; | ||
233 | |||
234 | this.import = function( importStr ) | ||
235 | { | ||
236 | this._lightDiff = eval( "[" + getPropertyFromString( "lightDiff: ", importStr ) + "]" ); | ||
237 | this._diffuseTexture = getPropertyFromString( "diffuseTexture: ", importStr ); | ||
238 | this._specularTexture = getPropertyFromString( "specularTexture: ", importStr ); | ||
239 | this._normalTexture = getPropertyFromString( "normalMap: ", importStr ); | ||
240 | } | ||
241 | |||
242 | this.init = function() | ||
243 | { | ||
244 | var material = this._materialNode; | ||
245 | if (material) | ||
246 | { | ||
247 | var technique = material.shaderProgram.default; | ||
248 | var renderer = g_Engine.getContext().renderer; | ||
249 | if (renderer && technique) | ||
250 | { | ||
251 | if (this._shader && this._shader.default) | ||
252 | { | ||
253 | technique.u_light0Diff.set( this._lightDiff ); | ||
254 | |||
255 | var tex; | ||
256 | var wrap = 'REPEAT', mips = true; | ||
257 | if (this._diffuseTexture) | ||
258 | { | ||
259 | tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); | ||
260 | if (tex) technique.u_colMap.set( tex ); | ||
261 | |||
262 | } | ||
263 | if (this._normalTexture) | ||
264 | { | ||
265 | tex = renderer.getTextureByName(this._normalTexture, wrap, mips ); | ||
266 | if (tex) technique.u_normalMap.set( tex ); | ||
267 | } | ||
268 | if (this._specularTexture) | ||
269 | { | ||
270 | tex = renderer.getTextureByName(this._specularTexture, wrap, mips ); | ||
271 | technique.u_glowMap.set( tex ); | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /* | ||
279 | this.update = function( time ) | ||
280 | { | ||
281 | var material = this._materialNode; | ||
282 | if (material) | ||
283 | { | ||
284 | var technique = material.shaderProgram.default; | ||
285 | var renderer = g_Engine.getContext().renderer; | ||
286 | if (renderer && technique) | ||
287 | { | ||
288 | if (this._shader && this._shader.default) | ||
289 | this._shader.default.u_time.set( [this._time] ); | ||
290 | this._time += this._dTime; | ||
291 | if (this._time > 200.0) this._time = 0.0; | ||
292 | } | ||
293 | } | ||
294 | } | ||
295 | */ | ||
296 | } | ||
297 | |||
298 | |||
214 | 299 | ||