aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials
diff options
context:
space:
mode:
authorhwc4872012-03-22 15:47:11 -0700
committerhwc4872012-03-22 15:47:11 -0700
commite927e4702d7dbd4a878f6979b3f56b46758f93de (patch)
treee6bb8951374a6504bd6c745ce7233da5cd4869dc /js/lib/rdge/materials
parent00cd98e49c959906d7c44bb6adcdef1f3d5148ae (diff)
parent31e924e1b8b8da8342b3ff2341c8284915486c0b (diff)
downloadninja-e927e4702d7dbd4a878f6979b3f56b46758f93de.tar.gz
Merge branch 'integration' of github.com:ericmueller/ninja-internal into Textures
Diffstat (limited to 'js/lib/rdge/materials')
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js40
-rw-r--r--js/lib/rdge/materials/cloud-material.js300
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js21
-rw-r--r--js/lib/rdge/materials/julia-material.js6
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js53
-rw-r--r--js/lib/rdge/materials/mandel-material.js6
-rw-r--r--js/lib/rdge/materials/plasma-material.js18
-rw-r--r--js/lib/rdge/materials/pulse-material.js44
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js57
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js54
-rw-r--r--js/lib/rdge/materials/taper-material.js27
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js28
-rwxr-xr-xjs/lib/rdge/materials/uber-material.js180
-rw-r--r--js/lib/rdge/materials/water-material.js103
14 files changed, 908 insertions, 29 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js
index fe8a9dd5..ccd8e3ca 100755
--- a/js/lib/rdge/materials/bump-metal-material.js
+++ b/js/lib/rdge/materials/bump-metal-material.js
@@ -190,6 +190,46 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
190 } 190 }
191 }; 191 };
192 192
193 this.exportJSON = function()
194 {
195 var jObj =
196 {
197 'material' : this.getShaderName(),
198 'name' : this.getName(),
199 'lightDiff' : this.getLightDiff(),
200 'diffuseTexture' : this.getDiffuseTexture(),
201 'specularTexture' : this.getSpecularTexture(),
202 'normalMap' : this.getNormalTexture()
203 };
204
205 return jObj;
206 };
207
208 this.importJSON = function( jObj )
209 {
210 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" );
211 this.setName( jObj.name );
212
213 try
214 {
215 var lightDiff = jObj.lightDiff,
216 dt = jObj.diffuseTexture,
217 st = jObj.specularTexture,
218 nt = jObj.normalMap;
219
220 this.setProperty( "lightDiff", lightDiff);
221 this.setProperty( "diffuseTexture", dt );
222 this.setProperty( "specularTexture", st );
223 this.setProperty( "normalMap", nt );
224 }
225 catch (e)
226 {
227 throw new Error( "could not import BumpMetal material: " + jObj );
228 }
229
230 return;
231 };
232
193 this.export = function() 233 this.export = function()
194 { 234 {
195 // every material needs the base type and instance name 235 // every material needs the base type and instance name
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
new file mode 100644
index 00000000..85088f91
--- /dev/null
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -0,0 +1,300 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material;
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13var CloudMaterial = function CloudMaterial() {
14 ///////////////////////////////////////////////////////////////////////
15 // Instance variables
16 ///////////////////////////////////////////////////////////////////////
17 this._name = "CloudMaterial";
18 this._shaderName = "cloud";
19
20 this._texMap = 'assets/images/cloud2.jpg';
21 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
22
23 this._time = 0.0;
24 this._dTime = 0.01;
25
26 ///////////////////////////////////////////////////////////////////////
27 // Property Accessors
28 ///////////////////////////////////////////////////////////////////////
29 this.getName = function() { return this._name; };
30 this.getShaderName = function() { return this._shaderName; };
31
32 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null };
33 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
34
35 this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); };
36 this.getDiffuseColor = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; };
37
38 this.isAnimated = function() { return true; };
39
40 ///////////////////////////////////////////////////////////////////////
41 // Material Property Accessors
42 ///////////////////////////////////////////////////////////////////////
43 this._propNames = ["texmap", "diffusecolor"];
44 this._propLabels = ["Texture map", "Diffuse Color"];
45 this._propTypes = ["file", "color"];
46 this._propValues = [];
47
48 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
49 this._propValues[ this._propNames[1] ] = this._diffuseColor.slice();
50
51 this.setProperty = function( prop, value )
52 {
53 if (prop === 'color') prop = 'diffusecolor';
54
55 // make sure we have legitimate imput
56 var ok = this.validateProperty( prop, value );
57 if (!ok) {
58 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
59 }
60
61 switch (prop)
62 {
63 case "texmap":
64 this.setTextureMap(value);
65 break;
66
67 case "diffusecolor":
68 this.setDiffuseColor( value );
69 break;
70
71 case "color":
72 break;
73 }
74 };
75 ///////////////////////////////////////////////////////////////////////
76
77
78 ///////////////////////////////////////////////////////////////////////
79 // Methods
80 ///////////////////////////////////////////////////////////////////////
81 // duplcate method requirde
82 this.dup = function( world )
83 {
84 // save the world
85 if (world) this.setWorld( world );
86
87 // allocate a new uber material
88 var newMat = new CloudMaterial();
89
90 // copy over the current values;
91 var propNames = [], propValues = [], propTypes = [], propLabels = [];
92 this.getAllProperties( propNames, propValues, propTypes, propLabels);
93 var n = propNames.length;
94 for (var i=0; i<n; i++) {
95 newMat.setProperty( propNames[i], propValues[i] );
96 }
97
98 return newMat;
99 };
100
101 this.init = function( world )
102 {
103 // save the world
104 if (world) this.setWorld( world );
105
106 // this variable declared above is inherited set to a smaller delta.
107 // the cloud material runs a little faster
108 this._dTime = 0.01;
109
110 // set up the shader
111 this._shader = new jshader();
112 this._shader.def = cloudMaterialDef;
113 this._shader.init();
114
115 // set up the material node
116 this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID());
117 this._materialNode.setShader(this._shader);
118
119 this._time = 0;
120 if (this._shader && this._shader['default']) {
121 this._shader['default'].u_time.set( [this._time] );
122 this._shader['default'].u_DiffuseColor.set( this._diffuseColor );
123 }
124
125 // set the shader values in the shader
126 this.updateTexture();
127 this.update( 0 );
128 };
129
130 this.updateColor = function()
131 {
132 var material = this._materialNode;
133 if (material)
134 {
135 var technique = material.shaderProgram['default'];
136 var renderer = g_Engine.getContext().renderer;
137 if (renderer && technique) {
138 var color = this._propValues[this._propNames[1]];
139 technique.u_DiffuseColor.set( this._diffuseColor );
140 }
141 }
142 }