1. THREE.WebGLShader: gl.getShaderInfoLog()
  2. 0(1) : warning C7022: unrecognized profile specifier "highp"
  3. 0(1) : warning C7022: unrecognized profile specifier "precision"
  4. 0(2) : warning C7022: unrecognized profile specifier "highp"
  5. 0(2) : warning C7022: unrecognized profile specifier "precision"
  6. 1: precision highp float;
  7. 2: precision highp int;
  8. 3:
  9. 4: #define VERTEX_TEXTURES
  10. 5:
  11. 6:
  12. 7: #define GAMMA_FACTOR 2
  13. 8: #define MAX_DIR_LIGHTS 1
  14. 9: #define MAX_POINT_LIGHTS 0
  15. 10: #define MAX_SPOT_LIGHTS 0
  16. 11: #define MAX_HEMI_LIGHTS 0
  17. 12: #define MAX_SHADOWS 0
  18. 13: #define MAX_BONES 59
  19. 14: #define USE_MAP
  20. 15:
  21. 16:
  22. 17:
  23. 18:
  24. 19:
  25. 20:
  26. 21:
  27. 22:
  28. 23:
  29. 24:
  30. 25:
  31. 26:
  32. 27:
  33. 28:
  34. 29:
  35. 30:
  36. 31:
  37. 32:
  38. 33:
  39. 34:
  40. 35:
  41. 36:
  42. 37: uniform mat4 modelMatrix;
  43. 38: uniform mat4 modelViewMatrix;
  44. 39: uniform mat4 projectionMatrix;
  45. 40: uniform mat4 viewMatrix;
  46. 41: uniform mat3 normalMatrix;
  47. 42: uniform vec3 cameraPosition;
  48. 43: attribute vec3 position;
  49. 44: attribute vec3 normal;
  50. 45: attribute vec2 uv;
  51. 46: attribute vec2 uv2;
  52. 47: #ifdef USE_COLOR
  53. 48: attribute vec3 color;
  54. 49: #endif
  55. 50: #ifdef USE_MORPHTARGETS
  56. 51: attribute vec3 morphTarget0;
  57. 52: attribute vec3 morphTarget1;
  58. 53: attribute vec3 morphTarget2;
  59. 54: attribute vec3 morphTarget3;
  60. 55: #ifdef USE_MORPHNORMALS
  61. 56: attribute vec3 morphNormal0;
  62. 57: attribute vec3 morphNormal1;
  63. 58: attribute vec3 morphNormal2;
  64. 59: attribute vec3 morphNormal3;
  65. 60: #else
  66. 61: attribute vec3 morphTarget4;
  67. 62: attribute vec3 morphTarget5;
  68. 63: attribute vec3 morphTarget6;
  69. 64: attribute vec3 morphTarget7;
  70. 65: #endif
  71. 66: #endif
  72. 67: #ifdef USE_SKINNING
  73. 68: attribute vec4 skinIndex;
  74. 69: attribute vec4 skinWeight;
  75. 70: #endif
  76. 71: #define PHONG
  77. 72: varying vec3 vViewPosition;
  78. 73: #ifndef FLAT_SHADED
  79. 74: varying vec3 vNormal;
  80. 75: #endif
  81. 76: #define PI 3.14159
  82. 77: #define PI2 6.28318
  83. 78: #define RECIPROCAL_PI2 0.15915494
  84. 79: #define LOG2 1.442695
  85. 80: #define EPSILON 1e-6
  86. 81:
  87. 82: float square( in float a ) { return a*a; }
  88. 83: vec2 square( in vec2 a ) { return vec2( a.x*a.x, a.y*a.y ); }
  89. 84: vec3 square( in vec3 a ) { return vec3( a.x*a.x, a.y*a.y, a.z*a.z ); }
  90. 85: vec4 square( in vec4 a ) { return vec4( a.x*a.x, a.y*a.y, a.z*a.z, a.w*a.w ); }
  91. 86: float saturate( in float a ) { return clamp( a, 0.0, 1.0 ); }
  92. 87: vec2 saturate( in vec2 a ) { return clamp( a, 0.0, 1.0 ); }
  93. 88: vec3 saturate( in vec3 a ) { return clamp( a, 0.0, 1.0 ); }
  94. 89: vec4 saturate( in vec4 a ) { return clamp( a, 0.0, 1.0 ); }
  95. 90: float average( in float a ) { return a; }
  96. 91: float average( in vec2 a ) { return ( a.x + a.y) * 0.5; }
  97. 92: float average( in vec3 a ) { return ( a.x + a.y + a.z) / 3.0; }
  98. 93: float average( in vec4 a ) { return ( a.x + a.y + a.z + a.w) * 0.25; }
  99. 94: float whiteCompliment( in float a ) { return saturate( 1.0 - a ); }
  100. 95: vec2 whiteCompliment( in vec2 a ) { return saturate( vec2(1.0) - a ); }
  101. 96: vec3 whiteCompliment( in vec3 a ) { return saturate( vec3(1.0) - a ); }
  102. 97: vec4 whiteCompliment( in vec4 a ) { return saturate( vec4(1.0) - a ); }
  103. 98: vec3 transformDirection( in vec3 normal, in mat4 matrix ) {
  104. 99: return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );
  105. 100: }
  106. 101: // http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations
  107. 102: vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {
  108. 103: return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );
  109. 104: }
  110. 105: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal) {
  111. 106: float distance = dot( planeNormal, point-pointOnPlane );
  112. 107: return point - distance * planeNormal;
  113. 108: }
  114. 109: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
  115. 110: return sign( dot( point - pointOnPlane, planeNormal ) );
  116. 111: }
  117. 112: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
  118. 113: return pointOnLine + lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) );
  119. 114: }
  120. 115: float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {
  121. 116: if ( decayExponent > 0.0 ) {
  122. 117: return pow( saturate( 1.0 - lightDistance / cutoffDistance ), decayExponent );
  123. 118: }
  124. 119: return 1.0;
  125. 120: }
  126. 121:
  127. 122: vec3 inputToLinear( in vec3 a ) {
  128. 123: #ifdef GAMMA_INPUT
  129. 124: return pow( a, vec3( float( GAMMA_FACTOR ) ) );
  130. 125: #else
  131. 126: return a;
  132. 127: #endif
  133. 128: }
  134. 129: vec3 linearToOutput( in vec3 a ) {
  135. 130: #ifdef GAMMA_OUTPUT
  136. 131: return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );
  137. 132: #else
  138. 133: return a;
  139. 134: #endif
  140. 135: }
  141. 136:
  142. 137: #if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )
  143. 138:
  144. 139: varying vec2 vUv;
  145. 140: uniform vec4 offsetRepeat;
  146. 141:
  147. 142: #endif
  148. 143:
  149. 144: #ifdef USE_LIGHTMAP
  150. 145:
  151. 146: varying vec2 vUv2;
  152. 147:
  153. 148: #endif
  154. 149: #if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )
  155. 150:
  156. 151: varying vec3 vReflect;
  157. 152:
  158. 153: uniform float refractionRatio;
  159. 154:
  160. 155: #endif
  161. 156:
  162. 157: #if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )
  163. 158:
  164. 159: varying vec3 vWorldPosition;
  165. 160:
  166. 161: #endif
  167. 162:
  168. 163: #ifdef USE_COLOR
  169. 164:
  170. 165: varying vec3 vColor;
  171. 166:
  172. 167: #endif
  173. 168: #ifdef USE_MORPHTARGETS
  174. 169:
  175. 170: #ifndef USE_MORPHNORMALS
  176. 171:
  177. 172: uniform float morphTargetInfluences[ 8 ];
  178. 173:
  179. 174: #else
  180. 175:
  181. 176: uniform float morphTargetInfluences[ 4 ];
  182. 177:
  183. 178: #endif
  184. 179:
  185. 180: #endif
  186. 181: #ifdef USE_SKINNING
  187. 182:
  188. 183: uniform mat4 bindMatrix;
  189. 184: uniform mat4 bindMatrixInverse;
  190. 185:
  191. 186: #ifdef BONE_TEXTURE
  192. 187:
  193. 188: uniform sampler2D boneTexture;
  194. 189: uniform int boneTextureWidth;
  195. 190: uniform int boneTextureHeight;
  196. 191:
  197. 192: mat4 getBoneMatrix( const in float i ) {
  198. 193:
  199. 194: float j = i * 4.0;
  200. 195: float x = mod( j, float( boneTextureWidth ) );
  201. 196: float y = floor( j / float( boneTextureWidth ) );
  202. 197:
  203. 198: float dx = 1.0 / float( boneTextureWidth );
  204. 199: float dy = 1.0 / float( boneTextureHeight );
  205. 200:
  206. 201: y = dy * ( y + 0.5 );
  207. 202:
  208. 203: vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );
  209. 204: vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );
  210. 205: vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );
  211. 206: vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );
  212. 207:
  213. 208: mat4 bone = mat4( v1, v2, v3, v4 );
  214. 209:
  215. 210: return bone;
  216. 211:
  217. 212: }
  218. 213:
  219. 214: #else
  220. 215:
  221. 216: uniform mat4 boneGlobalMatrices[ MAX_BONES ];
  222. 217:
  223. 218: mat4 getBoneMatrix( const in float i ) {
  224. 219:
  225. 220: mat4 bone = boneGlobalMatrices[ int(i) ];
  226. 221: return bone;
  227. 222:
  228. 223: }
  229. 224:
  230. 225: #endif
  231. 226:
  232. 227: #endif
  233. 228:
  234. 229: #ifdef USE_SHADOWMAP
  235. 230:
  236. 231: varying vec4 vShadowCoord[ MAX_SHADOWS ];
  237. 232: uniform mat4 shadowMatrix[ MAX_SHADOWS ];
  238. 233:
  239. 234: #endif
  240. 235: #ifdef USE_LOGDEPTHBUF
  241. 236:
  242. 237: #ifdef USE_LOGDEPTHBUF_EXT
  243. 238:
  244. 239: varying float vFragDepth;
  245. 240:
  246. 241: #endif
  247. 242:
  248. 243: uniform float logDepthBufFC;
  249. 244:
  250. 245: #endif
  251. 246: void main() {
  252. 247: #if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )
  253. 248:
  254. 249: vUv = uv * offsetRepeat.zw + offsetRepeat.xy;
  255. 250:
  256. 251: #endif
  257. 252: #ifdef USE_LIGHTMAP
  258. 253:
  259. 254: vUv2 = uv2;
  260. 255:
  261. 256: #endif
  262. 257: #ifdef USE_COLOR
  263. 258:
  264. 259: vColor.xyz = inputToLinear( color.xyz );
  265. 260:
  266. 261: #endif
  267. 262: #ifdef USE_MORPHNORMALS
  268. 263:
  269. 264: vec3 morphedNormal = vec3( 0.0 );
  270. 265:
  271. 266: morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];
  272. 267: morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];
  273. 268: morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];
  274. 269: morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];
  275. 270:
  276. 271: morphedNormal += normal;
  277. 272:
  278. 273: #endif
  279. 274: #ifdef USE_SKINNING
  280. 275:
  281. 276: mat4 boneMatX = getBoneMatrix( skinIndex.x );
  282. 277: mat4 boneMatY = getBoneMatrix( skinIndex.y );
  283. 278: mat4 boneMatZ = getBoneMatrix( skinIndex.z );
  284. 279: mat4 boneMatW = getBoneMatrix( skinIndex.w );
  285. 280:
  286. 281: #endif
  287. 282: #ifdef USE_SKINNING
  288. 283:
  289. 284: mat4 skinMatrix = mat4( 0.0 );
  290. 285: skinMatrix += skinWeight.x * boneMatX;
  291. 286: skinMatrix += skinWeight.y * boneMatY;
  292. 287: skinMatrix += skinWeight.z * boneMatZ;
  293. 288: skinMatrix += skinWeight.w * boneMatW;
  294. 289: skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
  295. 290:
  296. 291: #ifdef USE_MORPHNORMALS
  297. 292:
  298. 293: vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );
  299. 294:
  300. 295: #else
  301. 296:
  302. 297: vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );
  303. 298:
  304. 299: #endif
  305. 300:
  306. 301: #endif
  307. 302:
  308. 303: #ifdef USE_SKINNING
  309. 304:
  310. 305: vec3 objectNormal = skinnedNormal.xyz;
  311. 306:
  312. 307: #elif defined( USE_MORPHNORMALS )
  313. 308:
  314. 309: vec3 objectNormal = morphedNormal;
  315. 310:
  316. 311: #else
  317. 312:
  318. 313: vec3 objectNormal = normal;
  319. 314:
  320. 315: #endif
  321. 316:
  322. 317: #ifdef FLIP_SIDED
  323. 318:
  324. 319: objectNormal = -objectNormal;
  325. 320:
  326. 321: #endif
  327. 322:
  328. 323: vec3 transformedNormal = normalMatrix * objectNormal;
  329. 324:
  330. 325: #ifndef FLAT_SHADED
  331. 326: vNormal = normalize( transformedNormal );
  332. 327: #endif
  333. 328: #ifdef USE_MORPHTARGETS
  334. 329:
  335. 330: vec3 morphed = vec3( 0.0 );
  336. 331: morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];
  337. 332: morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];
  338. 333: morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];
  339. 334: morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];
  340. 335:
  341. 336: #ifndef USE_MORPHNORMALS
  342. 337:
  343. 338: morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];
  344. 339: morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];
  345. 340: morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];
  346. 341: morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];
  347. 342:
  348. 343: #endif
  349. 344:
  350. 345: morphed += position;
  351. 346:
  352. 347: #endif
  353. 348: #ifdef USE_SKINNING
  354. 349:
  355. 350: #ifdef USE_MORPHTARGETS
  356. 351:
  357. 352: vec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );
  358. 353:
  359. 354: #else
  360. 355:
  361. 356: vec4 skinVertex = bindMatrix * vec4( position, 1.0 );
  362. 357:
  363. 358: #endif
  364. 359:
  365. 360: vec4 skinned = vec4( 0.0 );
  366. 361: skinned += boneMatX * skinVertex * skinWeight.x;
  367. 362: skinned += boneMatY * skinVertex * skinWeight.y;
  368. 363: skinned += boneMatZ * skinVertex * skinWeight.z;
  369. 364: skinned += boneMatW * skinVertex * skinWeight.w;
  370. 365: skinned = bindMatrixInverse * skinned;
  371. 366:
  372. 367: #endif
  373. 368:
  374. 369: #ifdef USE_SKINNING
  375. 370:
  376. 371: vec4 mvPosition = modelViewMatrix * skinned;
  377. 372:
  378. 373: #elif defined( USE_MORPHTARGETS )
  379. 374:
  380. 375: vec4 mvPosition = modelViewMatrix * vec4( morphed, 1.0 );
  381. 376:
  382. 377: #else
  383. 378:
  384. 379: vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
  385. 380:
  386. 381: #endif
  387. 382:
  388. 383: gl_Position = projectionMatrix * mvPosition;
  389. 384:
  390. 385: #ifdef USE_LOGDEPTHBUF
  391. 386:
  392. 387: gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;
  393. 388:
  394. 389: #ifdef USE_LOGDEPTHBUF_EXT
  395. 390:
  396. 391: vFragDepth = 1.0 + gl_Position.w;
  397. 392:
  398. 393: #else
  399. 394:
  400. 395: gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;
  401. 396:
  402. 397: #endif
  403. 398:
  404. 399: #endif
  405. 400: vViewPosition = -mvPosition.xyz;
  406. 401: #if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )
  407. 402:
  408. 403: #ifdef USE_SKINNING
  409. 404:
  410. 405: vec4 worldPosition = modelMatrix * skinned;
  411. 406:
  412. 407: #elif defined( USE_MORPHTARGETS )
  413. 408:
  414. 409: vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );
  415. 410:
  416. 411: #else
  417. 412:
  418. 413: vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
  419. 414:
  420. 415: #endif
  421. 416:
  422. 417: #endif
  423. 418:
  424. 419: #if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )
  425. 420:
  426. 421: vec3 worldNormal = transformDirection( objectNormal, modelMatrix );
  427. 422:
  428. 423: vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
  429. 424:
  430. 425: #ifdef ENVMAP_MODE_REFLECTION
  431. 426:
  432. 427: vReflect = reflect( cameraToVertex, worldNormal );
  433. 428:
  434. 429: #else
  435. 430:
  436. 431: vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
  437. 432:
  438. 433: #endif
  439. 434:
  440. 435: #endif
  441. 436:
  442. 437: #if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )
  443. 438:
  444. 439: vWorldPosition = worldPosition.xyz;
  445. 440:
  446. 441: #endif
  447. 442: #ifdef USE_SHADOWMAP
  448. 443:
  449. 444: for( int i = 0; i < MAX_SHADOWS; i ++ ) {
  450. 445:
  451. 446: vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;
  452. 447:
  453. 448: }
  454. 449:
  455. 450: #endif
  456. 451: }
  457. three.m...?body=1 (строка 2)
  458. THREE.WebGLShader: gl.getShaderInfoLog()
  459. 0(1) : warning C7022: unrecognized profile specifier "highp"
  460. 0(1) : warning C7022: unrecognized profile specifier "precision"
  461. 0(2) : warning C7022: unrecognized profile specifier "highp"
  462. 0(2) : warning C7022: unrecognized profile specifier "precision"
  463. 1: precision highp float;
  464. 2: precision highp int;
  465. 3:
  466. 4:
  467. 5: #define MAX_DIR_LIGHTS 1
  468. 6: #define MAX_POINT_LIGHTS 0
  469. 7: #define MAX_SPOT_LIGHTS 0
  470. 8: #define MAX_HEMI_LIGHTS 0
  471. 9: #define MAX_SHADOWS 0
  472. 10:
  473. 11:
  474. 12:
  475. 13: #define GAMMA_FACTOR 2
  476. 14:
  477. 15:
  478. 16: #define USE_MAP
  479. 17:
  480. 18:
  481. 19:
  482. 20:
  483. 21:
  484. 22:
  485. 23:
  486. 24:
  487. 25:
  488. 26:
  489. 27:
  490. 28:
  491. 29:
  492. 30:
  493. 31:
  494. 32:
  495. 33:
  496. 34:
  497. 35:
  498. 36:
  499. 37: uniform mat4 viewMatrix;
  500. 38: uniform vec3 cameraPosition;
  501. 39: #define PHONG
  502. 40: uniform vec3 diffuse;
  503. 41: uniform vec3 emissive;
  504. 42: uniform vec3 specular;
  505. 43: uniform float shininess;
  506. 44: uniform float opacity;
  507. 45: #define PI 3.14159
  508. 46: #define PI2 6.28318
  509. 47: #define RECIPROCAL_PI2 0.15915494
  510. 48: #define LOG2 1.442695
  511. 49: #define EPSILON 1e-6
  512. 50:
  513. 51: float square( in float a ) { return a*a; }
  514. 52: vec2 square( in vec2 a ) { return vec2( a.x*a.x, a.y*a.y ); }
  515. 53: vec3 square( in vec3 a ) { return vec3( a.x*a.x, a.y*a.y, a.z*a.z ); }
  516. 54: vec4 square( in vec4 a ) { return vec4( a.x*a.x, a.y*a.y, a.z*a.z, a.w*a.w ); }
  517. 55: float saturate( in float a ) { return clamp( a, 0.0, 1.0 ); }
  518. 56: vec2 saturate( in vec2 a ) { return clamp( a, 0.0, 1.0 ); }
  519. 57: vec3 saturate( in vec3 a ) { return clamp( a, 0.0, 1.0 ); }
  520. 58: vec4 saturate( in vec4 a ) { return clamp( a, 0.0, 1.0 ); }
  521. 59: float average( in float a ) { return a; }
  522. 60: float average( in vec2 a ) { return ( a.x + a.y) * 0.5; }
  523. 61: float average( in vec3 a ) { return ( a.x + a.y + a.z) / 3.0; }
  524. 62: float average( in vec4 a ) { return ( a.x + a.y + a.z + a.w) * 0.25; }
  525. 63: float whiteCompliment( in float a ) { return saturate( 1.0 - a ); }
  526. 64: vec2 whiteCompliment( in vec2 a ) { return saturate( vec2(1.0) - a ); }
  527. 65: vec3 whiteCompliment( in vec3 a ) { return saturate( vec3(1.0) - a ); }
  528. 66: vec4 whiteCompliment( in vec4 a ) { return saturate( vec4(1.0) - a ); }
  529. 67: vec3 transformDirection( in vec3 normal, in mat4 matrix ) {
  530. 68: return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );
  531. 69: }
  532. 70: // http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations
  533. 71: vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {
  534. 72: return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );
  535. 73: }
  536. 74: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal) {
  537. 75: float distance = dot( planeNormal, point-pointOnPlane );
  538. 76: return point - distance * planeNormal;
  539. 77: }
  540. 78: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
  541. 79: return sign( dot( point - pointOnPlane, planeNormal ) );
  542. 80: }
  543. 81: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
  544. 82: return pointOnLine + lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) );
  545. 83: }
  546. 84: float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {
  547. 85: if ( decayExponent > 0.0 ) {
  548. 86: return pow( saturate( 1.0 - lightDistance / cutoffDistance ), decayExponent );
  549. 87: }
  550. 88: return 1.0;
  551. 89: }
  552. 90:
  553. 91: vec3 inputToLinear( in vec3 a ) {
  554. 92: #ifdef GAMMA_INPUT
  555. 93: return pow( a, vec3( float( GAMMA_FACTOR ) ) );
  556. 94: #else
  557. 95: return a;
  558. 96: #endif
  559. 97: }
  560. 98: vec3 linearToOutput( in vec3 a ) {
  561. 99: #ifdef GAMMA_OUTPUT
  562. 100: return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );
  563. 101: #else
  564. 102: return a;
  565. 103: #endif
  566. 104: }
  567. 105:
  568. 106: #ifdef USE_COLOR
  569. 107:
  570. 108: varying vec3 vColor;
  571. 109:
  572. 110: #endif
  573. 111:
  574. 112: #if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )
  575. 113:
  576. 114: varying vec2 vUv;
  577. 115:
  578. 116: #endif
  579. 117:
  580. 118: #ifdef USE_MAP
  581. 119:
  582. 120: uniform sampler2D map;
  583. 121:
  584. 122: #endif
  585. 123: #ifdef USE_ALPHAMAP
  586. 124:
  587. 125: uniform sampler2D alphaMap;
  588. 126:
  589. 127: #endif
  590. 128:
  591. 129: #ifdef USE_LIGHTMAP
  592. 130:
  593. 131: varying vec2 vUv2;
  594. 132: uniform sampler2D lightMap;
  595. 133:
  596. 134: #endif
  597. 135: #ifdef USE_ENVMAP
  598. 136:
  599. 137: uniform float reflectivity;
  600. 138: #ifdef ENVMAP_TYPE_CUBE
  601. 139: uniform samplerCube envMap;
  602. 140: #else
  603. 141: uniform sampler2D envMap;
  604. 142: #endif
  605. 143: uniform float flipEnvMap;
  606. 144:
  607. 145: #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
  608. 146:
  609. 147: uniform float refractionRatio;
  610. 148:
  611. 149: #else
  612. 150:
  613. 151: varying vec3 vReflect;
  614. 152:
  615. 153: #endif
  616. 154:
  617. 155: #endif
  618. 156:
  619. 157: #ifdef USE_FOG
  620. 158:
  621. 159: uniform vec3 fogColor;
  622. 160:
  623. 161: #ifdef FOG_EXP2
  624. 162:
  625. 163: uniform float fogDensity;
  626. 164:
  627. 165: #else
  628. 166:
  629. 167: uniform float fogNear;
  630. 168: uniform float fogFar;
  631. 169: #endif
  632. 170:
  633. 171: #endif
  634. 172: uniform vec3 ambientLightColor;
  635. 173:
  636. 174: #if MAX_DIR_LIGHTS > 0
  637. 175:
  638. 176: uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
  639. 177: uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
  640. 178:
  641. 179: #endif
  642. 180:
  643. 181: #if MAX_HEMI_LIGHTS > 0
  644. 182:
  645. 183: uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];
  646. 184: uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];
  647. 185: uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];
  648. 186:
  649. 187: #endif
  650. 188:
  651. 189: #if MAX_POINT_LIGHTS > 0
  652. 190:
  653. 191: uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
  654. 192:
  655. 193: uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
  656. 194: uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
  657. 195: uniform float pointLightDecay[ MAX_POINT_LIGHTS ];
  658. 196:
  659. 197: #endif
  660. 198:
  661. 199: #if MAX_SPOT_LIGHTS > 0
  662. 200:
  663. 201: uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];
  664. 202: uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];
  665. 203: uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];
  666. 204: uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];
  667. 205: uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];
  668. 206: uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];
  669. 207: uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];
  670. 208:
  671. 209: #endif
  672. 210:
  673. 211: #if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )
  674. 212:
  675. 213: varying vec3 vWorldPosition;
  676. 214:
  677. 215: #endif
  678. 216:
  679. 217: #ifdef WRAP_AROUND
  680. 218:
  681. 219: uniform vec3 wrapRGB;
  682. 220:
  683. 221: #endif
  684. 222:
  685. 223: varying vec3 vViewPosition;
  686. 224:
  687. 225: #ifndef FLAT_SHADED
  688. 226:
  689. 227: varying vec3 vNormal;
  690. 228:
  691. 229: #endif
  692. 230:
  693. 231: #ifdef USE_SHADOWMAP
  694. 232:
  695. 233: uniform sampler2D shadowMap[ MAX_SHADOWS ];
  696. 234: uniform vec2 shadowMapSize[ MAX_SHADOWS ];
  697. 235:
  698. 236: uniform float shadowDarkness[ MAX_SHADOWS ];
  699. 237: uniform float shadowBias[ MAX_SHADOWS ];
  700. 238:
  701. 239: varying vec4 vShadowCoord[ MAX_SHADOWS ];
  702. 240:
  703. 241: float unpackDepth( const in vec4 rgba_depth ) {
  704. 242:
  705. 243: const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );
  706. 244: float depth = dot( rgba_depth, bit_shift );
  707. 245: return depth;
  708. 246:
  709. 247: }
  710. 248:
  711. 249: #endif
  712. 250: #ifdef USE_BUMPMAP
  713. 251:
  714. 252: uniform sampler2D bumpMap;
  715. 253: uniform float bumpScale;
  716. 254:
  717. 255: // Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen
  718. 256: // http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html
  719. 257:
  720. 258: // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)
  721. 259:
  722. 260: vec2 dHdxy_fwd() {
  723. 261:
  724. 262: vec2 dSTdx = dFdx( vUv );
  725. 263: vec2 dSTdy = dFdy( vUv );
  726. 264:
  727. 265: float Hll = bumpScale * texture2D( bumpMap, vUv ).x;
  728. 266: float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;
  729. 267: float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;
  730. 268:
  731. 269: return vec2( dBx, dBy );
  732. 270:
  733. 271: }
  734. 272:
  735. 273: vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {
  736. 274:
  737. 275: vec3 vSigmaX = dFdx( surf_pos );
  738. 276: vec3 vSigmaY = dFdy( surf_pos );
  739. 277: vec3 vN = surf_norm; // normalized
  740. 278:
  741. 279: vec3 R1 = cross( vSigmaY, vN );
  742. 280: vec3 R2 = cross( vN, vSigmaX );
  743. 281:
  744. 282: float fDet = dot( vSigmaX, R1 );
  745. 283:
  746. 284: vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
  747. 285: return normalize( abs( fDet ) * surf_norm - vGrad );
  748. 286:
  749. 287: }
  750. 288:
  751. 289: #endif
  752. 290:
  753. 291: #ifdef USE_NORMALMAP
  754. 292:
  755. 293: uniform sampler2D normalMap;
  756. 294: uniform vec2 normalScale;
  757. 295:
  758. 296: // Per-Pixel Tangent Space Normal Mapping
  759. 297: // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
  760. 298:
  761. 299: vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
  762. 300:
  763. 301: vec3 q0 = dFdx( eye_pos.xyz );
  764. 302: vec3 q1 = dFdy( eye_pos.xyz );
  765. 303: vec2 st0 = dFdx( vUv.st );
  766. 304: vec2 st1 = dFdy( vUv.st );
  767. 305:
  768. 306: vec3 S = normalize( q0 * st1.t - q1 * st0.t );
  769. 307: vec3 T = normalize( -q0 * st1.s + q1 * st0.s );
  770. 308: vec3 N = normalize( surf_norm );
  771. 309:
  772. 310: vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
  773. 311: mapN.xy = normalScale * mapN.xy;
  774. 312: mat3 tsn = mat3( S, T, N );
  775. 313: return normalize( tsn * mapN );
  776. 314:
  777. 315: }
  778. 316:
  779. 317: #endif
  780. 318:
  781. 319: #ifdef USE_SPECULARMAP
  782. 320:
  783. 321: uniform sampler2D specularMap;
  784. 322:
  785. 323: #endif
  786. 324: #ifdef USE_LOGDEPTHBUF
  787. 325:
  788. 326: uniform float logDepthBufFC;
  789. 327:
  790. 328: #ifdef USE_LOGDEPTHBUF_EXT
  791. 329:
  792. 330: #extension GL_EXT_frag_depth : enable
  793. 331: varying float vFragDepth;
  794. 332:
  795. 333: #endif
  796. 334:
  797. 335: #endif
  798. 336: void main() {
  799. 337: vec3 outgoingLight = vec3( 0.0 );
  800. 338: vec4 diffuseColor = vec4( diffuse, opacity );
  801. 339: #if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)
  802. 340:
  803. 341: gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;
  804. 342:
  805. 343: #endif
  806. 344: #ifdef USE_MAP
  807. 345:
  808. 346: vec4 texelColor = texture2D( map, vUv );
  809. 347:
  810. 348: texelColor.xyz = inputToLinear( texelColor.xyz );
  811. 349:
  812. 350: diffuseColor *= texelColor;
  813. 351:
  814. 352: #endif
  815. 353: #ifdef USE_COLOR
  816. 354:
  817. 355: diffuseColor.rgb *= vColor;
  818. 356:
  819. 357: #endif
  820. 358: #ifdef USE_ALPHAMAP
  821. 359:
  822. 360: diffuseColor.a *= texture2D( alphaMap, vUv ).g;
  823. 361:
  824. 362: #endif
  825. 363:
  826. 364: #ifdef ALPHATEST
  827. 365:
  828. 366: if ( diffuseColor.a < ALPHATEST ) discard;
  829. 367:
  830. 368: #endif
  831. 369:
  832. 370: float specularStrength;
  833. 371:
  834. 372: #ifdef USE_SPECULARMAP
  835. 373:
  836. 374: vec4 texelSpecular = texture2D( specularMap, vUv );
  837. 375: specularStrength = texelSpecular.r;
  838. 376:
  839. 377: #else
  840. 378:
  841. 379: specularStrength = 1.0;
  842. 380:
  843. 381: #endif
  844. 382: #ifndef FLAT_SHADED
  845. 383:
  846. 384: vec3 normal = normalize( vNormal );
  847. 385:
  848. 386: #ifdef DOUBLE_SIDED
  849. 387:
  850. 388: normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );
  851. 389:
  852. 390: #endif
  853. 391:
  854. 392: #else
  855. 393:
  856. 394: vec3 fdx = dFdx( vViewPosition );
  857. 395: vec3 fdy = dFdy( vViewPosition );
  858. 396: vec3 normal = normalize( cross( fdx, fdy ) );
  859. 397:
  860. 398: #endif
  861. 399:
  862. 400: vec3 viewPosition = normalize( vViewPosition );
  863. 401:
  864. 402: #ifdef USE_NORMALMAP
  865. 403:
  866. 404: normal = perturbNormal2Arb( -vViewPosition, normal );
  867. 405:
  868. 406: #elif defined( USE_BUMPMAP )
  869. 407:
  870. 408: normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );
  871. 409:
  872. 410: #endif
  873. 411:
  874. 412: vec3 totalDiffuseLight = vec3( 0.0 );
  875. 413: vec3 totalSpecularLight = vec3( 0.0 );
  876. 414:
  877. 415: #if MAX_POINT_LIGHTS > 0
  878. 416:
  879. 417: for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
  880. 418:
  881. 419: vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
  882. 420: vec3 lVector = lPosition.xyz + vViewPosition.xyz;
  883. 421:
  884. 422: float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );
  885. 423:
  886. 424: lVector = normalize( lVector );
  887. 425:
  888. 426: // diffuse
  889. 427:
  890. 428: float dotProduct = dot( normal, lVector );
  891. 429:
  892. 430: #ifdef WRAP_AROUND
  893. 431:
  894. 432: float pointDiffuseWeightFull = max( dotProduct, 0.0 );
  895. 433: float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );
  896. 434:
  897. 435: vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );
  898. 436:
  899. 437: #else
  900. 438:
  901. 439: float pointDiffuseWeight = max( dotProduct, 0.0 );
  902. 440:
  903. 441: #endif
  904. 442:
  905. 443: totalDiffuseLight += pointLightColor[ i ] * pointDiffuseWeight * attenuation;
  906. 444:
  907. 445: // specular
  908. 446:
  909. 447: vec3 pointHalfVector = normalize( lVector + viewPosition );
  910. 448: float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
  911. 449: float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );
  912. 450:
  913. 451: float specularNormalization = ( shininess + 2.0 ) / 8.0;
  914. 452:
  915. 453: vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );
  916. 454: totalSpecularLight += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * attenuation * specularNormalization;
  917. 455:
  918. 456: }
  919. 457:
  920. 458: #endif
  921. 459:
  922. 460: #if MAX_SPOT_LIGHTS > 0
  923. 461:
  924. 462: for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
  925. 463:
  926. 464: vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );
  927. 465: vec3 lVector = lPosition.xyz + vViewPosition.xyz;
  928. 466:
  929. 467: float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );
  930. 468:
  931. 469: lVector = normalize( lVector );
  932. 470:
  933. 471: float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );
  934. 472:
  935. 473: if ( spotEffect > spotLightAngleCos[ i ] ) {
  936. 474:
  937. 475: spotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );
  938. 476:
  939. 477: // diffuse
  940. 478:
  941. 479: float dotProduct = dot( normal, lVector );
  942. 480:
  943. 481: #ifdef WRAP_AROUND
  944. 482:
  945. 483: float spotDiffuseWeightFull = max( dotProduct, 0.0 );
  946. 484: float spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );
  947. 485:
  948. 486: vec3 spotDiffuseWeight = mix( vec3( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );
  949. 487:
  950. 488: #else
  951. 489:
  952. 490: float spotDiffuseWeight = max( dotProduct, 0.0 );
  953. 491:
  954. 492: #endif
  955. 493:
  956. 494: totalDiffuseLight += spotLightColor[ i ] * spotDiffuseWeight * attenuation * spotEffect;
  957. 495:
  958. 496: // specular
  959. 497:
  960. 498: vec3 spotHalfVector = normalize( lVector + viewPosition );
  961. 499: float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );
  962. 500: float spotSpecularWeight = specularStrength * max( pow( spotDotNormalHalf, shininess ), 0.0 );
  963. 501:
  964. 502: float specularNormalization = ( shininess + 2.0 ) / 8.0;
  965. 503:
  966. 504: vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, spotHalfVector ), 0.0 ), 5.0 );
  967. 505: totalSpecularLight += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * attenuation * specularNormalization * spotEffect;
  968. 506:
  969. 507: }
  970. 508:
  971. 509: }
  972. 510:
  973. 511: #endif
  974. 512:
  975. 513: #if MAX_DIR_LIGHTS > 0
  976. 514:
  977. 515: for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
  978. 516:
  979. 517: vec3 dirVector = transformDirection( directionalLightDirection[ i ], viewMatrix );
  980. 518:
  981. 519: // diffuse
  982. 520:
  983. 521: float dotProduct = dot( normal, dirVector );
  984. 522:
  985. 523: #ifdef WRAP_AROUND
  986. 524:
  987. 525: float dirDiffuseWeightFull = max( dotProduct, 0.0 );
  988. 526: float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );
  989. 527:
  990. 528: vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );
  991. 529:
  992. 530: #else
  993. 531:
  994. 532: float dirDiffuseWeight = max( dotProduct, 0.0 );
  995. 533:
  996. 534: #endif
  997. 535:
  998. 536: totalDiffuseLight += directionalLightColor[ i ] * dirDiffuseWeight;
  999. 537:
  1000. 538: // specular
  1001. 539:
  1002. 540: vec3 dirHalfVector = normalize( dirVector + viewPosition );
  1003. 541: float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
  1004. 542: float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );
  1005. 543:
  1006. 544: /*
  1007. 545: // fresnel term from skin shader
  1008. 546: const float F0 = 0.128;
  1009. 547:
  1010. 548: float base = 1.0 - dot( viewPosition, dirHalfVector );
  1011. 549: float exponential = pow( base, 5.0 );
  1012. 550:
  1013. 551: float fresnel = exponential + F0 * ( 1.0 - exponential );
  1014. 552: */
  1015. 553:
  1016. 554: /*
  1017. 555: // fresnel term from fresnel shader
  1018. 556: const float mFresnelBias = 0.08;
  1019. 557: const float mFresnelScale = 0.3;
  1020. 558: const float mFresnelPower = 5.0;
  1021. 559:
  1022. 560: float fresnel = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( -viewPosition ), normal ), mFresnelPower );
  1023. 561: */
  1024. 562:
  1025. 563: float specularNormalization = ( shininess + 2.0 ) / 8.0;
  1026. 564:
  1027. 565: // dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization * fresnel;
  1028. 566:
  1029. 567: vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );
  1030. 568: totalSpecularLight += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;
  1031. 569:
  1032. 570:
  1033. 571: }
  1034. 572:
  1035. 573: #endif
  1036. 574:
  1037. 575: #if MAX_HEMI_LIGHTS > 0
  1038. 576:
  1039. 577: for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
  1040. 578:
  1041. 579: vec3 lVector = transformDirection( hemisphereLightDirection[ i ], viewMatrix );
  1042. 580:
  1043. 581: // diffuse
  1044. 582:
  1045. 583: float dotProduct = dot( normal, lVector );
  1046. 584: float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;
  1047. 585:
  1048. 586: vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );
  1049. 587:
  1050. 588: totalDiffuseLight += hemiColor;
  1051. 589:
  1052. 590: // specular (sky light)
  1053. 591:
  1054. 592: vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );
  1055. 593: float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;
  1056. 594: float hemiSpecularWeightSky = specularStrength * max( pow( max( hemiDotNormalHalfSky, 0.0 ), shininess ), 0.0 );
  1057. 595:
  1058. 596: // specular (ground light)
  1059. 597:
  1060. 598: vec3 lVectorGround = -lVector;
  1061. 599:
  1062. 600: vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );
  1063. 601: float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;
  1064. 602: float hemiSpecularWeightGround = specularStrength * max( pow( max( hemiDotNormalHalfGround, 0.0 ), shininess ), 0.0 );
  1065. 603:
  1066. 604: float dotProductGround = dot( normal, lVectorGround );
  1067. 605:
  1068. 606: float specularNormalization = ( shininess + 2.0 ) / 8.0;
  1069. 607:
  1070. 608: vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );
  1071. 609: vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );
  1072. 610: totalSpecularLight += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );
  1073. 611:
  1074. 612: }
  1075. 613:
  1076. 614: #endif
  1077. 615:
  1078. 616: #ifdef METAL
  1079. 617:
  1080. 618: outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + ambientLightColor ) * specular + totalSpecularLight + emissive;
  1081. 619:
  1082. 620: #else
  1083. 621:
  1084. 622: outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + ambientLightColor ) + totalSpecularLight + emissive;
  1085. 623:
  1086. 624: #endif
  1087. 625:
  1088. 626: #ifdef USE_LIGHTMAP
  1089. 627:
  1090. 628: outgoingLight *= diffuseColor.xyz * texture2D( lightMap, vUv2 ).xyz;
  1091. 629:
  1092. 630: #endif
  1093. 631: #ifdef USE_ENVMAP
  1094. 632:
  1095. 633: #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
  1096. 634:
  1097. 635: vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );
  1098. 636:
  1099. 637: // Transforming Normal Vectors with the Inverse Transformation
  1100. 638: vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
  1101. 639:
  1102. 640: #ifdef ENVMAP_MODE_REFLECTION
  1103. 641:
  1104. 642: vec3 reflectVec = reflect( cameraToVertex, worldNormal );
  1105. 643:
  1106. 644: #else
  1107. 645:
  1108. 646: vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );
  1109. 647:
  1110. 648: #endif
  1111. 649:
  1112. 650: #else
  1113. 651:
  1114. 652: vec3 reflectVec = vReflect;
  1115. 653:
  1116. 654: #endif
  1117. 655:
  1118. 656: #ifdef DOUBLE_SIDED
  1119. 657: float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );
  1120. 658: #else
  1121. 659: float flipNormal = 1.0;
  1122. 660: #endif
  1123. 661:
  1124. 662: #ifdef ENVMAP_TYPE_CUBE
  1125. 663: vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
  1126. 664:
  1127. 665: #elif defined( ENVMAP_TYPE_EQUIREC )
  1128. 666: vec2 sampleUV;
  1129. 667: sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );
  1130. 668: sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
  1131. 669: vec4 envColor = texture2D( envMap, sampleUV );
  1132. 670:
  1133. 671: #elif defined( ENVMAP_TYPE_SPHERE )
  1134. 672: vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));
  1135. 673: vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );
  1136. 674: #endif
  1137. 675:
  1138. 676: envColor.xyz = inputToLinear( envColor.xyz );
  1139. 677:
  1140. 678: #ifdef ENVMAP_BLENDING_MULTIPLY
  1141. 679:
  1142. 680: outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
  1143. 681:
  1144. 682: #elif defined( ENVMAP_BLENDING_MIX )
  1145. 683:
  1146. 684: outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
  1147. 685:
  1148. 686: #elif defined( ENVMAP_BLENDING_ADD )
  1149. 687:
  1150. 688: outgoingLight += envColor.xyz * specularStrength * reflectivity;
  1151. 689:
  1152. 690: #endif
  1153. 691:
  1154. 692: #endif
  1155. 693:
  1156. 694: #ifdef USE_SHADOWMAP
  1157. 695:
  1158. 696: #ifdef SHADOWMAP_DEBUG
  1159. 697:
  1160. 698: vec3 frustumColors[3];
  1161. 699: frustumColors[0] = vec3( 1.0, 0.5, 0.0 );
  1162. 700: frustumColors[1] = vec3( 0.0, 1.0, 0.8 );
  1163. 701: frustumColors[2] = vec3( 0.0, 0.5, 1.0 );
  1164. 702:
  1165. 703: #endif
  1166. 704:
  1167. 705: #ifdef SHADOWMAP_CASCADE
  1168. 706:
  1169. 707: int inFrustumCount = 0;
  1170. 708:
  1171. 709: #endif
  1172. 710:
  1173. 711: float fDepth;
  1174. 712: vec3 shadowColor = vec3( 1.0 );
  1175. 713:
  1176. 714: for( int i = 0; i < MAX_SHADOWS; i ++ ) {
  1177. 715:
  1178. 716: vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;
  1179. 717:
  1180. 718: // if ( something && something ) breaks ATI OpenGL shader compiler
  1181. 719: // if ( all( something, something ) ) using this instead
  1182. 720:
  1183. 721: bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );
  1184. 722: bool inFrustum = all( inFrustumVec );
  1185. 723:
  1186. 724: // don't shadow pixels outside of light frustum
  1187. 725: // use just first frustum (for cascades)
  1188. 726: // don't shadow pixels behind far plane of light frustum
  1189. 727:
  1190. 728: #ifdef SHADOWMAP_CASCADE
  1191. 729:
  1192. 730: inFrustumCount += int( inFrustum );
  1193. 731: bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );
  1194. 732:
  1195. 733: #else
  1196. 734:
  1197. 735: bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );
  1198. 736:
  1199. 737: #endif
  1200. 738:
  1201. 739: bool frustumTest = all( frustumTestVec );
  1202. 740:
  1203. 741: if ( frustumTest ) {
  1204. 742:
  1205. 743: shadowCoord.z += shadowBias[ i ];
  1206. 744:
  1207. 745: #if defined( SHADOWMAP_TYPE_PCF )
  1208. 746:
  1209. 747: // Percentage-close filtering
  1210. 748: // (9 pixel kernel)
  1211. 749: // http://fabiensanglard.net/shadowmappingPCF/
  1212. 750:
  1213. 751: float shadow = 0.0;
  1214. 752:
  1215. 753: /*
  1216. 754: // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
  1217. 755: // must enroll loop manually
  1218. 756:
  1219. 757: for ( float y = -1.25; y <= 1.25; y += 1.25 )
  1220. 758: for ( float x = -1.25; x <= 1.25; x += 1.25 ) {
  1221. 759:
  1222. 760: vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );
  1223. 761:
  1224. 762: // doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup
  1225. 763: //vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );
  1226. 764:
  1227. 765: float fDepth = unpackDepth( rgbaDepth );
  1228. 766:
  1229. 767: if ( fDepth < shadowCoord.z )
  1230. 768: shadow += 1.0;
  1231. 769:
  1232. 770: }
  1233. 771:
  1234. 772: shadow /= 9.0;
  1235. 773:
  1236. 774: */
  1237. 775:
  1238. 776: const float shadowDelta = 1.0 / 9.0;
  1239. 777:
  1240. 778: float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
  1241. 779: float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
  1242. 780:
  1243. 781: float dx0 = -1.25 * xPixelOffset;
  1244. 782: float dy0 = -1.25 * yPixelOffset;
  1245. 783: float dx1 = 1.25 * xPixelOffset;
  1246. 784: float dy1 = 1.25 * yPixelOffset;
  1247. 785:
  1248. 786: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
  1249. 787: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1250. 788:
  1251. 789: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
  1252. 790: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1253. 791:
  1254. 792: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
  1255. 793: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1256. 794:
  1257. 795: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
  1258. 796: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1259. 797:
  1260. 798: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );
  1261. 799: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1262. 800:
  1263. 801: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
  1264. 802: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1265. 803:
  1266. 804: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
  1267. 805: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1268. 806:
  1269. 807: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
  1270. 808: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1271. 809:
  1272. 810: fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
  1273. 811: if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
  1274. 812:
  1275. 813: shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );
  1276. 814:
  1277. 815: #elif defined( SHADOWMAP_TYPE_PCF_SOFT )
  1278. 816:
  1279. 817: // Percentage-close filtering
  1280. 818: // (9 pixel kernel)
  1281. 819: // http://fabiensanglard.net/shadowmappingPCF/
  1282. 820:
  1283. 821: float shadow = 0.0;
  1284. 822:
  1285. 823: float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
  1286. 824: float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
  1287. 825:
  1288. 826: float dx0 = -1.0 * xPixelOffset;
  1289. 827: float dy0 = -1.0 * yPixelOffset;
  1290. 828: float dx1 = 1.0 * xPixelOffset;
  1291. 829: float dy1 = 1.0 * yPixelOffset;
  1292. 830:
  1293. 831: mat3 shadowKernel;
  1294. 832: mat3 depthKernel;
  1295. 833:
  1296. 834: depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
  1297. 835: depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
  1298. 836: depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
  1299. 837: depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
  1300. 838: depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );
  1301. 839: depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
  1302. 840: depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
  1303. 841: depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
  1304. 842: depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
  1305. 843:
  1306. 844: vec3 shadowZ = vec3( shadowCoord.z );
  1307. 845: shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));
  1308. 846: shadowKernel[0] *= vec3(0.25);
  1309. 847:
  1310. 848: shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));
  1311. 849: shadowKernel[1] *= vec3(0.25);
  1312. 850:
  1313. 851: shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));
  1314. 852: shadowKernel[2] *= vec3(0.25);
  1315. 853:
  1316. 854: vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );
  1317. 855:
  1318. 856: shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );
  1319. 857: shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );
  1320. 858:
  1321. 859: vec4 shadowValues;
  1322. 860: shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );
  1323. 861: shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );
  1324. 862: shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );
  1325. 863: shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );
  1326. 864:
  1327. 865: shadow = dot( shadowValues, vec4( 1.0 ) );
  1328. 866:
  1329. 867: shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );
  1330. 868:
  1331. 869: #else
  1332. 870:
  1333. 871: vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );
  1334. 872: float fDepth = unpackDepth( rgbaDepth );
  1335. 873:
  1336. 874: if ( fDepth < shadowCoord.z )
  1337. 875:
  1338. 876: // spot with multiple shadows is darker
  1339. 877:
  1340. 878: shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );
  1341. 879:
  1342. 880: // spot with multiple shadows has the same color as single shadow spot
  1343. 881:
  1344. 882: // shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );
  1345. 883:
  1346. 884: #endif
  1347. 885:
  1348. 886: }
  1349. 887:
  1350. 888:
  1351. 889: #ifdef SHADOWMAP_DEBUG
  1352. 890:
  1353. 891: #ifdef SHADOWMAP_CASCADE
  1354. 892:
  1355. 893: if ( inFrustum && inFrustumCount == 1 ) outgoingLight *= frustumColors[ i ];
  1356. 894:
  1357. 895: #else
  1358. 896:
  1359. 897: if ( inFrustum ) outgoingLight *= frustumColors[ i ];
  1360. 898:
  1361. 899: #endif
  1362. 900:
  1363. 901: #endif
  1364. 902:
  1365. 903: }
  1366. 904:
  1367. 905: // NOTE: I am unsure if this is correct in linear space. -bhouston, Dec 29, 2014
  1368. 906: shadowColor = inputToLinear( shadowColor );
  1369. 907:
  1370. 908: outgoingLight = outgoingLight * shadowColor;
  1371. 909:
  1372. 910: #endif
  1373. 911:
  1374. 912:
  1375. 913: outgoingLight = linearToOutput( outgoingLight );
  1376. 914:
  1377. 915: #ifdef USE_FOG
  1378. 916:
  1379. 917: #ifdef USE_LOGDEPTHBUF_EXT
  1380. 918:
  1381. 919: float depth = gl_FragDepthEXT / gl_FragCoord.w;
  1382. 920:
  1383. 921: #else
  1384. 922:
  1385. 923: float depth = gl_FragCoord.z / gl_FragCoord.w;
  1386. 924:
  1387. 925: #endif
  1388. 926:
  1389. 927: #ifdef FOG_EXP2
  1390. 928:
  1391. 929: float fogFactor = exp2( - square( fogDensity ) * square( depth ) * LOG2 );
  1392. 930: fogFactor = whiteCompliment( fogFactor );
  1393. 931:
  1394. 932: #else
  1395. 933:
  1396. 934: float fogFactor = smoothstep( fogNear, fogFar, depth );
  1397. 935:
  1398. 936: #endif
  1399. 937:
  1400. 938: outgoingLight = mix( outgoingLight, fogColor, fogFactor );
  1401. 939:
  1402. 940: #endif
  1403. 941: gl_FragColor = vec4( outgoingLight, diffuseColor.a );
  1404. 942: }
  1405. three.m...?body=1 (line 2)
  1406. THREE.WebGLProgram: gl.getProgramInfoLog()Vertex info
  1407. -----------
  1408. 0(1) : warning C7022: unrecognized profile specifier "highp"
  1409. 0(1) : warning C7022: unrecognized profile specifier "precision"
  1410. 0(2) : warning C7022: unrecognized profile specifier "highp"
  1411. 0(2) : warning C7022: unrecognized profile specifier "precision"
  1412. Fragment info
  1413. -------------
  1414. 0(1) : warning C7022: unrecognized profile specifier "highp"
  1415. 0(1) : warning C7022: unrecognized profile specifier "precision"
  1416. 0(2) : warning C7022: unrecognized profile specifier "highp"
  1417. 0(2) : warning C7022: unrecognized profile specifier "precision"