Avatar Impostors tech details

=== How To ===
Avatar Impostors can be turned on or off from the Second Life Edit menu > Preferences... > Graphics > [X] Custom > Avatar Rendering: [X] Avatar Impostors
=== Feature Design Document ===
Avatar impostors replace the rendering of an avatar with a cached 2D rendering (sprite) of the avatar. The sprite is updated only when needed, thus reducing the total number of full avatar renders and improving performance.
==== Requirements ====
* Enabling avatar impostors should generally improve performance of crowded scenes.
* Enabling avatar impostors must NEVER harm performance.
* For visible avatars, the logic to draw them are based on the value of debug setting called "RenderAvatarMaxVisible" :
** The 25% closest avatars are not impostored
** The back 25% are impostored and updated when needed, but no more than once every 16 frames
** The middle 50% are impostored and updated when needed.
* For the above description, "when needed" consists of:
** Significant changes in viewing angle/distance.
** Change of avatar pose
** Change of avatar attachment
** Attachment animation
* When impostering is enabled, avatars becoming visible/invisible while in view should fade in/out smoothly.
** To avoid too much fade-in/fade-out (which is distracting) avatars that have become visible will stay visible for at least 10 seconds.
==== Example ====
The 25/50/25 split is a source of much confusion. Here's a plain example:
Suppose RenderAvatarMaxVisible was set to 100. 
* That means the viewer would try to render no more than 100 avatars. 
* Since the first 25 avatars will not be impostored, you would need to fit 26 avatars on the screen at one time in order for one avatar to become an impostor. 
** In this example, the avatar furthest away *from the camera* would be an impostor. 
** Every frame, the viewer will figure out which visible avatar of the 26 is furthest away and impostor that avatar. 
* If 75 avatars are visible, the closest 25 will not be impostored, but the furthest 50 will. 
* If 76 avatars are visible, the furthest avatar will be impostored, and its impostor will only update once every 16 frames. 
* If more than 100 avatars are visible, only the closest 100 are rendered, plus avatars that are "transitioning" between visible and invisible. 
** To avoid flickering avatars against the background, avatars will fade out if they get too far away in the crowd.
=== Functional Spec ===
(none)
=== Test scripts ===
(none)
=== Discussion for future improvements ===
(none)
=== Relationship to other features ===
=== User Guides ===
(none)
An attachment (at some distance) is visible with 50% transparency and disappears at 51% transparency.
What are the rules? 
Impostors are cutouts, not translucency, so anything the avatar is wearing that more than 50% transparent will not be rendered. The same thing happens for non-impostored geometry on a face-by-face basis for items that are very small on screen. 
----
How can I tell if impostors are working?
Turn on Wireframe mode (ctrl-shift-R or Client>Rendering>Wireframe). Impostored avatar will not be visible as a wireframe.
----
how does the avatar detail slider affect the impostor distance?
how does the size of the avatar + attachments affect the impostor distance?
how do we measure the size of the avatar + attachments?
how often should the impostor update? how can we measure that?
The code for impostor update frequency is as such:
 F32 impostor_area = 256.f*512.f*(8.125f - LLVOAvatar::sLODFactor*8.f);
 if (visible && mPixelArea <= impostor_area)
 {
 mUpdatePeriod = llclamp((S32) sqrtf(impostor_area*4.f/mPixelArea), 2, 8);
 visible = (LLDrawable::getCurrentFrame()+mID.mData[0])%mUpdatePeriod == 0 ? TRUE : FALSE;
 }
If that visible BOOL comes out TRUE for a given frame, that avatar will get an animation update. LLVOAvatar::sLODFactor is the value that comes out of the avatar mesh detail slider. mPixelArea is the number of pixels being covered by the AABB that surrounds the avatar and all of its attachments.
If the AABB of the avatar hasn't changed significantly after an animation update, there is no impostor update (this prevents redundantly updating impostors for avatars that aren't moving).
There's no info display for impostor update periods or when an update is triggered. Would you like me to make one? It should be trivial to make impostors flash green on frames where they received an update and display the update period as debug text.
== Related Links==
*What are Avatar Impostors?