aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xassets/shaders/linearGradient.vert.glsl5
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js43
2 files changed, 45 insertions, 3 deletions
diff --git a/assets/shaders/linearGradient.vert.glsl b/assets/shaders/linearGradient.vert.glsl
index aac9cbee..f0800812 100755
--- a/assets/shaders/linearGradient.vert.glsl
+++ b/assets/shaders/linearGradient.vert.glsl
@@ -37,6 +37,7 @@ uniform float u_colorStop3;
37uniform float u_colorStop4; 37uniform float u_colorStop4;
38uniform vec2 u_cos_sin_angle; 38uniform vec2 u_cos_sin_angle;
39//uniform int u_colorCount; // currently using 4 39//uniform int u_colorCount; // currently using 4
40uniform mat3 u_texTransform;
40 41
41varying vec2 v_uv; 42varying vec2 v_uv;
42 43
@@ -44,5 +45,7 @@ varying vec2 v_uv;
44void main(void) 45void main(void)
45{ 46{
46 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; 47 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ;
47 v_uv = texcoord; 48 //v_uv = texcoord;
49 vec3 tmp = u_texTransform * vec3( texcoord, 1.0);
50 v_uv = tmp.xy;
48} 51}
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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material; 8var Material = require("js/lib/rdge/materials/material").Material;
9var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
9 10
10var LinearGradientMaterial = function LinearGradientMaterial() { 11var 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 },