lldrawpoolavatar.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. /**
  2. * @file lldrawpoolavatar.cpp
  3. * @brief LLDrawPoolAvatar class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lldrawpoolavatar.h"
  34. #include "llfasttimer.h"
  35. #include "llnoise.h"
  36. #include "llrenderutils.h" // For gSphere
  37. #include "llagent.h"
  38. #include "llface.h"
  39. #include "llpipeline.h"
  40. //MK
  41. #include "mkrlinterface.h"
  42. //mk
  43. #include "llviewercamera.h"
  44. #include "llviewercontrol.h"
  45. #include "llviewerpartsim.h"
  46. #include "llviewershadermgr.h"
  47. #include "llvoavatarself.h"
  48. #include "llvovolume.h"
  49. LLGLSLShader* LLDrawPoolAvatar::sVertexProgram = NULL;
  50. bool LLDrawPoolAvatar::sSkipOpaque = false;
  51. bool LLDrawPoolAvatar::sSkipTransparent = false;
  52. S32 LLDrawPoolAvatar::sShadowPass = -1;
  53. S32 LLDrawPoolAvatar::sDiffuseChannel = 0;
  54. F32 LLDrawPoolAvatar::sMinimumAlpha = 0.2f;
  55. static bool sIsPostDeferredRender = false;
  56. constexpr F32 CLOTHING_GRAVITY_EFFECT = 0.7f;
  57. static S32 sShaderLevel = 0;
  58. static S32 sNormalChannel = -1;
  59. static S32 sSpecularChannel = -1;
  60. LLDrawPoolAvatar::LLDrawPoolAvatar(U32 type)
  61. : LLFacePool(type)
  62. {
  63. }
  64. //virtual
  65. LLDrawPoolAvatar::~LLDrawPoolAvatar()
  66. {
  67. if (!isDead())
  68. {
  69. llwarns << "Destroying a pool (" << std::hex << (intptr_t)this
  70. << std::dec << ") still containing faces" << llendl;
  71. }
  72. }
  73. //virtual
  74. void LLDrawPoolAvatar::prerender()
  75. {
  76. mShaderLevel = sShaderLevel =
  77. gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR);
  78. }
  79. LLMatrix4& LLDrawPoolAvatar::getModelView()
  80. {
  81. static LLMatrix4 ret;
  82. ret.set(gGLModelView.getF32ptr());
  83. return ret;
  84. }
  85. //virtual
  86. void LLDrawPoolAvatar::beginDeferredPass(S32 pass)
  87. {
  88. LL_FAST_TIMER(FTM_RENDER_CHARACTERS);
  89. sSkipTransparent = true;
  90. if (LLPipeline::sImpostorRender)
  91. {
  92. // Impostor pass does not have impostor rendering
  93. ++pass;
  94. }
  95. switch (pass)
  96. {
  97. case 0:
  98. beginDeferredImpostor();
  99. break;
  100. case 1:
  101. beginDeferredRigid();
  102. break;
  103. case 2:
  104. beginDeferredSkinned();
  105. default:
  106. break;
  107. }
  108. }
  109. //virtual
  110. void LLDrawPoolAvatar::endDeferredPass(S32 pass)
  111. {
  112. LL_FAST_TIMER(FTM_RENDER_CHARACTERS);
  113. sSkipTransparent = false;
  114. if (LLPipeline::sImpostorRender)
  115. {
  116. ++pass;
  117. }
  118. switch (pass)
  119. {
  120. case 0:
  121. endDeferredImpostor();
  122. break;
  123. case 1:
  124. endDeferredRigid();
  125. break;
  126. case 2:
  127. endDeferredSkinned();
  128. default:
  129. break;
  130. }
  131. }
  132. //virtual
  133. void LLDrawPoolAvatar::beginPostDeferredPass(S32 pass)
  134. {
  135. sSkipOpaque = true;
  136. sVertexProgram = &gDeferredAvatarAlphaProgram;
  137. gPipeline.bindDeferredShader(*sVertexProgram);
  138. sVertexProgram->setMinimumAlpha(sMinimumAlpha);
  139. sDiffuseChannel = sVertexProgram->enableTexture(LLShaderMgr::DIFFUSE_MAP);
  140. }
  141. //virtual
  142. void LLDrawPoolAvatar::endPostDeferredPass(S32 pass)
  143. {
  144. // If we are in software-blending, remember to set the fence _after_ we
  145. // draw so we wait till this rendering is done
  146. sSkipOpaque = false;
  147. gPipeline.unbindDeferredShader(*sVertexProgram);
  148. sDiffuseChannel = 0;
  149. }
  150. //virtual
  151. void LLDrawPoolAvatar::renderPostDeferred(S32 pass)
  152. {
  153. sIsPostDeferredRender = true;
  154. if (LLPipeline::sImpostorRender)
  155. {
  156. // *HACK: for impostors so actual pass ends up being proper pass
  157. render(0);
  158. }
  159. else
  160. {
  161. render(2);
  162. }
  163. sIsPostDeferredRender = false;
  164. }
  165. //virtual
  166. void LLDrawPoolAvatar::beginShadowPass(S32 pass)
  167. {
  168. LL_FAST_TIMER(FTM_SHADOW_AVATAR);
  169. if (pass == SHADOW_PASS_AVATAR_OPAQUE)
  170. {
  171. sVertexProgram = &gDeferredAvatarShadowProgram;
  172. if (mShaderLevel) // For hardware blending
  173. {
  174. sVertexProgram->bind();
  175. }
  176. gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f);
  177. }
  178. else if (pass == SHADOW_PASS_AVATAR_ALPHA_BLEND)
  179. {
  180. sVertexProgram = &gDeferredAvatarAlphaShadowProgram;
  181. // Bind diffuse tex so we can reference the alpha channel...
  182. if (sVertexProgram->getUniformLocation(LLViewerShaderMgr::DIFFUSE_MAP) != -1)
  183. {
  184. sDiffuseChannel =
  185. sVertexProgram->enableTexture(LLShaderMgr::DIFFUSE_MAP);
  186. }
  187. else
  188. {
  189. sDiffuseChannel = 0;
  190. }
  191. if (mShaderLevel) // For hardware blending
  192. {
  193. sVertexProgram->bind();
  194. }
  195. gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f);
  196. }
  197. else if (pass == SHADOW_PASS_AVATAR_ALPHA_MASK)
  198. {
  199. sVertexProgram = &gDeferredAvatarAlphaMaskShadowProgram;
  200. // Bind diffuse tex so we can reference the alpha channel...
  201. if (sVertexProgram->getUniformLocation(LLViewerShaderMgr::DIFFUSE_MAP) != -1)
  202. {
  203. sDiffuseChannel =
  204. sVertexProgram->enableTexture(LLShaderMgr::DIFFUSE_MAP);
  205. }
  206. else
  207. {
  208. sDiffuseChannel = 0;
  209. }
  210. if (mShaderLevel) // For hardware blending
  211. {
  212. sVertexProgram->bind();
  213. }
  214. gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f);
  215. }
  216. }
  217. //virtual
  218. void LLDrawPoolAvatar::endShadowPass(S32 pass)
  219. {
  220. LL_FAST_TIMER(FTM_SHADOW_AVATAR);
  221. if (mShaderLevel)
  222. {
  223. sVertexProgram->unbind();
  224. }
  225. sVertexProgram = NULL;
  226. sShadowPass = -1;
  227. }
  228. //virtual
  229. void LLDrawPoolAvatar::renderShadow(S32 pass)
  230. {
  231. LL_FAST_TIMER(FTM_SHADOW_AVATAR);
  232. if (mDrawFace.empty())
  233. {
  234. return;
  235. }
  236. const LLFace* facep = mDrawFace[0];
  237. if (!facep || !facep->getDrawable())
  238. {
  239. return;
  240. }
  241. LLVOAvatar* avatarp = (LLVOAvatar*)facep->getDrawable()->getVObj().get();
  242. if (!avatarp || avatarp->isDead() || avatarp->isUIAvatar() ||
  243. avatarp->mDrawable.isNull() || avatarp->isVisuallyMuted() ||
  244. avatarp->isImpostor())
  245. {
  246. return;
  247. }
  248. sShadowPass = pass;
  249. if (pass == SHADOW_PASS_AVATAR_OPAQUE)
  250. {
  251. sSkipTransparent = true;
  252. avatarp->renderSkinned();
  253. sSkipTransparent = false;
  254. return;
  255. }
  256. if (pass == SHADOW_PASS_AVATAR_ALPHA_BLEND ||
  257. pass == SHADOW_PASS_AVATAR_ALPHA_MASK)
  258. {
  259. sSkipOpaque = true;
  260. avatarp->renderSkinned();
  261. sSkipOpaque = false;
  262. }
  263. }
  264. //virtual
  265. void LLDrawPoolAvatar::render(S32 pass)
  266. {
  267. LL_FAST_TIMER(FTM_RENDER_CHARACTERS);
  268. if (LLPipeline::sImpostorRender)
  269. {
  270. ++pass;
  271. }
  272. renderAvatars(NULL, pass); // Render all avatars
  273. }
  274. //virtual
  275. void LLDrawPoolAvatar::beginRenderPass(S32 pass)
  276. {
  277. LL_FAST_TIMER(FTM_RENDER_CHARACTERS);
  278. // Reset vertex buffer mappings
  279. LLVertexBuffer::unbind();
  280. if (LLPipeline::sImpostorRender)
  281. {
  282. // Impostor render does not have impostors rendering
  283. ++pass;
  284. }
  285. switch (pass)
  286. {
  287. case 0:
  288. beginImpostor();
  289. // Make sure no stale colors are left over from a previous render
  290. gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f);
  291. break;
  292. case 1:
  293. beginRigid();
  294. break;
  295. case 2:
  296. beginSkinned();
  297. default:
  298. break;
  299. }
  300. }
  301. //virtual
  302. void LLDrawPoolAvatar::endRenderPass(S32 pass)
  303. {
  304. LL_FAST_TIMER(FTM_RENDER_CHARACTERS);
  305. if (LLPipeline::sImpostorRender)
  306. {
  307. ++pass;
  308. }
  309. switch (pass)
  310. {
  311. case 0:
  312. endImpostor();
  313. break;
  314. case 1:
  315. endRigid();
  316. break;
  317. case 2:
  318. endSkinned();
  319. default:
  320. break;
  321. }
  322. }
  323. //static
  324. void LLDrawPoolAvatar::beginImpostor()
  325. {
  326. if (!LLPipeline::sReflectionRender)
  327. {
  328. LLVOAvatar::sRenderDistance = llclamp(LLVOAvatar::sRenderDistance,
  329. 16.f, 256.f);
  330. LLVOAvatar::sNumVisibleAvatars = 0;
  331. }
  332. gImpostorProgram.bind();
  333. gImpostorProgram.setMinimumAlpha(0.01f);
  334. gPipeline.enableLightsFullbright();
  335. sDiffuseChannel = 0;
  336. }
  337. //static
  338. void LLDrawPoolAvatar::endImpostor()
  339. {
  340. gImpostorProgram.unbind();
  341. gPipeline.enableLightsDynamic();
  342. }
  343. //static
  344. void LLDrawPoolAvatar::beginRigid()
  345. {
  346. if (!gPipeline.shadersLoaded())
  347. {
  348. sVertexProgram = NULL;
  349. return;
  350. }
  351. if (LLPipeline::sUnderWaterRender && !gUsePBRShaders)
  352. {
  353. sVertexProgram = &gObjectAlphaMaskNoColorWaterProgram;
  354. }
  355. else
  356. {
  357. sVertexProgram = &gObjectAlphaMaskNoColorProgram;
  358. }
  359. // Eyeballs render with the specular shader
  360. sVertexProgram->bind();
  361. sVertexProgram->setMinimumAlpha(sMinimumAlpha);
  362. if (!gUsePBRShaders)
  363. {
  364. S32 no_atmo = LLPipeline::sRenderingHUDs ? 1 : 0;
  365. sVertexProgram->uniform1i(LLShaderMgr::NO_ATMO, no_atmo);
  366. }
  367. }
  368. //static
  369. void LLDrawPoolAvatar::endRigid()
  370. {
  371. if (sVertexProgram)
  372. {
  373. sVertexProgram->unbind();
  374. }
  375. }
  376. //static
  377. void LLDrawPoolAvatar::beginDeferredImpostor()
  378. {
  379. if (!LLPipeline::sReflectionRender)
  380. {
  381. LLVOAvatar::sRenderDistance = llclamp(LLVOAvatar::sRenderDistance,
  382. 16.f, 256.f);
  383. LLVOAvatar::sNumVisibleAvatars = 0;
  384. }
  385. sVertexProgram = &gDeferredImpostorProgram;
  386. sSpecularChannel =
  387. sVertexProgram->enableTexture(LLShaderMgr::SPECULAR_MAP);
  388. sNormalChannel =
  389. sVertexProgram->enableTexture(LLShaderMgr::DEFERRED_NORMAL);
  390. sDiffuseChannel = sVertexProgram->enableTexture(LLShaderMgr::DIFFUSE_MAP);
  391. sVertexProgram->bind();
  392. sVertexProgram->setMinimumAlpha(0.01f);
  393. }
  394. //static
  395. void LLDrawPoolAvatar::endDeferredImpostor()
  396. {
  397. sVertexProgram->disableTexture(LLShaderMgr::DEFERRED_NORMAL);
  398. sVertexProgram->disableTexture(LLShaderMgr::SPECULAR_MAP);
  399. sVertexProgram->disableTexture(LLShaderMgr::DIFFUSE_MAP);
  400. gPipeline.unbindDeferredShader(*sVertexProgram);
  401. sVertexProgram = NULL;
  402. sDiffuseChannel = 0;
  403. }
  404. //static
  405. void LLDrawPoolAvatar::beginDeferredRigid()
  406. {
  407. sVertexProgram = &gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
  408. sDiffuseChannel = sVertexProgram->enableTexture(LLShaderMgr::DIFFUSE_MAP);
  409. sVertexProgram->bind();
  410. sVertexProgram->setMinimumAlpha(sMinimumAlpha);
  411. if (!gUsePBRShaders)
  412. {
  413. S32 no_atmo = LLPipeline::sRenderingHUDs ? 1 : 0;
  414. sVertexProgram->uniform1i(LLShaderMgr::NO_ATMO, no_atmo);
  415. }
  416. }
  417. //static
  418. void LLDrawPoolAvatar::endDeferredRigid()
  419. {
  420. sVertexProgram->disableTexture(LLShaderMgr::DIFFUSE_MAP);
  421. sVertexProgram->unbind();
  422. gGL.getTexUnit(0)->activate();
  423. }
  424. //static
  425. void LLDrawPoolAvatar::beginSkinned()
  426. {
  427. if (gUsePBRShaders)
  428. {
  429. sVertexProgram = &gAvatarProgram;
  430. sVertexProgram->bind();
  431. sVertexProgram->setMinimumAlpha(sMinimumAlpha);
  432. return;
  433. }
  434. if (sShaderLevel)
  435. {
  436. if (LLPipeline::sUnderWaterRender)
  437. {
  438. sVertexProgram = &gAvatarWaterProgram;
  439. }
  440. else
  441. {
  442. sVertexProgram = &gAvatarProgram;
  443. }
  444. }
  445. else if (LLPipeline::sUnderWaterRender)
  446. {
  447. sVertexProgram = &gObjectAlphaMaskNoColorWaterProgram;
  448. }
  449. else
  450. {
  451. sVertexProgram = &gObjectAlphaMaskNoColorProgram;
  452. }
  453. if (sShaderLevel) // For hardware blending
  454. {
  455. sVertexProgram->bind();
  456. sVertexProgram->enableTexture(LLShaderMgr::BUMP_MAP);
  457. S32 no_atmo = LLPipeline::sRenderingHUDs ? 1 : 0;
  458. sVertexProgram->uniform1i(LLShaderMgr::NO_ATMO, no_atmo);
  459. gGL.getTexUnit(0)->activate();
  460. }
  461. else if (gPipeline.shadersLoaded())
  462. {
  463. // Software skinning, use a basic shader for windlight.
  464. // *TODO: find a better fallback method for software skinning.
  465. sVertexProgram->bind();
  466. S32 no_atmo = LLPipeline::sRenderingHUDs ? 1 : 0;
  467. sVertexProgram->uniform1i(LLShaderMgr::NO_ATMO, no_atmo);
  468. }
  469. sVertexProgram->setMinimumAlpha(sMinimumAlpha);
  470. }
  471. //static
  472. void LLDrawPoolAvatar::endSkinned()
  473. {
  474. LLTexUnit* unitp = gGL.getTexUnit(0);
  475. // If we are in software-blending, remember to set the fence _after_ we
  476. // draw so we wait till this rendering is done
  477. if (sShaderLevel)
  478. {
  479. if (!gUsePBRShaders) // BUMP_MAP not used by the PBR avatar shaders. HB
  480. {
  481. sVertexProgram->disableTexture(LLShaderMgr::BUMP_MAP);
  482. }
  483. unitp->activate();
  484. sVertexProgram->unbind();
  485. }
  486. else if (gPipeline.shadersLoaded())
  487. {
  488. // Software skinning, use a basic shader for windlight.
  489. // *TODO: find a better fallback method for software skinning.
  490. sVertexProgram->unbind();
  491. }
  492. unitp->activate();
  493. }
  494. //static
  495. void LLDrawPoolAvatar::beginDeferredSkinned()
  496. {
  497. sVertexProgram = &gDeferredAvatarProgram;
  498. sVertexProgram->bind();
  499. sVertexProgram->setMinimumAlpha(sMinimumAlpha);
  500. if (!gUsePBRShaders)
  501. {
  502. S32 no_atmo = LLPipeline::sRenderingHUDs ? 1 : 0;
  503. sVertexProgram->uniform1i(LLShaderMgr::NO_ATMO, no_atmo);
  504. }
  505. sDiffuseChannel = sVertexProgram->enableTexture(LLShaderMgr::DIFFUSE_MAP);
  506. gGL.getTexUnit(0)->activate();
  507. }
  508. //static
  509. void LLDrawPoolAvatar::endDeferredSkinned()
  510. {
  511. // If we are in software-blending, remember to set the fence _after_ we
  512. // draw so we wait till this rendering is done
  513. sVertexProgram->unbind();
  514. sVertexProgram->disableTexture(LLShaderMgr::DIFFUSE_MAP);
  515. gGL.getTexUnit(0)->activate();
  516. }
  517. void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass)
  518. {
  519. LL_FAST_TIMER(FTM_RENDER_AVATARS);
  520. if (pass > 2)
  521. {
  522. return;
  523. }
  524. if (pass == -1)
  525. {
  526. prerender();
  527. // Start with pass 1 and skip impostor pass
  528. beginRenderPass(1);
  529. renderAvatars(single_avatar, 1);
  530. endRenderPass(1);
  531. beginRenderPass(2);
  532. renderAvatars(single_avatar, 2);
  533. endRenderPass(2);
  534. return;
  535. }
  536. if (!single_avatar && mDrawFace.empty())
  537. {
  538. return;
  539. }
  540. LLVOAvatar* avatarp;
  541. if (single_avatar)
  542. {
  543. avatarp = single_avatar;
  544. }
  545. else
  546. {
  547. const LLFace* facep = mDrawFace[0];
  548. if (!facep || !facep->getDrawable())
  549. {
  550. return;
  551. }
  552. avatarp = (LLVOAvatar*)facep->getDrawable()->getVObj().get();
  553. }
  554. if (!avatarp || avatarp->isDead() || avatarp->mDrawable.isNull())
  555. {
  556. return;
  557. }
  558. //MK
  559. // If this avatar is totally hidden by vision restriction spheres, then do
  560. // not render it at all...
  561. if (gRLenabled && !gRLInterface.avatarVisibility(avatarp))
  562. {
  563. return;
  564. }
  565. //mk
  566. if (!single_avatar && !avatarp->isFullyLoaded())
  567. {
  568. if (pass == 0 &&
  569. (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES) ||
  570. LLViewerPartSim::getMaxPartCount() <= 0))
  571. {
  572. // Debug code to draw a sphere in place of avatar
  573. gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
  574. gGL.setColorMask(true, true);
  575. LLVector3 pos = avatarp->getPositionAgent();
  576. gGL.color4f(1.f, 1.f, 1.f, 0.7f);
  577. gGL.pushMatrix();
  578. gGL.translatef((F32)pos.mV[VX], (F32)pos.mV[VY], (F32)pos.mV[VZ]);
  579. gGL.scalef(0.15f, 0.15f, 0.3f);
  580. gSphere.renderGGL();
  581. gGL.popMatrix();
  582. gGL.setColorMask(true, false);
  583. }
  584. // Do not render please
  585. return;
  586. }
  587. if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_AVATAR))
  588. {
  589. return;
  590. }
  591. bool impostor = !single_avatar && avatarp->isImpostor();
  592. bool only_pass0 = impostor ||
  593. (single_avatar && !avatarp->needsImpostorUpdate() &&
  594. (avatarp->getVisualMuteSettings() ==
  595. LLVOAvatar::AV_DO_NOT_RENDER ||
  596. //MK
  597. (gRLenabled &&
  598. gRLInterface.avatarVisibility(avatarp) != 1)));
  599. //mk
  600. if (pass != 0 && only_pass0)
  601. {
  602. // Do not draw anything but the impostor for impostored avatars
  603. return;
  604. }
  605. if (pass == 0 && !impostor && LLPipeline::sUnderWaterRender)
  606. {
  607. // Do not draw foot shadows under water
  608. return;
  609. }
  610. if (single_avatar)
  611. {
  612. LLVOAvatar* attached_av = avatarp->getAttachedAvatar();
  613. // Do not render any animesh for visually muted avatars
  614. if (attached_av && attached_av->isVisuallyMuted())
  615. {
  616. return;
  617. }
  618. }
  619. if (pass == 0)
  620. {
  621. if (!LLPipeline::sReflectionRender)
  622. {
  623. ++LLVOAvatar::sNumVisibleAvatars;
  624. }
  625. if (only_pass0)
  626. {
  627. if (LLPipeline::sRenderDeferred &&
  628. !LLPipeline::sReflectionRender &&
  629. avatarp->mImpostor.isComplete())
  630. {
  631. U32 num_tex = avatarp->mImpostor.getNumTextures();
  632. if (sNormalChannel > -1 && num_tex >= 3)
  633. {
  634. avatarp->mImpostor.bindTexture(2, sNormalChannel);
  635. }
  636. if (sSpecularChannel > -1 && num_tex >= 2)
  637. {
  638. avatarp->mImpostor.bindTexture(1, sSpecularChannel);
  639. }
  640. }
  641. avatarp->renderImpostor(avatarp->getMutedAVColor(),
  642. sDiffuseChannel);
  643. }
  644. return;
  645. }
  646. if (pass == 1)
  647. {
  648. // Render rigid meshes (eyeballs) first
  649. avatarp->renderRigid();
  650. // Render the hit box after the rigid parts of the avatar. This relies
  651. // on the fact that the shader for rigid parts would get unloaded at
  652. // the return from this method anyway (and nothing fancy with texture
  653. // units & Co is done either: see LLDrawPoolAvatar::endRigid()), so we
  654. // can bind another shader here without breaking avatar rendering... HB
  655. static LLCachedControl<bool> hit_box(gSavedSettings, "RenderDebugHitBox");
  656. if (!single_avatar && hit_box)
  657. {
  658. gDebugProgram.bind();
  659. // Set up drawing mode and remove any texture in use
  660. LLGLEnable blend(GL_BLEND);
  661. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  662. // Save current world matrix
  663. gGL.matrixMode(LLRender::MM_MODELVIEW);
  664. gGL.pushMatrix();
  665. const LLColor4& avatar_color = avatarp->getMinimapColor();
  666. gGL.diffuseColor4f(avatar_color.mV[VX], avatar_color.mV[VY],
  667. avatar_color.mV[VZ], avatar_color.mV[VW]);
  668. const LLVector3& pos = avatarp->getPositionAgent();
  669. const LLVector3& size = avatarp->getScale();
  670. LLQuaternion rot = avatarp->getRotationRegion();
  671. // Set up and rotate the hit box to avatar orientation and half the
  672. // avatar size in either direction.
  673. static const LLVector3 sv1 = LLVector3(0.5f, 0.5f, 0.5f);
  674. static const LLVector3 sv2 = LLVector3(-0.5f, 0.5f, 0.5f);
  675. static const LLVector3 sv3 = LLVector3(-0.5f, -0.5f, 0.5f);
  676. static const LLVector3 sv4 = LLVector3(0.5f, -0.5f, 0.5f);
  677. LLVector3 v1 = size.scaledVec(sv1) * rot;
  678. LLVector3 v2 = size.scaledVec(sv2) * rot;
  679. LLVector3 v3 = size.scaledVec(sv3) * rot;
  680. LLVector3 v4 = size.scaledVec(sv4) * rot;
  681. // Box corners coordinates
  682. LLVector3 pospv1 = pos + v1;
  683. LLVector3 posmv1 = pos - v1;
  684. LLVector3 pospv2 = pos + v2;
  685. LLVector3 posmv2 = pos - v2;
  686. LLVector3 pospv3 = pos + v3;
  687. LLVector3 posmv3 = pos - v3;
  688. LLVector3 pospv4 = pos + v4;
  689. LLVector3 posmv4 = pos - v4;
  690. // Render the box
  691. gGL.begin(LLRender::LINES);
  692. // Top
  693. gGL.vertex3fv(pospv1.mV);
  694. gGL.vertex3fv(pospv2.mV);
  695. gGL.vertex3fv(pospv2.mV);
  696. gGL.vertex3fv(pospv3.mV);
  697. gGL.vertex3fv(pospv3.mV);
  698. gGL.vertex3fv(pospv4.mV);
  699. gGL.vertex3fv(pospv4.mV);
  700. gGL.vertex3fv(pospv1.mV);
  701. // Bottom
  702. gGL.vertex3fv(posmv1.mV);
  703. gGL.vertex3fv(posmv2.mV);
  704. gGL.vertex3fv(posmv2.mV);
  705. gGL.vertex3fv(posmv3.mV);
  706. gGL.vertex3fv(posmv3.mV);
  707. gGL.vertex3fv(posmv4.mV);
  708. gGL.vertex3fv(posmv4.mV);
  709. gGL.vertex3fv(posmv1.mV);
  710. // Right
  711. gGL.vertex3fv(pospv1.mV);
  712. gGL.vertex3fv(posmv3.mV);
  713. gGL.vertex3fv(pospv4.mV);
  714. gGL.vertex3fv(posmv2.mV);
  715. // Left
  716. gGL.vertex3fv(pospv2.mV);
  717. gGL.vertex3fv(posmv4.mV);
  718. gGL.vertex3fv(pospv3.mV);
  719. gGL.vertex3fv(posmv1.mV);
  720. gGL.end();
  721. // Restore world matrix
  722. gGL.popMatrix();
  723. gDebugProgram.unbind();
  724. }
  725. return;
  726. }
  727. if (!gUsePBRShaders && mShaderLevel >= SHADER_LEVEL_CLOTH)
  728. {
  729. LLMatrix4 rot_mat;
  730. gViewerCamera.getMatrixToLocal(rot_mat);
  731. LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
  732. rot_mat *= cfr;
  733. LLVector4 wind;
  734. wind.set(avatarp->mWindVec);
  735. wind.mV[VW] = 0.f;
  736. wind = wind * rot_mat;
  737. wind.mV[VW] = avatarp->mWindVec.mV[VW];
  738. sVertexProgram->uniform4fv(LLShaderMgr::AVATAR_WIND, 1, wind.mV);
  739. F32 phase = -(avatarp->mRipplePhase);
  740. F32 freq = 7.f + 2.f * noise1(avatarp->mRipplePhase);
  741. LLVector4 sin_params(freq, freq, freq, phase);
  742. sVertexProgram->uniform4fv(LLShaderMgr::AVATAR_SINWAVE, 1,
  743. sin_params.mV);
  744. LLVector4 gravity(0.f, 0.f, -CLOTHING_GRAVITY_EFFECT, 0.f);
  745. gravity = gravity * rot_mat;
  746. sVertexProgram->uniform4fv(LLShaderMgr::AVATAR_GRAVITY, 1, gravity.mV);
  747. }
  748. if (!single_avatar || avatarp == single_avatar)
  749. {
  750. avatarp->renderSkinned();
  751. //MK
  752. if (sIsPostDeferredRender && gRLenabled && avatarp->isSelf() &&
  753. !gRLInterface.mRenderLimitRenderedThisFrame &&
  754. gRLInterface.mVisionRestricted && avatarp->isFullyLoaded())
  755. {
  756. LL_TRACY_TIMER(TRC_RLV_RENDER_LIMITS);
  757. // Possibly draw a big black sphere around our avatar if the camera
  758. // render is limited
  759. gRLInterface.drawRenderLimit(false);
  760. }
  761. //mk
  762. }
  763. }