aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js212
1 files changed, 0 insertions, 212 deletions
diff --git a/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js b/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js
deleted file mode 100644
index ac1d3fe7..00000000
--- a/js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js
+++ /dev/null
@@ -1,212 +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()
84 {
85 // set up the shader
86 this._shader = new jshader();
87 this._shader.def = iridescentScalesShaderDef;
88 this._shader.init();
89
90 // create the material node
91 this._materialNode = createMaterialNode( this.getName() );
92 this._materialNode.setShader(this._shader);
93
94 // set up the material node
95 this._materialNode.setDiffuseTexture( this.getDiffuseTexture() );
96 this._materialNode.setSpecTexture( this.getSpecularTexture() );
97 this._materialNode.setNormalTexture( this.getNormalTexture() );
98 }
99
100 this.export = function()
101 {
102 // every material needs the base type and instance name
103 var exportStr = "material: " + this.getShaderName() + "\n";
104 exportStr += "name: " + this.getName() + "\n";
105
106 exportStr += "diffuseTexture: " + this.getDiffuseTexture() + "\n";
107 exportStr += "specularTexture: " + this.getSpecularTexture() + "\n";
108 exportStr += "normalTexture: " + this.getNormalTexture() + "\n";
109
110 // every material needs to terminate like this
111 exportStr += "endMaterial\n";
112
113 return exportStr;
114 }
115
116 this.import = function( importStr )
117 {
118 var pu = new ParseUtils( importStr );
119 var material = pu.nextValue( "material: " );
120 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
121 this.setName( pu.nextValue( "name: ") );
122
123 var rtnStr;
124 try
125 {
126 var dt = pu.nextValue( "diffuseTexture: " ),
127 st = pu.nextValue( "specularTexture: " ),
128 nt = pu.nextValue( "normalTexture: " );
129
130 var endKey = "endMaterial\n";
131 var index = importStr.indexOf( endKey );
132 index += endKey.length;
133 rtnStr = importStr.substr( index );
134 }
135 catch (e)
136 {
137 throw new Error( "could not import material: " + importStr );
138 }
139
140 return rtnStr;
141 }
142}
143
144///////////////////////////////////////////////////////////////////////////////////////
145// RDGE shaders
146/*
147 * The main shader for the scene
148 */
149var iridescentScalesShaderDef = {'shaders': {
150 // this shader is being referenced by file
151 'defaultVShader':"assets/shaders/test_vshader.glsl",
152 'defaultFShader':"assets/shaders/test_fshader.glsl",
153
154 // this shader is inline
155 'dirLightVShader': "\
156 uniform mat4 u_mvMatrix;\
157 uniform mat4 u_normalMatrix;\
158 uniform mat4 u_projMatrix;\
159 uniform mat4 u_worldMatrix;\
160 attribute vec3 a_pos;\
161 attribute vec3 a_nrm;\
162 varying vec3 vNormal;\
163 varying vec3 vPos;\
164 void main() {\
165 vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\
166 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\
167 vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\
168 }",
169 'dirLightFShader': "\
170 precision highp float;\
171 uniform vec4 u_light1Diff;\
172 uniform vec3 u_light1Pos;\
173 uniform vec4 u_light2Diff;\
174 uniform vec3 u_light2Pos;\
175 varying vec3 vNormal;\
176 varying vec3 vPos;\
177 void main() {\
178 vec3 light1 = vec3(u_light1Pos.x - vPos.x, u_light1Pos.y - vPos.y, u_light1Pos.z - vPos.z);\
179 vec3 light2 = vec3(u_light2Pos.x - vPos.x, u_light2Pos.y - vPos.y, u_light2Pos.z - vPos.z);\
180 float t = 0.75;\
181 float range = t*t;\
182 float alpha1 = max(0.0, 1.0 - ( (light1.x*light1.x)/range + (light1.y*light1.y)/range + (light1.z*light1.z)/range));\
183 float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\
184 gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\
185 }",
186 },
187 'techniques': {
188 'default':[{
189 'vshader' : 'defaultVShader',
190 'fshader' : 'defaultFShader',
191 // attributes
192 'attributes' :
193 {
194 'vert' : { 'type' : 'vec3' },
195 'normal' : { 'type' : 'vec3' },
196 'texcoord' : { 'type' : 'vec2' },
197 },
198 // parameters
199 'params' :