fur.fragment.fx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. precision highp float;
  2. // Constants
  3. uniform vec3 vEyePosition;
  4. uniform vec4 vDiffuseColor;
  5. // Input
  6. uniform vec4 furColor;
  7. varying vec3 vPositionW;
  8. varying float vfur_length;
  9. #ifdef NORMAL
  10. varying vec3 vNormalW;
  11. #endif
  12. #ifdef VERTEXCOLOR
  13. varying vec4 vColor;
  14. #endif
  15. // Lights
  16. #ifdef LIGHT0
  17. uniform vec4 vLightData0;
  18. uniform vec4 vLightDiffuse0;
  19. #ifdef SHADOW0
  20. #if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
  21. varying vec4 vPositionFromLight0;
  22. uniform sampler2D shadowSampler0;
  23. #else
  24. uniform samplerCube shadowSampler0;
  25. #endif
  26. uniform vec3 shadowsInfo0;
  27. #endif
  28. #ifdef SPOTLIGHT0
  29. uniform vec4 vLightDirection0;
  30. #endif
  31. #ifdef HEMILIGHT0
  32. uniform vec3 vLightGround0;
  33. #endif
  34. #endif
  35. #ifdef LIGHT1
  36. uniform vec4 vLightData1;
  37. uniform vec4 vLightDiffuse1;
  38. #ifdef SHADOW1
  39. #if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
  40. varying vec4 vPositionFromLight1;
  41. uniform sampler2D shadowSampler1;
  42. #else
  43. uniform samplerCube shadowSampler1;
  44. #endif
  45. uniform vec3 shadowsInfo1;
  46. #endif
  47. #ifdef SPOTLIGHT1
  48. uniform vec4 vLightDirection1;
  49. #endif
  50. #ifdef HEMILIGHT1
  51. uniform vec3 vLightGround1;
  52. #endif
  53. #endif
  54. #ifdef LIGHT2
  55. uniform vec4 vLightData2;
  56. uniform vec4 vLightDiffuse2;
  57. #ifdef SHADOW2
  58. #if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
  59. varying vec4 vPositionFromLight2;
  60. uniform sampler2D shadowSampler2;
  61. #else
  62. uniform samplerCube shadowSampler2;
  63. #endif
  64. uniform vec3 shadowsInfo2;
  65. #endif
  66. #ifdef SPOTLIGHT2
  67. uniform vec4 vLightDirection2;
  68. #endif
  69. #ifdef HEMILIGHT2
  70. uniform vec3 vLightGround2;
  71. #endif
  72. #endif
  73. #ifdef LIGHT3
  74. uniform vec4 vLightData3;
  75. uniform vec4 vLightDiffuse3;
  76. #ifdef SHADOW3
  77. #if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
  78. varying vec4 vPositionFromLight3;
  79. uniform sampler2D shadowSampler3;
  80. #else
  81. uniform samplerCube shadowSampler3;
  82. #endif
  83. uniform vec3 shadowsInfo3;
  84. #endif
  85. #ifdef SPOTLIGHT3
  86. uniform vec4 vLightDirection3;
  87. #endif
  88. #ifdef HEMILIGHT3
  89. uniform vec3 vLightGround3;
  90. #endif
  91. #endif
  92. // Samplers
  93. #ifdef DIFFUSE
  94. varying vec2 vDiffuseUV;
  95. uniform sampler2D diffuseSampler;
  96. uniform vec2 vDiffuseInfos;
  97. #endif
  98. // Fur uniforms
  99. #ifdef HIGHLEVEL
  100. uniform float furOffset;
  101. uniform sampler2D furTexture;
  102. varying vec2 vFurUV;
  103. #endif
  104. // Shadows
  105. #ifdef SHADOWS
  106. float unpack(vec4 color)
  107. {
  108. const vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);
  109. return dot(color, bit_shift);
  110. }
  111. #if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)
  112. float computeShadowCube(vec3 lightPosition, samplerCube shadowSampler, float darkness, float bias)
  113. {
  114. vec3 directionToLight = vPositionW - lightPosition;
  115. float depth = length(directionToLight);
  116. depth = clamp(depth, 0., 1.);
  117. directionToLight.y = 1.0 - directionToLight.y;
  118. float shadow = unpack(textureCube(shadowSampler, directionToLight)) + bias;
  119. if (depth > shadow)
  120. {
  121. return darkness;
  122. }
  123. return 1.0;
  124. }
  125. float computeShadowWithPCFCube(vec3 lightPosition, samplerCube shadowSampler, float bias, float darkness)
  126. {
  127. vec3 directionToLight = vPositionW - lightPosition;
  128. float depth = length(directionToLight);
  129. depth = clamp(depth, 0., 1.);
  130. directionToLight.y = 1.0 - directionToLight.y;
  131. float visibility = 1.;
  132. vec3 poissonDisk[4];
  133. poissonDisk[0] = vec3(-0.094201624, 0.04, -0.039906216);
  134. poissonDisk[1] = vec3(0.094558609, -0.04, -0.076890725);
  135. poissonDisk[2] = vec3(-0.094184101, 0.01, -0.092938870);
  136. poissonDisk[3] = vec3(0.034495938, -0.01, 0.029387760);
  137. // Poisson Sampling
  138. float biasedDepth = depth - bias;
  139. if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[0])) < biasedDepth) visibility -= 0.25;
  140. if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[1])) < biasedDepth) visibility -= 0.25;
  141. if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[2])) < biasedDepth) visibility -= 0.25;
  142. if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[3])) < biasedDepth) visibility -= 0.25;
  143. return min(1.0, visibility + darkness);
  144. }
  145. #endif
  146. #if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)
  147. float computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)
  148. {
  149. vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
  150. depth = 0.5 * depth + vec3(0.5);
  151. vec2 uv = depth.xy;
  152. if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
  153. {
  154. return 1.0;
  155. }
  156. float shadow = unpack(texture2D(shadowSampler, uv)) + bias;
  157. if (depth.z > shadow)
  158. {
  159. return darkness;
  160. }
  161. return 1.;
  162. }
  163. float computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias, float darkness)
  164. {
  165. vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
  166. depth = 0.5 * depth + vec3(0.5);
  167. vec2 uv = depth.xy;
  168. if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)
  169. {
  170. return 1.0;
  171. }
  172. float visibility = 1.;
  173. vec2 poissonDisk[4];
  174. poissonDisk[0] = vec2(-0.94201624, -0.39906216);
  175. poissonDisk[1] = vec2(0.94558609, -0.76890725);
  176. poissonDisk[2] = vec2(-0.094184101, -0.92938870);
  177. poissonDisk[3] = vec2(0.34495938, 0.29387760);
  178. // Poisson Sampling
  179. float biasedDepth = depth.z - bias;
  180. if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] / mapSize)) < biasedDepth) visibility -= 0.25;
  181. if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] / mapSize)) < biasedDepth) visibility -= 0.25;
  182. if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] / mapSize)) < biasedDepth) visibility -= 0.25;
  183. if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] / mapSize)) < biasedDepth) visibility -= 0.25;
  184. return min(1.0, visibility + darkness);
  185. }
  186. // Thanks to http://devmaster.net/
  187. float unpackHalf(vec2 color)
  188. {
  189. return color.x + (color.y / 255.0);
  190. }
  191. float linstep(float low, float high, float v) {
  192. return clamp((v - low) / (high - low), 0.0, 1.0);
  193. }
  194. float ChebychevInequality(vec2 moments, float compare, float bias)
  195. {
  196. float p = smoothstep(compare - bias, compare, moments.x);
  197. float variance = max(moments.y - moments.x * moments.x, 0.02);
  198. float d = compare - moments.x;
  199. float p_max = linstep(0.2, 1.0, variance / (variance + d * d));
  200. return clamp(max(p, p_max), 0.0, 1.0);
  201. }
  202. float computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias, float darkness)
  203. {
  204. vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;
  205. depth = 0.5 * depth + vec3(0.5);
  206. vec2 uv = depth.xy;
  207. if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z >= 1.0)
  208. {
  209. return 1.0;
  210. }
  211. vec4 texel = texture2D(shadowSampler, uv);
  212. vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));
  213. return min(1.0, 1.0 - ChebychevInequality(moments, depth.z, bias) + darkness);
  214. }
  215. #endif
  216. #endif
  217. #ifdef CLIPPLANE
  218. varying float fClipDistance;
  219. #endif
  220. // Fog
  221. #ifdef FOG
  222. #define FOGMODE_NONE 0.
  223. #define FOGMODE_EXP 1.
  224. #define FOGMODE_EXP2 2.
  225. #define FOGMODE_LINEAR 3.
  226. #define E 2.71828
  227. uniform vec4 vFogInfos;
  228. uniform vec3 vFogColor;
  229. varying float fFogDistance;
  230. float CalcFogFactor()
  231. {
  232. float fogCoeff = 1.0;
  233. float fogStart = vFogInfos.y;
  234. float fogEnd = vFogInfos.z;
  235. float fogDensity = vFogInfos.w;
  236. if (FOGMODE_LINEAR == vFogInfos.x)
  237. {
  238. fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);
  239. }
  240. else if (FOGMODE_EXP == vFogInfos.x)
  241. {
  242. fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);
  243. }
  244. else if (FOGMODE_EXP2 == vFogInfos.x)
  245. {
  246. fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);
  247. }
  248. return clamp(fogCoeff, 0.0, 1.0);
  249. }
  250. #endif
  251. // Light Computing
  252. struct lightingInfo
  253. {
  254. vec3 diffuse;
  255. };
  256. lightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, float range) {
  257. lightingInfo result;
  258. vec3 lightVectorW;
  259. float attenuation = 1.0;
  260. if (lightData.w == 0.)
  261. {
  262. vec3 direction = lightData.xyz - vPositionW;
  263. attenuation = max(0., 1.0 - length(direction) / range);
  264. lightVectorW = normalize(direction);
  265. }
  266. else
  267. {
  268. lightVectorW = normalize(-lightData.xyz);
  269. }
  270. // diffuse
  271. float ndl = max(0., dot(vNormal, lightVectorW));
  272. result.diffuse = ndl * diffuseColor * attenuation;
  273. return result;
  274. }
  275. lightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, float range) {
  276. lightingInfo result;
  277. vec3 direction = lightData.xyz - vPositionW;
  278. vec3 lightVectorW = normalize(direction);
  279. float attenuation = max(0., 1.0 - length(direction) / range);
  280. // diffuse
  281. float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));
  282. float spotAtten = 0.0;
  283. if (cosAngle >= lightDirection.w)
  284. {
  285. cosAngle = max(0., pow(cosAngle, lightData.w));
  286. spotAtten = clamp((cosAngle - lightDirection.w) / (1. - cosAngle), 0.0, 1.0);
  287. // Diffuse
  288. float ndl = max(0., dot(vNormal, -lightDirection.xyz));
  289. result.diffuse = ndl * spotAtten * diffuseColor * attenuation;
  290. return result;
  291. }
  292. result.diffuse = vec3(0.);
  293. return result;
  294. }
  295. lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 groundColor) {
  296. lightingInfo result;
  297. // Diffuse
  298. float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;
  299. result.diffuse = mix(groundColor, diffuseColor, ndl);
  300. return result;
  301. }
  302. float Rand(vec3 rv) {
  303. float x = dot(rv, vec3(12.9898,78.233, 24.65487));
  304. return fract(sin(x) * 43758.5453);
  305. }
  306. void main(void) {
  307. // Clip plane
  308. #ifdef CLIPPLANE
  309. if (fClipDistance > 0.0)
  310. discard;
  311. #endif
  312. vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
  313. // Base color
  314. vec4 baseColor = furColor;
  315. vec3 diffuseColor = vDiffuseColor.rgb;
  316. // Alpha
  317. float alpha = vDiffuseColor.a;
  318. #ifdef DIFFUSE
  319. baseColor *= texture2D(diffuseSampler, vDiffuseUV);
  320. #ifdef ALPHATEST
  321. if (baseColor.a < 0.4)
  322. discard;
  323. #endif
  324. baseColor.rgb *= vDiffuseInfos.y;
  325. #endif
  326. #ifdef VERTEXCOLOR
  327. baseColor.rgb *= vColor.rgb;
  328. #endif
  329. // Bump
  330. #ifdef NORMAL
  331. vec3 normalW = normalize(vNormalW);
  332. #else
  333. vec3 normalW = vec3(1.0, 1.0, 1.0);
  334. #endif
  335. #ifdef HIGHLEVEL
  336. // Fur
  337. vec4 furTextureColor = texture2D(furTexture, vec2(vFurUV.x, vFurUV.y));
  338. if (furTextureColor.a <= 0.0 || furTextureColor.g < furOffset) {
  339. discard;
  340. }
  341. float occlusion = mix(0.0, furTextureColor.b * 1.2, furOffset);
  342. baseColor = vec4(baseColor.xyz * occlusion, 1.1 - furOffset);
  343. #endif
  344. // Lighting
  345. vec3 diffuseBase = vec3(0., 0., 0.);
  346. float shadow = 1.;
  347. #ifdef LIGHT0
  348. #ifdef SPOTLIGHT0
  349. lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightDiffuse0.a);
  350. #endif
  351. #ifdef HEMILIGHT0
  352. lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightGround0);
  353. #endif
  354. #if defined(POINTLIGHT0) || defined(DIRLIGHT0)
  355. lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightDiffuse0.a);
  356. #endif
  357. #ifdef SHADOW0
  358. #ifdef SHADOWVSM0
  359. shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);
  360. #else
  361. #ifdef SHADOWPCF0
  362. #if defined(POINTLIGHT0)
  363. shadow = computeShadowWithPCFCube(vLightData0.xyz, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);
  364. #else
  365. shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);
  366. #endif
  367. #else
  368. #if defined(POINTLIGHT0)
  369. shadow = computeShadowCube(vLightData0.xyz, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);
  370. #else
  371. shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);
  372. #endif
  373. #endif
  374. #endif
  375. #else
  376. shadow = 1.;
  377. #endif
  378. diffuseBase += info.diffuse * shadow;
  379. #endif
  380. #ifdef LIGHT1
  381. #ifdef SPOTLIGHT1
  382. info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightDiffuse1.a);
  383. #endif
  384. #ifdef HEMILIGHT1
  385. info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightGround1.a);
  386. #endif
  387. #if defined(POINTLIGHT1) || defined(DIRLIGHT1)
  388. info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightDiffuse1.a);
  389. #endif
  390. #ifdef SHADOW1
  391. #ifdef SHADOWVSM1
  392. shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);
  393. #else
  394. #ifdef SHADOWPCF1
  395. #if defined(POINTLIGHT1)
  396. shadow = computeShadowWithPCFCube(vLightData1.xyz, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);
  397. #else
  398. shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);
  399. #endif
  400. #else
  401. #if defined(POINTLIGHT1)
  402. shadow = computeShadowCube(vLightData1.xyz, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);
  403. #else
  404. shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);
  405. #endif
  406. #endif
  407. #endif
  408. #else
  409. shadow = 1.;
  410. #endif
  411. diffuseBase += info.diffuse * shadow;
  412. #endif
  413. #ifdef LIGHT2
  414. #ifdef SPOTLIGHT2
  415. info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightDiffuse2.a);
  416. #endif
  417. #ifdef HEMILIGHT2
  418. info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightGround2);
  419. #endif
  420. #if defined(POINTLIGHT2) || defined(DIRLIGHT2)
  421. info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightDiffuse2.a);
  422. #endif
  423. #ifdef SHADOW2
  424. #ifdef SHADOWVSM2
  425. shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);
  426. #else
  427. #ifdef SHADOWPCF2
  428. #if defined(POINTLIGHT2)
  429. shadow = computeShadowWithPCFCube(vLightData2.xyz, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);
  430. #else
  431. shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);
  432. #endif
  433. #else
  434. #if defined(POINTLIGHT2)
  435. shadow = computeShadowCube(vLightData2.xyz, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);
  436. #else
  437. shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);
  438. #endif
  439. #endif
  440. #endif
  441. #else
  442. shadow = 1.;
  443. #endif
  444. diffuseBase += info.diffuse * shadow;
  445. #endif
  446. #ifdef LIGHT3
  447. #ifdef SPOTLIGHT3
  448. info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightDiffuse3.a);
  449. #endif
  450. #ifdef HEMILIGHT3
  451. info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightGround3);
  452. #endif
  453. #if defined(POINTLIGHT3) || defined(DIRLIGHT3)
  454. info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightDiffuse3.a);
  455. #endif
  456. #ifdef SHADOW3
  457. #ifdef SHADOWVSM3
  458. shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);
  459. #else
  460. #ifdef SHADOWPCF3
  461. #if defined(POINTLIGHT3)
  462. shadow = computeShadowWithPCFCube(vLightData3.xyz, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);
  463. #else
  464. shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);
  465. #endif
  466. #else
  467. #if defined(POINTLIGHT3)
  468. shadow = computeShadowCube(vLightData3.xyz, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);
  469. #else
  470. shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);
  471. #endif
  472. #endif
  473. #endif
  474. #else
  475. shadow = 1.;
  476. #endif
  477. diffuseBase += info.diffuse * shadow;
  478. #endif
  479. #ifdef VERTEXALPHA
  480. alpha *= vColor.a;
  481. #endif
  482. vec3 finalDiffuse = clamp(diffuseBase.rgb * baseColor.rgb, 0.0, 1.0);
  483. // Composition
  484. #ifdef HIGHLEVEL
  485. vec4 color = vec4(finalDiffuse, alpha);
  486. #else
  487. float r = vfur_length * 0.5;
  488. vec4 color = vec4(finalDiffuse * (0.5 + r), alpha);
  489. #endif
  490. #ifdef FOG
  491. float fog = CalcFogFactor();
  492. color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;
  493. #endif
  494. gl_FragColor = color;
  495. }