aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/bump-metal-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/bump-metal-material.js')
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js154
1 files changed, 77 insertions, 77 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js
index 3db3df1d..bcc092f9 100755
--- a/js/lib/rdge/materials/bump-metal-material.js
+++ b/js/lib/rdge/materials/bump-metal-material.js
@@ -40,62 +40,62 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
40 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
41 // Instance variables 41 // Instance variables
42 /////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////
43 this._name = "Bump Metal"; 43 this._name = "Bump Metal";
44 this._shaderName = "bumpMetal"; 44 this._shaderName = "bumpMetal";
45 45
46 46
47 this._defaultDiffuseTexture = "assets/images/metal.png"; 47 this._defaultDiffuseTexture = "assets/images/metal.png";
48 this._defaultSpecularTexture = "assets/images/silver.png"; 48 this._defaultSpecularTexture = "assets/images/silver.png";
49 this._defaultNormalTexture = "assets/images/normalMap.png"; 49 this._defaultNormalTexture = "assets/images/normalMap.png";
50 50
51 // array textures indexed by shader uniform name 51 // array textures indexed by shader uniform name
52 this._glTextures = []; 52 this._glTextures = [];
53 53
54 this._speed = 1.0; 54 this._speed = 1.0;
55 55
56 /////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////
57 // Property Accessors 57 // Property Accessors
58 /////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////
59 this.isAnimated = function() { return true; }; 59 this.isAnimated = function() { return true; };
60 this.getShaderDef = function() { return bumpMetalMaterialDef; }; 60 this.getShaderDef = function() { return bumpMetalMaterialDef; };
61 61
62 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
63 // Material Property Accessors 63 // Material Property Accessors
64 /////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////
65 this._propNames = ["u_light0Diff", "u_colMap", "u_normalMap", "u_glowMap" ]; 65 this._propNames = ["u_light0Diff", "u_colMap", "u_normalMap", "u_glowMap" ];
66 this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map" ]; 66 this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map" ];
67 this._propTypes = ["color", "file", "file", "file" ]; 67 this._propTypes = ["color", "file", "file", "file" ];
68 this._propValues = []; 68 this._propValues = [];
69 69
70 this._propValues[ this._propNames[0] ] = [0.3, 0.3, 0.3, 1.0]; 70 this._propValues[ this._propNames[0] ] = [0.3, 0.3, 0.3, 1.0];
71 this._propValues[ this._propNames[1] ] = this._defaultDiffuseTexture.slice(0); 71 this._propValues[ this._propNames[1] ] = this._defaultDiffuseTexture.slice(0);
72 this._propValues[ this._propNames[2] ] = this._defaultNormalTexture.slice(0); 72 this._propValues[ this._propNames[2] ] = this._defaultNormalTexture.slice(0);
73 this._propValues[ this._propNames[3] ] = this._defaultSpecularTexture.slice(0); 73 this._propValues[ this._propNames[3] ] = this._defaultSpecularTexture.slice(0);
74 74
75 75
76 /////////////////////////////////////////////////////////////////////// 76 ///////////////////////////////////////////////////////////////////////
77 // Methods 77 // Methods
78 /////////////////////////////////////////////////////////////////////// 78 ///////////////////////////////////////////////////////////////////////
79 79
80 this.init = function( world ) 80 this.init = function( world )
81 { 81 {
82 // save the world 82 // save the world
83 if (world) { 83 if (world) {
84 this.setWorld( world ); 84 this.setWorld( world );
85 } 85 }
86 86
87 // set up the shader 87 // set up the shader
88 this._shader = new RDGE.jshader(); 88 this._shader = new RDGE.jshader();
89 this._shader.def = bumpMetalMaterialDef; 89 this._shader.def = bumpMetalMaterialDef;
90 this._shader.init(); 90 this._shader.init();
91 91
92 // set up the material node 92 // set up the material node
93 this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); 93 this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() );
94 this._materialNode.setShader(this._shader); 94 this._materialNode.setShader(this._shader);
95 95
96 this.setShaderValues(); 96 this.setShaderValues();
97 this.update(0); 97 this.update(0);
98 }; 98 };
99}; 99};
100 100
101/////////////////////////////////////////////////////////////////////////////////////// 101///////////////////////////////////////////////////////////////////////////////////////
@@ -104,28 +104,28 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
104// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 104// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
105var bumpMetalMaterialDef = bumpMetalShaderDef = 105var bumpMetalMaterialDef = bumpMetalShaderDef =
106{ 106{
107 'shaders': 107 'shaders':
108 { 108 {
109 // this shader is being referenced by file 109 // this shader is being referenced by file
110 'defaultVShader':"assets/shaders/test_vshader.glsl", 110 'defaultVShader':"assets/shaders/test_vshader.glsl",
111 'defaultFShader':"assets/shaders/test_fshader.glsl", 111 'defaultFShader':"assets/shaders/test_fshader.glsl",
112 112
113 // this shader is inline 113 // this shader is inline
114 'dirLightVShader': "\ 114 'dirLightVShader': "\
115 uniform mat4 u_mvMatrix;\ 115 uniform mat4 u_mvMatrix;\
116 uniform mat4 u_normalMatrix;\ 116 uniform mat4 u_normalMatrix;\
117 uniform mat4 u_projMatrix;\ 117 uniform mat4 u_projMatrix;\
118 uniform mat4 u_worldMatrix;\ 118 uniform mat4 u_worldMatrix;\
119 attribute vec3 a_pos;\ 119 attribute vec3 a_pos;\
120 attribute vec3 a_nrm;\ 120 attribute vec3 a_nrm;\
121 varying vec3 vNormal;\ 121 varying vec3 vNormal;\
122 varying vec3 vPos;\ 122 varying vec3 vPos;\
123 void main() {\ 123 void main() {\
124 vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\ 124 vNormal.xyz = (u_normalMatrix*vec4(a_nrm, 0.0)).xyz;\
125 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\ 125 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\
126 vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\ 126 vPos = (u_worldMatrix * vec4(a_pos,1.0)).xyz;\
127 }", 127 }",
128 'dirLightFShader': "\ 128 'dirLightFShader': "\
129 precision highp float;\ 129 precision highp float;\
130 uniform vec4 u_light1Diff;\ 130 uniform vec4 u_light1Diff;\
131 uniform vec3 u_light1Pos;\ 131 uniform vec3 u_light1Pos;\
@@ -142,29 +142,29 @@ var bumpMetalMaterialDef = bumpMetalShaderDef =
142 float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\ 142 float alpha2 = max(0.0, 1.0 - ( (light2.x*light2.x)/range + (light2.y*light2.y)/range + (light2.z*light2.z)/range));\
143 gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\ 143 gl_FragColor = vec4((u_light2Diff*alpha2 + u_light1Diff*alpha1).rgb, 1.0);\
144 }" 144 }"
145 }, 145 },
146 'techniques': 146 'techniques':
147 { 147 {
148 'default': 148 'default':
149 [ 149 [
150 { 150 {
151 'vshader' : 'defaultVShader', 151 'vshader' : 'defaultVShader',
152 'fshader' : 'defaultFShader', 152 'fshader' : 'defaultFShader',
153 // attributes 153 // attributes
154 'attributes' : 154 'attributes' :
155 { 155 {
156 'vert' : { 'type' : 'vec3' }, 156 'vert' : { 'type' : 'vec3' },
157 'normal' : { 'type' : 'vec3' }, 157 'normal' : { 'type' : 'vec3' },
158 'texcoord' : { 'type' : 'vec2' } 158 'texcoord' : { 'type' : 'vec2' }
159 }, 159 },
160 // parameters 160 // parameters
161 'params' : 161 'params' :
162 { 162 {
163 'u_light0Diff' : { 'type' : 'vec4' }, 163 'u_light0Diff' : { 'type' : 'vec4' },
164 'u_colMap': { 'type' : 'tex2d' }, 164 'u_colMap': { 'type' : 'tex2d' },
165 'u_normalMap': { 'type' : 'tex2d' }, 165 'u_normalMap': { 'type' : 'tex2d' },
166 'u_glowMap': { 'type' : 'tex2d' } 166 'u_glowMap': { 'type' : 'tex2d' }
167 }, 167 },
168 168
169 // render states 169 // render states
170 'states' : 170 'states' :
@@ -172,7 +172,7 @@ var bumpMetalMaterialDef = bumpMetalShaderDef =
172 'depthEnable' : true, 172 'depthEnable' : true,
173 'offset':[1.0, 0.1] 173 'offset':[1.0, 0.1]
174 } 174 }
175 }, 175 },
176 { // light pass 176 { // light pass
177 'vshader' : 'dirLightVShader', 177 'vshader' : 'dirLightVShader',
178 'fshader' : 'dirLightFShader', 178 'fshader' : 'dirLightFShader',
@@ -195,9 +195,9 @@ var bumpMetalMaterialDef = bumpMetalShaderDef =
195 "srcBlend" : "SRC_ALPHA", 195 "srcBlend" : "SRC_ALPHA",
196 "dstBlend" : "DST_ALPHA" 196 "dstBlend" : "DST_ALPHA"
197 } 197 }
198 } // light pass 198 } // light pass
199 ] 199 ]
200 } // techniques