diff options
author | hwc487 | 2012-05-08 16:14:28 -0700 |
---|---|---|
committer | hwc487 | 2012-05-08 16:14:28 -0700 |
commit | 24417212f9fad7e992697e9370047fcf2f037913 (patch) | |
tree | 249ef89e903e0bc0cf32b237521ee4b0439b9280 /js/lib/rdge/materials | |
parent | 7af54816bb6311421f976661d07b7776d5cd37c9 (diff) | |
download | ninja-24417212f9fad7e992697e9370047fcf2f037913.tar.gz |
WebGL linear gradients to match CSS
Diffstat (limited to 'js/lib/rdge/materials')
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 51a7430c..0df9511e 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | ||
9 | 10 | ||
10 | var LinearGradientMaterial = function LinearGradientMaterial() { | 11 | var LinearGradientMaterial = function LinearGradientMaterial() { |
11 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
@@ -245,9 +246,46 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
245 | this._shader['default'].u_colorStop4.set([s]); | 246 | this._shader['default'].u_colorStop4.set([s]); |
246 | 247 | ||
247 | this.setAngle(this.getAngle()); | 248 | this.setAngle(this.getAngle()); |
248 | } | 249 | |
250 | this._shader['default'].u_texTransform.set( [1,0,0, 0,1,0, 0,0,1] ); | ||
251 | } | ||
249 | }; | 252 | }; |
250 | 253 | ||
254 | this.fitToPrimitive = function( prim ) | ||
255 | { | ||
256 | /* | ||
257 | var bounds = ShapePrimitive.getBounds( prim ); | ||
258 | if (bounds) | ||
259 | { | ||
260 | var dx = Math.abs( bounds[3] - bounds[0] ), | ||
261 | dy = Math.abs( bounds[4] - bounds[1] ); | ||
262 | if (dy == 0) dy = 1.0; | ||
263 | if (dx == 0) dx = 1.0; | ||
264 | var xScale = 2.0, yScale = 2.0; | ||
265 | if (dx > dy) | ||
266 | yScale *= dy/dx; | ||
267 | else | ||
268 | xScale *= dx/dy; | ||
269 | |||
270 | // build the matrix - the translation to the origin, the scale, | ||
271 | // and the translation back to the center (hard coded at (0.5, 0.5) for now). | ||
272 | // the matrix is build directly instead of with matrix multiplications | ||
273 | // for efficiency, not to mention that the multiplication function does | ||
274 | // not exist for mat3's. | ||
275 | // the matrix as laid out below looks transposed - order is columnwise. | ||
276 | var xCtr = 0.5, yCtr = 0.5; | ||
277 | this._textureTransform = [ | ||
278 | xScale, 0.0, 0.0, | ||
279 | 0.0, yScale, 0.0, | ||
280 | 0.0, 0.0, 1.0 | ||
281 | ]; | ||
282 | |||
283 | if (this._shader && this._shader['default']) | ||
284 | this._shader['default'].u_texTransform.set( this._textureTransform ); | ||
285 | } | ||
286 | */ | ||
287 | }; | ||
288 | |||
251 | this.exportJSON = function () { | 289 | this.exportJSON = function () { |
252 | var jObj = | 290 | var jObj = |
253 | { | 291 | { |
@@ -367,7 +405,8 @@ var linearGradientMaterialDef = | |||
367 | 'u_colorStop2': { 'type' : 'float' }, | 405 | 'u_colorStop2': { 'type' : 'float' }, |
368 | 'u_colorStop3': { 'type' : 'float' }, | 406 | 'u_colorStop3': { 'type' : 'float' }, |
369 | 'u_colorStop4': { 'type' : 'float' }, | 407 | 'u_colorStop4': { 'type' : 'float' }, |
370 | 'u_cos_sin_angle' : { 'type' : 'vec2' } | 408 | 'u_cos_sin_angle': { 'type' : 'vec2' }, |
409 | 'u_texTransform': { 'type' : 'mat3' } | ||
371 | //'u_colorCount': {'type' : 'int' } | 410 | //'u_colorCount': {'type' : 'int' } |
372 | 411 | ||
373 | }, | 412 | }, |