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.js36
-rwxr-xr-xjs/lib/rdge/materials/material.js4
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js70
3 files changed, 92 insertions, 18 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js
index 51a7430c..9b331fa7 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 ///////////////////////////////////////////////////////////////////////
@@ -25,6 +26,8 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
25 // this._colorCount = 4; 26 // this._colorCount = 4;
26 this._angle = 0.0; // the shader takes [cos(a), sin(a)] 27 this._angle = 0.0; // the shader takes [cos(a), sin(a)]
27 28
29 this._textureTransform = [1,0,0, 0,1,0, 0,0,1];
30
28 /////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////
29 // Property Accessors 32 // Property Accessors
30 /////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////
@@ -132,12 +135,6 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
132 } 135 }
133 }; 136 };
134 137
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 () { 138 this.getAngle = function () {
142 return this._angle; 139 return this._angle;
143 }; 140 };
@@ -200,7 +197,21 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
200 // Methods 197 // Methods
201 /////////////////////////////////////////////////////////////////////// 198 ///////////////////////////////////////////////////////////////////////
202 // duplcate method requirde 199 // duplcate method requirde
203 this.dup = function () { return new LinearGradientMaterial(); }; 200 this.dup = function () {
201 // allocate a new material
202 var newMat = new LinearGradientMaterial();
203
204 // copy over the current values;
205 var propNames = [], propValues = [], propTypes = [], propLabels = [];
206 this.getAllProperties( propNames, propValues, propTypes, propLabels);
207 var n = propNames.length;
208 for (var i=0; i<n; i++) {
209 newMat.setProperty( propNames[i], propValues[i] );
210 }
211 newMat._textureTransform = this._textureTransform.slice();
212
213 return newMat;
214 };
204 215
205 this.init = function (world) { 216 this.init = function (world) {
206 this.setWorld(world); 217 this.setWorld(world);
@@ -245,7 +256,9 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
245 this._shader['default'].u_colorStop4.set([s]); 256 this._shader['default'].u_colorStop4.set([s]);
246 257
247 this.setAngle(this.getAngle()); 258 this.setAngle(this.getAngle());
248 } 259
260 this._shader['default'].u_texTransform.set( this._textureTransform );
261 }
249 }; 262 };
250 263
251 this.exportJSON = function () { 264 this.exportJSON = function () {
@@ -261,7 +274,8 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
261 'colorStop2': this.getColorStop2(), 274 'colorStop2': this.getColorStop2(),
262 'colorStop3': this.getColorStop3(), 275 'colorStop3': this.getColorStop3(),
263 'colorStop4': this.getColorStop4(), 276 'colorStop4': this.getColorStop4(),
264 'angle': this.getAngle() 277 'angle': this.getAngle(),
278 'textureTransform': this._textureTransform
265 }; 279 };
266 280
267 return jObj; 281 return jObj;
@@ -281,6 +295,7 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
281 colorStop3 = jObj.colorStop3, 295 colorStop3 = jObj.colorStop3,
282 colorStop4 = jObj.colorStop4, 296 colorStop4 = jObj.colorStop4,
283 angle = jObj.angle; 297 angle = jObj.angle;
298 this._textureTransform = jObj.textureTransform;
284 299
285 this.setProperty("color1", color1); 300 this.setProperty("color1", color1);
286 this.setProperty("color2", color2); 301 this.setProperty("color2", color2);
@@ -367,7 +382,8 @@ var linearGradientMaterialDef =
367 'u_colorStop2': { 'type' : 'float' }, 382 'u_colorStop2': { 'type' : 'float' },
368 'u_colorStop3': { 'type' : 'float' }, 383 'u_colorStop3': { 'type' : 'float' },
369 'u_colorStop4': { 'type' : 'float' }, 384 'u_colorStop4': { 'type' : 'float' },
370 'u_cos_sin_angle' : { 'type' : 'vec2' } 385 'u_cos_sin_angle': { 'type' : 'vec2' },
386 'u_texTransform': { 'type' : 'mat3' }
371 //'u_colorCount': {'type' : 'int' } 387 //'u_colorCount': {'type' : 'int' }
372 388
373 }, 389 },
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..b0b63cee 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,8 @@ 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 this._textureTransform = [1,0,0, 0,1,0, 0,0,1];
29
27 /////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////
28 // Property Accessors 31 // Property Accessors
29 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
@@ -143,9 +146,9 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
143 /////////////////////////////////////////////////////////////////////// 146 ///////////////////////////////////////////////////////////////////////
144 // Material Property Accessors 147 // Material Property Accessors
145 /////////////////////////////////////////////////////////////////////// 148 ///////////////////////////////////////////////////////////////////////
146 this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4", "angle"]; 149 this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4" ];
147 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"]; 150 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4" ];
148 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "float"]; 151 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float" ];
149 this._propValues = []; 152 this._propValues = [];
150 153
151 this._propValues[this._propNames[0]] = this._color1.slice(0); 154 this._propValues[this._propNames[0]] = this._color1.slice(0);
@@ -188,9 +191,21 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
188 // Methods 191 // Methods
189 /////////////////////////////////////////////////////////////////////// 192 ///////////////////////////////////////////////////////////////////////
190 // duplcate method requirde 193 // duplcate method requirde
191 this.dup = function () { 194 this.dup = function () {
192 return new RadialGradientMaterial(); 195 // allocate a new material
193 }; 196 var newMat = new RadialGradientMaterial();
197
198 // copy over the current values;
199 var propNames = [], propValues = [], propTypes = [], propLabels = [];
200 this.getAllProperties( propNames, propValues, propTypes, propLabels);
201 var n = propNames.length;
202 for (var i=0; i<n; i++) {
203 newMat.setProperty( propNames[i], propValues[i] );
204 }
205 newMat._textureTransform = this._textureTransform.slice();
206
207 return newMat;
208 };
194 209
195 this.init = function (world) { 210 this.init = function (world) {
196 this.setWorld(world); 211 this.setWorld(world);
@@ -231,9 +246,45 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
231 this._shader['default'].u_colorStop3.set([s]); 246 this._shader['default'].u_colorStop3.set([s]);
232 s = this.getColorStop4(); 247 s = this.getColorStop4();
233 this._shader['default'].u_colorStop4.set([s]); 248 this._shader['default'].u_colorStop4.set([s]);
249
250 this._shader['default'].u_texTransform.set( this._textureTransform );
234 } 251<