@@ -12,6 +12,8 @@ THREE.ShaderSkin = {
12
12
// - physically based specular term (Kelemen/Szirmay-Kalos specular reflectance)
13
13
//
14
14
// - diffuse map
15
+ // - bump map
16
+ // - specular map
15
17
// - point and directional lights (use with "lights: true" material option)
16
18
// - fog (use with "fog: true" material option)
17
19
// - shadow maps
@@ -28,6 +30,9 @@ THREE.ShaderSkin = {
28
30
29
31
{
30
32
33
+ "enableBump" : { type : "i" , value : 0 } ,
34
+ "enableSpecular" : { type : "i" , value : 0 } ,
35
+
31
36
"tDiffuse" : { type : "t" , value : 0 , texture : null } ,
32
37
"tBeckmann" : { type : "t" , value : 1 , texture : null } ,
33
38
@@ -39,6 +44,13 @@ THREE.ShaderSkin = {
39
44
"uRoughness" : { type : "f" , value : 0.15 } ,
40
45
"uSpecularBrightness" : { type : "f" , value : 0.75 } ,
41
46
47
+ "bumpMap" : { type : "t" , value : 2 , texture : null } ,
48
+ "bumpScale" : { type : "f" , value : 1 } ,
49
+
50
+ "specularMap" : { type : "t" , value : 3 , texture : null } ,
51
+
52
+ "offsetRepeat" : { type : "v4" , value : new THREE . Vector4 ( 0 , 0 , 1 , 1 ) } ,
53
+
42
54
"uWrapRGB" : { type : "v3" , value : new THREE . Vector3 ( 0.75 , 0.375 , 0.1875 ) }
43
55
44
56
}
@@ -47,6 +59,12 @@ THREE.ShaderSkin = {
47
59
48
60
fragmentShader : [
49
61
62
+ "#define USE_BUMPMAP" ,
63
+ "#extension GL_OES_standard_derivatives : enable" ,
64
+
65
+ "uniform bool enableBump;" ,
66
+ "uniform bool enableSpecular;" ,
67
+
50
68
"uniform vec3 uAmbientColor;" ,
51
69
"uniform vec3 uDiffuseColor;" ,
52
70
"uniform vec3 uSpecularColor;" ,
@@ -60,6 +78,8 @@ THREE.ShaderSkin = {
60
78
"uniform sampler2D tDiffuse;" ,
61
79
"uniform sampler2D tBeckmann;" ,
62
80
81
+ "uniform sampler2D specularMap;" ,
82
+
63
83
"varying vec3 vNormal;" ,
64
84
"varying vec2 vUv;" ,
65
85
@@ -84,6 +104,7 @@ THREE.ShaderSkin = {
84
104
85
105
THREE . ShaderChunk [ "shadowmap_pars_fragment" ] ,
86
106
THREE . ShaderChunk [ "fog_pars_fragment" ] ,
107
+ THREE . ShaderChunk [ "bumpmap_pars_fragment" ] ,
87
108
88
109
// Fresnel term
89
110
@@ -140,6 +161,25 @@ THREE.ShaderSkin = {
140
161
"vec3 normal = normalize( vNormal );" ,
141
162
"vec3 viewPosition = normalize( vViewPosition );" ,
142
163
164
+ "float specularStrength;" ,
165
+
166
+ "if ( enableSpecular ) {" ,
167
+
168
+ "vec4 texelSpecular = texture2D( specularMap, vUv );" ,
169
+ "specularStrength = texelSpecular.r;" ,
170
+
171
+ "} else {" ,
172
+
173
+ "specularStrength = 1.0;" ,
174
+
175
+ "}" ,
176
+
177
+ "#ifdef USE_BUMPMAP" ,
178
+
179
+ "if ( enableBump ) normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );" ,
180
+
181
+ "#endif" ,
182
+
143
183
// point lights
144
184
145
185
"vec3 specularTotal = vec3( 0.0 );" ,
@@ -168,7 +208,7 @@ THREE.ShaderSkin = {
168
208
"float pointSpecularWeight = KS_Skin_Specular( normal, lVector, viewPosition, uRoughness, uSpecularBrightness );" ,
169
209
170
210
"pointTotal += lDistance * uDiffuseColor * pointLightColor[ i ] * pointDiffuseWeight;" ,
171
- "specularTotal += lDistance * uSpecularColor * pointLightColor[ i ] * pointSpecularWeight;" ,
211
+ "specularTotal += lDistance * uSpecularColor * pointLightColor[ i ] * pointSpecularWeight * specularStrength ;" ,
172
212
173
213
"}" ,
174
214
@@ -193,7 +233,7 @@ THREE.ShaderSkin = {
193
233
"float dirSpecularWeight = KS_Skin_Specular( normal, dirVector, viewPosition, uRoughness, uSpecularBrightness );" ,
194
234
195
235
"dirTotal += uDiffuseColor * directionalLightColor[ i ] * dirDiffuseWeight;" ,
196
- "specularTotal += uSpecularColor * directionalLightColor[ i ] * dirSpecularWeight;" ,
236
+ "specularTotal += uSpecularColor * directionalLightColor[ i ] * dirSpecularWeight * specularStrength ;" ,
197
237
198
238
"}" ,
199
239
@@ -223,6 +263,8 @@ THREE.ShaderSkin = {
223
263
224
264
vertexShader : [
225
265
266
+ "uniform vec4 offsetRepeat;" ,
267
+
226
268
"varying vec3 vNormal;" ,
227
269
"varying vec2 vUv;" ,
228
270
@@ -237,7 +279,7 @@ THREE.ShaderSkin = {
237
279
238
280
"vNormal = normalMatrix * normal;" ,
239
281
240
- "vUv = uv;" ,
282
+ "vUv = uv * offsetRepeat.zw + offsetRepeat.xy ;" ,
241
283
242
284
"gl_Position = projectionMatrix * mvPosition;" ,
243
285
0 commit comments