aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js
diff options
context:
space:
mode:
authorJohn Mayhew2012-02-10 16:20:45 -0800
committerJohn Mayhew2012-02-10 16:20:45 -0800
commiteb0032234971f2c1c471f562d52c086fcffe8a14 (patch)
tree9fe9a49b5b49c3c0d15ea4fc124df4c100ffb730 /js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js
parent730c1e191e36b8ab8dba576c481a6585e0dfa69e (diff)
parent344933fd505afb9f5dfa3be8cc959112df04da0a (diff)
downloadninja-eb0032234971f2c1c471f562d52c086fcffe8a14.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into WorkingBranch
Diffstat (limited to 'js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js215
1 files changed, 0 insertions, 215 deletions
diff --git a/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js b/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js
deleted file mode 100644
index a8b1c18b..00000000
--- a/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js
+++ /dev/null
@@ -1,215 +0,0 @@
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
7
8///////////////////////////////////////////////////////////////////////
9// Class GLMaterial
10// GL representation of a material.
11///////////////////////////////////////////////////////////////////////
12function IridescentScalesMaterial()
13{
14 // initialize the inherited members
15 this.inheritedFrom = GLMaterial;
16 this.inheritedFrom();
17
18 ///////////////////////////////////////////////////////////////////////
19 // Instance variables
20 ///////////////////////////////////////////////////////////////////////
21 this._name = "IridescentScalesMaterial";
22 this._shaderName = "iridescentScales";
23
24 //this._diffuseTexture = "grey";
25 //this._specularTexture = "irredecentENV";
26 //this._normalTexture = "scales_normal";
27
28 ///////////////////////////////////////////////////////////////////////
29 // Property Accessors
30 ///////////////////////////////////////////////////////////////////////
31 this.getShaderName = function() { return this._shaderName; }
32
33 //this.getLightDiff = function() { return this._lightDiff; }
34
35 this.getDiffuseTexture = function() { return this._propValues["diffuseTexture"].slice(0); }
36 this.setDiffuseTexture = function(dt) { this._propValues["diffuseTexture"] = dt.slice(0);
37 if (this._materialNode) this._materialNode.setDiffuseTexture( dt ); }
38
39 this.getSpecularTexture = function() { return this._propValues["specularTexture"].slice(0); }
40 this.setSpecularTexture = function(st) { this._propValues["specularTexture"] = st.slice(0);
41 if (this._materialNode) this._materialNode.setSpecularTexture( st ); }
42
43 this.getNormalTexture = function() { return this._propValues["normalTexture"].slice(0); }
44 this.setNormalTexture = function(nt) { this._propValues["normalTexture"] = nt.slice(0);
45 if (this._materialNode) this._materialNode.setNormalTexture( nt ); }
46
47 ///////////////////////////////////////////////////////////////////////
48 // Material Property Accessors
49 ///////////////////////////////////////////////////////////////////////
50 this._propNames = ["diffuseTexture", "specularTexture", "normalTexture"];
51 this._propLabels = ["Diffuse Tecture", "Specular Texture", "Bump Map"];
52 this._propTypes = ["file", "file", "file"];
53 this._propValues = [];
54
55 this._propValues[ this._propNames[0] ] = "grey";
56 this._propValues[ this._propNames[1] ] = "irredecentENV";
57 this._propValues[ this._propNames[2] ] = "scales_normal";
58
59 this.setProperty = function( prop, value )
60 {
61 // make sure we have legitimate imput
62 var ok = this.validateProperty( prop, value );
63 if (!ok)
64 console.log( "invalid property in Bump Metal Materia;" + prop + " : " + value );
65
66 switch (prop)
67 {
68 case "diffuseTexture": this.setDiffuseTexture( value ); break;
69 case "specularTexture": this.setSpecularTexture( value ); break;
70 case "normalMap": this.setNormalTexture( value ); break;
71
72 default:
73 console.log( "invalid property to Iridescent Scales Material: " + prop + ", value: " + value );
74 break;
75 }
76 }
77
78 ///////////////////////////////////////////////////////////////////////
79 // Methods
80 ///////////////////////////////////////////////////////////////////////
81 this.dup = function() { return new IridescentScalesMaterial(); }
82
83 this.init = function( world )
84 {
85 // save the world
86 if (world) this.setWorld( world );
87
88 // set up the shader
89 this._shader = new jshader();
90 this._shader.def = iridescentScalesShaderDef;
91 this._shader.init();
92
93 // create the material node
94 this._materialNode = createMaterialNode( this.getName() );
95 this._materialNode.setShader(this._shader);
96
97 // set up the material node
98 this._materialNode.setDiffuseTexture( this.getDiffuseTexture() );
99 this._materialNode.setSpecTexture( this.getSpecularTexture() );
100 this._materialNode.setNormalTexture( this.getNormalTexture() );
101 }
102
103 this.export = function()
104 {
105 // every material needs the base type and instance name
106 var exportStr = "material: " + this.getShaderName() + "\n";
107 exportStr += "name: " + this.getName() + "\n";
108
109 exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n";
110 exportStr += "specularTexture: " + this.getSpecularTexture() + "\n";
111 exportStr += "normalTexture: " + this.getNormalTexture() + "\n";
112
113 // every material needs to terminate like this
114 exportStr += "endMaterial\n";
115
116 return exportStr;
117 }
118
119 this.import = function( importStr )
120 {
121 var pu = new ParseUtils( importStr );
122 var material = pu.nextValue( "material: " );
123 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
124 this.setName( pu.nextValue( "name: ") );
125
126 var rtnStr;
127 try
128 {
129 var dt = pu.nextValue( "diffuseTexture: " ),
130 st = pu.nextValue( "specularTexture: " ),
131 nt = pu.nextValue( "normalTexture: " );
132
133 var endKey = "endMaterial\n";
134 var index = importStr.indexOf( endKey );
135 index += endKey.length;
136 rtnStr = importStr.substr( index );
137 }
138 catch (e)
139 {
140 throw new Error( "could not import material: " + importStr );
141 }
142
143 return rtnStr;
144 }
145}
146
147///////////////////////////////////////////////////////////////////////////////////////
148// RDGE shaders
149/*
150 * The main shader for the scene
151 */
152var iridescentScalesShaderDef = {'shaders': {
153 // this shader is being referenced by file
154 'defaultVShader':"assets/shaders/test_vshader.glsl",
155 'defaultFShader':"assets/shaders/test_fshader.glsl",
156
157 // this shader is inline
158 'dirLightVShader': "\
159 uniform mat4 u_mvMatrix;\
160 uniform mat4 u_normalMatrix;\
161 uniform mat4 u_projMatrix;\
162 uniform mat4 u_worldMatrix;\
163 attribute vec3 a_pos;\
164 attribute vec3 a_nrm;\
165 varying vec3 vNormal;\
166 varying vec3 vPos;\
167 void main() {\
168 vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\
169 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\
170 vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\
171 }",
172 'dirLightFShader': "\
173 precision highp float;\
174 uniform vec4 u_light1Diff;\
175 uniform vec3 u_light1Pos;\
176 uniform vec4 u_light2Diff;\
177 uniform vec3 u_light2Pos;\
178 varying vec3 vNormal;\
179 varying vec3 vPos;\
180 void main() {\
181 vec3 light1 = vec3(u_light1Pos.x - vPos.x, u_light1Pos.y - vPos.y, u_light1Pos.z - vPos.z);\
182 vec3 light2 = vec3(u_light2Pos.x - vPos.x, u_light2Pos.y - vPos.y, u_light2Pos.z - vPos.z);\
183 float t = 0.75;\
184 float range = t*t;\
185 float alpha1 = max(0.0, 1.0 - ( (light1.x*light1.x)/range + (light1.y*light1.y)/range + (light1.z*light1.z)/range));\
186 float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\
187 gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\
188 }",
189 },
190 'techniques': {
191 'default':[{
192 'vshader' : 'defaultVShader',
193 'fshader' : 'defaultFShader',
194