1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
|
/**
* @file lldrawpoolavatar.cpp
* @brief LLDrawPoolAvatar class implementation
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "lldrawpoolavatar.h"
#include "llskinningutil.h"
#include "llrender.h"
#include "llvoavatar.h"
#include "m3math.h"
#include "llmatrix4a.h"
#include "llagent.h" //for gAgent.needsRenderAvatar()
#include "lldrawable.h"
#include "lldrawpoolbump.h"
#include "llface.h"
#include "llmeshrepository.h"
#include "llsky.h"
#include "llviewercamera.h"
#include "llviewerregion.h"
#include "noise.h"
#include "pipeline.h"
#include "llviewershadermgr.h"
#include "llvovolume.h"
#include "llvolume.h"
#include "llappviewer.h"
#include "llrendersphere.h"
#include "llviewerpartsim.h"
#include "llviewercontrol.h" // for gSavedSettings
#include "llviewertexturelist.h"
static U32 sShaderLevel = 0;
LLGLSLShader* LLDrawPoolAvatar::sVertexProgram = NULL;
BOOL LLDrawPoolAvatar::sSkipOpaque = FALSE;
BOOL LLDrawPoolAvatar::sSkipTransparent = FALSE;
S32 LLDrawPoolAvatar::sShadowPass = -1;
S32 LLDrawPoolAvatar::sDiffuseChannel = 0;
F32 LLDrawPoolAvatar::sMinimumAlpha = 0.2f;
LLUUID gBlackSquareID;
static bool is_deferred_render = false;
static bool is_post_deferred_render = false;
extern BOOL gUseGLPick;
F32 CLOTHING_GRAVITY_EFFECT = 0.7f;
F32 CLOTHING_ACCEL_FORCE_FACTOR = 0.2f;
// Format for gAGPVertices
// vertex format for bumpmapping:
// vertices 12
// pad 4
// normals 12
// pad 4
// texcoords0 8
// texcoords1 8
// total 48
//
// for no bumpmapping
// vertices 12
// texcoords 8
// normals 12
// total 32
//
S32 AVATAR_OFFSET_POS = 0;
S32 AVATAR_OFFSET_NORMAL = 16;
S32 AVATAR_OFFSET_TEX0 = 32;
S32 AVATAR_OFFSET_TEX1 = 40;
S32 AVATAR_VERTEX_BYTES = 48;
BOOL gAvatarEmbossBumpMap = FALSE;
static BOOL sRenderingSkinned = FALSE;
S32 normal_channel = -1;
S32 specular_channel = -1;
S32 cube_channel = -1;
LLDrawPoolAvatar::LLDrawPoolAvatar(U32 type) :
LLFacePool(type)
{
}
LLDrawPoolAvatar::~LLDrawPoolAvatar()
{
if (!isDead())
{
LL_WARNS() << "Destroying avatar drawpool that still contains faces" << LL_ENDL;
}
}
// virtual
BOOL LLDrawPoolAvatar::isDead()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
if (!LLFacePool::isDead())
{
return FALSE;
}
return TRUE;
}
S32 LLDrawPoolAvatar::getShaderLevel() const
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
return (S32) LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR);
}
void LLDrawPoolAvatar::prerender()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
mShaderLevel = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR);
sShaderLevel = mShaderLevel;
}
LLMatrix4& LLDrawPoolAvatar::getModelView()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
static LLMatrix4 ret;
ret.initRows(LLVector4(gGLModelView+0),
LLVector4(gGLModelView+4),
LLVector4(gGLModelView+8),
LLVector4(gGLModelView+12));
return ret;
}
//-----------------------------------------------------------------------------
// render()
//-----------------------------------------------------------------------------
void LLDrawPoolAvatar::beginDeferredPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
sSkipTransparent = TRUE;
is_deferred_render = true;
if (LLPipeline::sImpostorRender)
{ //impostor pass does not have rigid or impostor rendering
pass += 2;
}
switch (pass)
{
case 0:
beginDeferredImpostor();
break;
case 1:
beginDeferredRigid();
break;
case 2:
beginDeferredSkinned();
break;
}
}
void LLDrawPoolAvatar::endDeferredPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
sSkipTransparent = FALSE;
is_deferred_render = false;
if (LLPipeline::sImpostorRender)
{
pass += 2;
}
switch (pass)
{
case 0:
endDeferredImpostor();
break;
case 1:
endDeferredRigid();
break;
case 2:
endDeferredSkinned();
break;
}
}
void LLDrawPoolAvatar::renderDeferred(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
render(pass);
}
S32 LLDrawPoolAvatar::getNumPostDeferredPasses()
{
return 1;
}
void LLDrawPoolAvatar::beginPostDeferredPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
sSkipOpaque = TRUE;
sShaderLevel = mShaderLevel;
sVertexProgram = &gDeferredAvatarAlphaProgram;
sRenderingSkinned = TRUE;
gPipeline.bindDeferredShader(*sVertexProgram);
sVertexProgram->setMinimumAlpha(LLDrawPoolAvatar::sMinimumAlpha);
sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
}
void LLDrawPoolAvatar::endPostDeferredPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
// if we're in software-blending, remember to set the fence _after_ we draw so we wait till this rendering is done
sRenderingSkinned = FALSE;
sSkipOpaque = FALSE;
gPipeline.unbindDeferredShader(*sVertexProgram);
sDiffuseChannel = 0;
sShaderLevel = mShaderLevel;
}
void LLDrawPoolAvatar::renderPostDeferred(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
is_post_deferred_render = true;
if (LLPipeline::sImpostorRender)
{ //HACK for impostors so actual pass ends up being proper pass
render(0);
}
else
{
render(2);
}
is_post_deferred_render = false;
}
S32 LLDrawPoolAvatar::getNumShadowPasses()
{
// avatars opaque, avatar alpha, avatar alpha mask, alpha attachments, alpha mask attachments, opaque attachments...
return NUM_SHADOW_PASSES;
}
void LLDrawPoolAvatar::beginShadowPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
if (pass == SHADOW_PASS_AVATAR_OPAQUE)
{
sVertexProgram = &gDeferredAvatarShadowProgram;
if ((sShaderLevel > 0)) // for hardware blending
{
sRenderingSkinned = TRUE;
sVertexProgram->bind();
}
gGL.diffuseColor4f(1, 1, 1, 1);
}
else if (pass == SHADOW_PASS_AVATAR_ALPHA_BLEND)
{
sVertexProgram = &gDeferredAvatarAlphaShadowProgram;
// bind diffuse tex so we can reference the alpha channel...
S32 loc = sVertexProgram->getUniformLocation(LLViewerShaderMgr::DIFFUSE_MAP);
sDiffuseChannel = 0;
if (loc != -1)
{
sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
}
if ((sShaderLevel > 0)) // for hardware blending
{
sRenderingSkinned = TRUE;
sVertexProgram->bind();
}
gGL.diffuseColor4f(1, 1, 1, 1);
}
else if (pass == SHADOW_PASS_AVATAR_ALPHA_MASK)
{
sVertexProgram = &gDeferredAvatarAlphaMaskShadowProgram;
// bind diffuse tex so we can reference the alpha channel...
S32 loc = sVertexProgram->getUniformLocation(LLViewerShaderMgr::DIFFUSE_MAP);
sDiffuseChannel = 0;
if (loc != -1)
{
sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
}
if ((sShaderLevel > 0)) // for hardware blending
{
sRenderingSkinned = TRUE;
sVertexProgram->bind();
}
gGL.diffuseColor4f(1, 1, 1, 1);
}
}
void LLDrawPoolAvatar::endShadowPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
if (sShaderLevel > 0)
{
sVertexProgram->unbind();
}
sVertexProgram = NULL;
sRenderingSkinned = FALSE;
LLDrawPoolAvatar::sShadowPass = -1;
}
void LLDrawPoolAvatar::renderShadow(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
if (mDrawFace.empty())
{
return;
}
const LLFace *facep = mDrawFace[0];
if (!facep->getDrawable())
{
return;
}
LLVOAvatar *avatarp = (LLVOAvatar *)facep->getDrawable()->getVObj().get();
if (avatarp->isDead() || avatarp->isUIAvatar() || avatarp->mDrawable.isNull())
{
return;
}
LLVOAvatar::AvatarOverallAppearance oa = avatarp->getOverallAppearance();
BOOL impostor = !LLPipeline::sImpostorRender && avatarp->isImpostor();
// no shadows if the shadows are causing this avatar to breach the limit.
if (avatarp->isTooSlow() || impostor || (oa == LLVOAvatar::AOA_INVISIBLE))
{
// No shadows for impostored (including jellydolled) or invisible avs.
return;
}
LLDrawPoolAvatar::sShadowPass = pass;
if (pass == SHADOW_PASS_AVATAR_OPAQUE)
{
LLDrawPoolAvatar::sSkipTransparent = true;
avatarp->renderSkinned();
LLDrawPoolAvatar::sSkipTransparent = false;
}
else if (pass == SHADOW_PASS_AVATAR_ALPHA_BLEND)
{
LLDrawPoolAvatar::sSkipOpaque = true;
avatarp->renderSkinned();
LLDrawPoolAvatar::sSkipOpaque = false;
}
else if (pass == SHADOW_PASS_AVATAR_ALPHA_MASK)
{
LLDrawPoolAvatar::sSkipOpaque = true;
avatarp->renderSkinned();
LLDrawPoolAvatar::sSkipOpaque = false;
}
}
S32 LLDrawPoolAvatar::getNumPasses()
{
return 3;
}
S32 LLDrawPoolAvatar::getNumDeferredPasses()
{
return 3;
}
void LLDrawPoolAvatar::render(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
if (LLPipeline::sImpostorRender)
{
renderAvatars(NULL, pass+2);
return;
}
renderAvatars(NULL, pass); // render all avatars
}
void LLDrawPoolAvatar::beginRenderPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
//reset vertex buffer mappings
LLVertexBuffer::unbind();
if (LLPipeline::sImpostorRender)
{ //impostor render does not have impostors or rigid rendering
pass += 2;
}
switch (pass)
{
case 0:
beginImpostor();
break;
case 1:
beginRigid();
break;
case 2:
beginSkinned();
break;
}
if (pass == 0)
{ //make sure no stale colors are left over from a previous render
gGL.diffuseColor4f(1,1,1,1);
}
}
void LLDrawPoolAvatar::endRenderPass(S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
if (LLPipeline::sImpostorRender)
{
pass += 2;
}
switch (pass)
{
case 0:
endImpostor();
break;
case 1:
endRigid();
break;
case 2:
endSkinned();
break;
}
}
void LLDrawPoolAvatar::beginImpostor()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
if (!LLPipeline::sReflectionRender)
{
LLVOAvatar::sRenderDistance = llclamp(LLVOAvatar::sRenderDistance, 16.f, 256.f);
LLVOAvatar::sNumVisibleAvatars = 0;
}
gImpostorProgram.bind();
gImpostorProgram.setMinimumAlpha(0.01f);
gPipeline.enableLightsFullbright();
sDiffuseChannel = 0;
}
void LLDrawPoolAvatar::endImpostor()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
gImpostorProgram.unbind();
gPipeline.enableLightsDynamic();
}
void LLDrawPoolAvatar::beginRigid()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
if (gPipeline.shadersLoaded())
{
if (LLPipeline::sUnderWaterRender)
{
sVertexProgram = &gObjectAlphaMaskNoColorWaterProgram;
}
else
{
sVertexProgram = &gObjectAlphaMaskNoColorProgram;
}
if (sVertexProgram != NULL)
{ //eyeballs render with the specular shader
sVertexProgram->bind();
sVertexProgram->setMinimumAlpha(LLDrawPoolAvatar::sMinimumAlpha);
}
}
else
{
sVertexProgram = NULL;
}
}
void LLDrawPoolAvatar::endRigid()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
sShaderLevel = mShaderLevel;
if (sVertexProgram != NULL)
{
sVertexProgram->unbind();
}
}
void LLDrawPoolAvatar::beginDeferredImpostor()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
if (!LLPipeline::sReflectionRender)
{
LLVOAvatar::sRenderDistance = llclamp(LLVOAvatar::sRenderDistance, 16.f, 256.f);
LLVOAvatar::sNumVisibleAvatars = 0;
}
sVertexProgram = &gDeferredImpostorProgram;
specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP);
normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::DEFERRED_NORMAL);
sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
sVertexProgram->bind();
sVertexProgram->setMinimumAlpha(0.01f);
}
void LLDrawPoolAvatar::endDeferredImpostor()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
sShaderLevel = mShaderLevel;
sVertexProgram->disableTexture(LLViewerShaderMgr::DEFERRED_NORMAL);
sVertexProgram->disableTexture(LLViewerShaderMgr::SPECULAR_MAP);
sVertexProgram->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
gPipeline.unbindDeferredShader(*sVertexProgram);
sVertexProgram = NULL;
sDiffuseChannel = 0;
}
void LLDrawPoolAvatar::beginDeferredRigid()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
sVertexProgram = &gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
sVertexProgram->bind();
sVertexProgram->setMinimumAlpha(LLDrawPoolAvatar::sMinimumAlpha);
}
void LLDrawPoolAvatar::endDeferredRigid()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
sShaderLevel = mShaderLevel;
sVertexProgram->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
sVertexProgram->unbind();
gGL.getTexUnit(0)->activate();
}
void LLDrawPoolAvatar::beginSkinned()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
if (sShaderLevel > 0)
{
if (LLPipeline::sUnderWaterRender)
{
sVertexProgram = &gAvatarWaterProgram;
sShaderLevel = llmin((U32) 1, sShaderLevel);
}
else
{
sVertexProgram = &gAvatarProgram;
}
}
else
{
if (LLPipeline::sUnderWaterRender)
{
sVertexProgram = &gObjectAlphaMaskNoColorWaterProgram;
}
else
{
sVertexProgram = &gObjectAlphaMaskNoColorProgram;
}
}
if (sShaderLevel > 0) // for hardware blending
{
sRenderingSkinned = TRUE;
sVertexProgram->bind();
sVertexProgram->enableTexture(LLViewerShaderMgr::BUMP_MAP);
gGL.getTexUnit(0)->activate();
}
else
{
if(gPipeline.shadersLoaded())
{
// software skinning, use a basic shader for windlight.
// TODO: find a better fallback method for software skinning.
sVertexProgram->bind();
}
}
sVertexProgram->setMinimumAlpha(LLDrawPoolAvatar::sMinimumAlpha);
}
void LLDrawPoolAvatar::endSkinned()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
// if we're in software-blending, remember to set the fence _after_ we draw so we wait till this rendering is done
if (sShaderLevel > 0)
{
sRenderingSkinned = FALSE;
sVertexProgram->disableTexture(LLViewerShaderMgr::BUMP_MAP);
gGL.getTexUnit(0)->activate();
sVertexProgram->unbind();
sShaderLevel = mShaderLevel;
}
else
{
if(gPipeline.shadersLoaded())
{
// software skinning, use a basic shader for windlight.
// TODO: find a better fallback method for software skinning.
sVertexProgram->unbind();
}
}
gGL.getTexUnit(0)->activate();
}
void LLDrawPoolAvatar::beginDeferredSkinned()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
sShaderLevel = mShaderLevel;
sVertexProgram = &gDeferredAvatarProgram;
sRenderingSkinned = TRUE;
sVertexProgram->bind();
sVertexProgram->setMinimumAlpha(LLDrawPoolAvatar::sMinimumAlpha);
sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
gGL.getTexUnit(0)->activate();
}
void LLDrawPoolAvatar::endDeferredSkinned()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
// if we're in software-blending, remember to set the fence _after_ we draw so we wait till this rendering is done
sRenderingSkinned = FALSE;
sVertexProgram->unbind();
sVertexProgram->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
sShaderLevel = mShaderLevel;
gGL.getTexUnit(0)->activate();
}
void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR; //LL_RECORD_BLOCK_TIME(FTM_RENDER_CHARACTERS);
if (pass == -1)
{
for (S32 i = 1; i < getNumPasses(); i++)
{ //skip foot shadows
prerender();
beginRenderPass(i);
renderAvatars(single_avatar, i);
endRenderPass(i);
}
return;
}
if (mDrawFace.empty() && !single_avatar)
{
return;
}
LLVOAvatar *avatarp = NULL;
if (single_avatar)
{
avatarp = single_avatar;
}
else
{
const LLFace *facep = mDrawFace[0];
if (!facep->getDrawable())
{
return;
}
avatarp = (LLVOAvatar *)facep->getDrawable()->getVObj().get();
}
if (avatarp->isDead() || avatarp->mDrawable.isNull())
{
return;
}
if (!single_avatar && !avatarp->isFullyLoaded() )
{
if (pass==0 && (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES) || LLViewerPartSim::getMaxPartCount() <= 0))
{
// debug code to draw a sphere in place of avatar
gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
gGL.setColorMask(true, true);
LLVector3 pos = avatarp->getPositionAgent();
gGL.color4f(1.0f, 1.0f, 1.0f, 0.7f);
gGL.pushMatrix();
gGL.translatef((F32)(pos.mV[VX]),
(F32)(pos.mV[VY]),
(F32)(pos.mV[VZ]));
gGL.scalef(0.15f, 0.15f, 0.3f);
gSphere.renderGGL();
gGL.popMatrix();
gGL.setColorMask(true, false);
}
// don't render please
return;
}
BOOL impostor = !LLPipeline::sImpostorRender && avatarp->isImpostor() && !single_avatar;
if (( avatarp->isInMuteList()
|| impostor
|| (LLVOAvatar::AOA_NORMAL != avatarp->getOverallAppearance() && !avatarp->needsImpostorUpdate()) ) && pass != 0)
// || (LLVOAvatar::AV_DO_NOT_RENDER == avatarp->getVisualMuteSettings() && !avatarp->needsImpostorUpdate()) ) && pass != 0)
{ //don't draw anything but the impostor for impostored avatars
return;
}
if (pass == 0 && !impostor && LLPipeline::sUnderWaterRender)
{ //don't draw foot shadows under water
return;
}
LLVOAvatar *attached_av = avatarp->getAttachedAvatar();
if (attached_av && (LLVOAvatar::AOA_NORMAL != attached_av->getOverallAppearance() || !gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_AVATAR)))
{
// Animesh attachment of a jellydolled or invisible parent - don't show
return;
}
if (pass == 0)
{
if (!LLPipeline::sReflectionRender)
{
LLVOAvatar::sNumVisibleAvatars++;
}
// if (impostor || (LLVOAvatar::AV_DO_NOT_RENDER == avatarp->getVisualMuteSettings() && !avatarp->needsImpostorUpdate()))
if (impostor || (LLVOAvatar::AOA_NORMAL != avatarp->getOverallAppearance() && !avatarp->needsImpostorUpdate()))
{
if (LLPipeline::sRenderDeferred && !LLPipeline::sReflectionRender && avatarp->mImpostor.isComplete())
{
if (normal_channel > -1)
{
avatarp->mImpostor.bindTexture(2, normal_channel);
}
if (specular_channel > -1)
{
avatarp->mImpostor.bindTexture(1, specular_channel);
}
}
avatarp->renderImpostor(avatarp->getMutedAVColor(), sDiffuseChannel);
}
return;
}
if (pass == 1)
{
// render rigid meshes (eyeballs) first
avatarp->renderRigid();
return;
}
if ((sShaderLevel >= SHADER_LEVEL_CLOTH))
{
LLMatrix4 rot_mat;
LLViewerCamera::getInstance()->getMatrixToLocal(rot_mat);
LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
rot_mat *= cfr;
LLVector4 wind;
wind.setVec(avatarp->mWindVec);
wind.mV[VW] = 0;
wind = wind * rot_mat;
wind.mV[VW] = avatarp->mWindVec.mV[VW];
sVertexProgram->uniform4fv(LLViewerShaderMgr::AVATAR_WIND, 1, wind.mV);
F32 phase = -1.f * (avatarp->mRipplePhase);
F32 freq = 7.f + (noise1(avatarp->mRipplePhase) * 2.f);
LLVector4 sin_params(freq, freq, freq, phase);
sVertexProgram->uniform4fv(LLViewerShaderMgr::AVATAR_SINWAVE, 1, sin_params.mV);
LLVector4 gravity(0.f, 0.f, -CLOTHING_GRAVITY_EFFECT, 0.f);
gravity = gravity * rot_mat;
sVertexProgram->uniform4fv(LLViewerShaderMgr::AVATAR_GRAVITY, 1, gravity.mV);
}
if( !single_avatar || (avatarp == single_avatar) )
{
avatarp->renderSkinned();
}
}
static LLTrace::BlockTimerStatHandle FTM_RIGGED_VBO("Rigged VBO");
//-----------------------------------------------------------------------------
// getDebugTexture()
//-----------------------------------------------------------------------------
LLViewerTexture *LLDrawPoolAvatar::getDebugTexture()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
if (mReferences.empty())
{
return NULL;
}
LLFace *face = mReferences[0];
if (!face->getDrawable())
{
return NULL;
}
const LLViewerObject *objectp = face->getDrawable()->getVObj();
// Avatar should always have at least 1 (maybe 3?) TE's.
return objectp->getTEImage(0);
}
LLColor3 LLDrawPoolAvatar::getDebugColor() const
{
return LLColor3(0.f, 1.f, 0.f);
}
|