aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge
diff options
context:
space:
mode:
authorhwc4872012-06-07 17:07:21 -0700
committerhwc4872012-06-07 17:07:21 -0700
commitdb2bb0ab5d2747f0d07878e3b8a7d2d10c755110 (patch)
tree7e3ca8a757aa0c28ccdbef2e773f54a5cfc13a98 /js/lib/rdge
parent6c994c4b90023cecf4fd0caafb404b859fe28f54 (diff)
downloadninja-db2bb0ab5d2747f0d07878e3b8a7d2d10c755110.tar.gz
Material cleanup
Diffstat (limited to 'js/lib/rdge')
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js187
-rw-r--r--js/lib/rdge/materials/deform-material.js21
-rw-r--r--js/lib/rdge/materials/flag-material.js110
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js113
-rw-r--r--js/lib/rdge/materials/fly-material.js38
-rw-r--r--js/lib/rdge/materials/julia-material.js52
-rw-r--r--js/lib/rdge/materials/keleidoscope-material.js52
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js252
-rw-r--r--js/lib/rdge/materials/pulse-material.js4
-rw-r--r--js/lib/rdge/materials/water-material.js387
10 files changed, 209 insertions, 1007 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js
index 30624f7b..f73f1d34 100755
--- a/js/lib/rdge/materials/bump-metal-material.js
+++ b/js/lib/rdge/materials/bump-metal-material.js
@@ -19,11 +19,10 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
19 this._name = "BumpMetalMaterial"; 19 this._name = "BumpMetalMaterial";
20 this._shaderName = "bumpMetal"; 20 this._shaderName = "bumpMetal";
21 21
22 this._lightDiff = [0.3, 0.3, 0.3, 1.0]; 22
23 23 this._defaultDiffuseTexture = "assets/images/metal.png";
24 this._diffuseTexture = "assets/images/metal.png"; 24 this._defaultSpecularTexture = "assets/images/silver.png";
25 this._specularTexture = "assets/images/silver.png"; 25 this._defaultNormalTexture = "assets/images/normalMap.png";
26 this._normalTexture = "assets/images/normalMap.png";
27 26
28 // keep the array of initialized textures 27 // keep the array of initialized textures
29 this._textures = []; 28 this._textures = [];
@@ -33,77 +32,22 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
33 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
34 // Property Accessors 33 // Property Accessors
35 /////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////
36 this.getName = function() {
37 return this._name;
38 };
39
40 this.getShaderName = function() {
41 return this._shaderName;
42 };
43
44 this.getLightDiff = function() {
45 return this._lightDiff;
46 };
47
48 this.setLightDiff = function(ld) {
49 this._lightDiff = ld;
50 // Bad property name. Commenting for now
51
52 if (this._shader && this._shader['default']){
53 this._shader['default'].u_light0Diff.set( ld );
54 }
55
56 };
57
58 this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null };
59 this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.initTexture(1); };
60
61 this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null };
62 this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.initTexture(2); };
63
64 this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null };
65 this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.initTexture(3); };
66
67 this.isAnimated = function() { return true; }; 35 this.isAnimated = function() { return true; };
36 this.getShaderDef = function() { return bumpMetalMaterialDef; };
68 37
69 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
70 // Material Property Accessors 39 // Material Property Accessors
71 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
72 this._propNames = ["lightDiff", "diffuseTexture", "normalMap" ]; 41 this._propNames = ["u_light0Diff", "u_colMap", "u_normalMap", "u_glowMap" ];
73 this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map" ]; 42 this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map" ];
74 this._propTypes = ["color", "file", "file" ]; 43 this._propTypes = ["color", "file", "file", "file" ];
75 this._propValues = []; 44 this._propValues = [];
76 45
77 this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); 46 this._propValues[ this._propNames[0] ] = [0.3, 0.3, 0.3, 1.0];
78 this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); 47 this._propValues[ this._propNames[1] ] = this._defaultDiffuseTexture.slice(0);
79 this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); 48 this._propValues[ this._propNames[2] ] = this._defaultNormalTexture.slice(0);
80 49 this._propValues[ this._propNames[3] ] = this._defaultSpecularTexture.slice(0);
81 // TODO - shader techniques are not all named the same, i.e., FlatMaterial uses "colorMe" and BrickMaterial uses "default"
82 this.setProperty = function( prop, value )
83 {
84 // every material should do something with the "color" property
85 if (prop === "color") return;
86 50
87 // make sure we have legitimate imput
88 var ok = this.validateProperty( prop, value );
89 if (!ok)
90 {
91 console.log( "invalid property in Bump Metal Materia;" + prop + " : " + value );
92 return;
93 }
94
95 switch (prop)
96 {
97 case "lightDiff": this.setLightDiff( value ); break;
98 case "diffuseTexture": this.setDiffuseTexture( value ); break;
99 case "specularTexture": this.setSpecularTexture( value ); break;
100 case "normalMap": this.setNormalTexture( value ); break;
101
102 default:
103 console.log( "invalid property to Bump Metal Material: " + prop + ", value: " + value );
104 break;
105 }
106 };
107 51
108 /////////////////////////////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////
109 // Methods 53 // Methods
@@ -120,116 +64,13 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
120 this._shader = new RDGE.jshader(); 64 this._shader = new RDGE.jshader();
121 this._shader.def = bumpMetalMaterialDef; 65 this._shader.def = bumpMetalMaterialDef;
122 this._shader.init(); 66 this._shader.init();
123 this._shader['default'].u_light0Diff.set( this.getLightDiff() );
124 67
125 // set up the material node 68 // set up the material node
126 this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); 69 this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() );
127 this._materialNode.setShader(this._shader); 70 this._materialNode.setShader(this._shader);
128 71
129 this.initTextures(); 72 this.setShaderValues();
130 }; 73 this.update(0);
131
132 this.initTexture = function( index )
133 {
134 var dstWorld = this.getWorld();
135 if (dstWorld)
136 {
137 var texMapName = this._propValues[this._propNames[index]];
138 if (texMapName)
139 {
140 var texture = new Texture( dstWorld, texMapName );
141 this._textures[index] = texture;
142 }
143 else
144 this._textures[index] = null;
145
146 this.updateTexture( index );
147 }
148 }
149
150 this.initTextures = function()
151 {
152 var dstWorld = this.getWorld();
153 if (dstWorld)
154 {
155 // find the world with the given id
156 for (var i=1; i<=3; i++)
157 {
158 this.initTexture( i );
159 }
160 }
161 }
162
163 this.updateTexture = function( index )
164 {
165 var material = this._materialNode;
166 if (material)
167 {
168 var technique = material.shaderProgram['default'];
169 var renderer = RDGE.globals.engine.getContext().renderer;
170 if (renderer && technique)
171 {
172 var glTex = this._textures[ index ];
173 var tex;
174 if (glTex)
175 {
176 if (glTex.isAnimated())
177 glTex.render();
178
179 tex = glTex.getTexture();
180 }
181
182 {
183 switch (index)
184 {
185 case 1: technique.u_colMap.set( tex ); break;
186 case 2: technique.u_normalMap.set( tex ); break;
187 case 3: technique.u_glowMap.set( tex ); break;
188 default: console.log( "invalid map index in BumpMetalMaterial, " + index );
189 }
190 }
191 }
192 }
193 };
194
195 this.exportJSON = function()
196 {
197 var jObj =
198 {
199 'material' : this.getShaderName(),
200 'name' : this.getName(),
201 'lightDiff' : this.getLightDiff(),