aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials')
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js14
-rwxr-xr-xjs/lib/rdge/materials/material.js4
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js43
3 files changed, 52 insertions, 9 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js
index 51a7430c..79f323db 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 ///////////////////////////////////////////////////////////////////////
@@ -132,12 +133,6 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
132 } 133 }
133 }; 134 };
134 135
135 // this.getColorCount = function() { return this._colorCount; };
136 // this.setColorCount = function(c) { this._colorCount = c;
137 // if (this._shader && this._shader['default'])
138 // this._shader['default'].u_colorCount.set([c]);
139 // };
140
141 this.getAngle = function () { 136 this.getAngle = function () {
142 return this._angle; 137 return this._angle;
143 }; 138 };
@@ -245,7 +240,9 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
245 this._shader['default'].u_colorStop4.set([s]); 240 this._shader['default'].u_colorStop4.set([s]);
246 241
247 this.setAngle(this.getAngle()); 242 this.setAngle(this.getAngle());
248 } 243
244 this._shader['default'].u_texTransform.set( [1,0,0, 0,1,0, 0,0,1] );
245 }
249 }; 246 };
250 247
251 this.exportJSON = function () { 248 this.exportJSON = function () {
@@ -367,7 +364,8 @@ var linearGradientMaterialDef =
367 'u_colorStop2': { 'type' : 'float' }, 364 'u_colorStop2': { 'type' : 'float' },
368 'u_colorStop3': { 'type' : 'float' }, 365 'u_colorStop3': { 'type' : 'float' },
369 'u_colorStop4': { 'type' : 'float' }, 366 'u_colorStop4': { 'type' : 'float' },
370 'u_cos_sin_angle' : { 'type' : 'vec2' } 367 'u_cos_sin_angle': { 'type' : 'vec2' },
368 'u_texTransform': { 'type' : 'mat3' }
371 //'u_colorCount': {'type' : 'int' } 369 //'u_colorCount': {'type' : 'int' }
372 370
373 }, 371 },
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index 276c7687..b96768b3 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -228,6 +228,10 @@ var Material = function GLMaterial( world ) {
228 // animated materials should implement the update method 228 // animated materials should implement the update method
229 }; 229 };
230 230
231 this.fitToPrimitive = function( prim ) {
232 // some materials need to preserve an aspect ratio - or someting else.
233 };
234
231 this.registerTexture = function( texture ) { 235 this.registerTexture = function( texture ) {
232 // the world needs to know about the texture map 236 // the world needs to know about the texture map
233 var world = this.getWorld(); 237 var world = this.getWorld();
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js
index dd40d31d..a671ee42 100755
--- a/js/lib/rdge/materials/radial-gradient-material.js
+++ b/js/lib/rdge/materials/radial-gradient-material.js
@@ -6,6 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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 RadialGradientMaterial = function RadialGradientMaterial() { 11var RadialGradientMaterial = function RadialGradientMaterial() {
11 /////////////////////////////////////////////////////////////////////// 12 ///////////////////////////////////////////////////////////////////////
@@ -24,6 +25,9 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
24 this._colorStop4 = 1.0; 25 this._colorStop4 = 1.0;
25 // this._colorCount = 4; 26 // this._colorCount = 4;
26 27
28 var s = Math.sqrt( 2.0 );
29 this._textureTransform = [s,0,0, 0,s,0, 0,0,1];
30
27 /////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////
28 // Property Accessors 32 // Property Accessors
29 /////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////
@@ -231,9 +235,45 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
231 this._shader['default'].u_colorStop3.set([s]); 235 this._shader['default'].u_colorStop3.set([s]);
232 s = this.getColorStop4(); 236 s = this.getColorStop4();
233 this._shader['default'].u_colorStop4.set([s]); 237 this._shader['default'].u_colorStop4.set([s]);
238
239 this._shader['default'].u_texTransform.set( this._textureTransform );
234 } 240 }
235 }; 241 };
236 242
243 this.fitToPrimitive = function( prim )
244 {
245 var bounds = ShapePrimitive.getBounds( prim );
246 if (bounds)
247 {
248 var dx = Math.abs( bounds[3] - bounds[0] ),
249 dy = Math.abs( bounds[4] - bounds[1] );
250 if (dy == 0) dy = 1.0;
251 if (dx == 0) dx = 1.0;
252 var xScale = 2.0, yScale = 2.0;
253 if (dx > dy)
254 yScale *= dy/dx;
255 else
256 xScale *= dx/dy;
257
258 // build the matrix - the translation to the origin, the scale,
259 // and the translation back to the center (hard coded at (0.5, 0.5) for now).
260 // the matrix is build directly instead of with matrix multiplications
261 // for efficiency, not to mention that the multiplication function does
262 // not exist for mat3's.
263 // the matrix as laid out below looks transposed - order is columnwise.
264 var xCtr = 0.5, yCtr = 0.5;
265 this._textureTransform = [
266 xScale, 0.0, 0.0,
267 0.0, yScale, 0.0,
268 xCtr*(1-xScale), yCtr*(1 - yScale), 1.0
269 ];
270
271 if (this._shader && this._shader['default'])
272 this._shader['default'].u_texTransform.set( this._textureTransform );
273
274 }
275 };
276
237 this.exportJSON = function () { 277 this.exportJSON = function () {
238 var jObj = 278 var jObj =
239 { 279 {
@@ -316,7 +356,8 @@ var radialGradientMaterialDef =
316 'u_colorStop1': { 'type': 'float' }, 356 'u_colorStop1': { 'type': 'float' },
317 'u_colorStop2': { 'type': 'float' }, 357 'u_colorStop2': { 'type': 'float' },
318 'u_colorStop3': { 'type': 'float' }, 358 'u_colorStop3': { 'type': 'float' },
319 'u_colorStop4': { 'type': 'float' } 359 'u_colorStop4': { 'type': 'float' },
360 'u_texTransform': { 'type' : 'mat3' }
320 //'u_colorCount': {'type' : 'int' } 361 //'u_colorCount': {'type' : 'int' }
321 }, 362 },
322 363