Sunday, June 2, 2013

Building a Better Second Life

Building a Better Second Life
Tips for squeezing both better performance and more detail
out of SL through efficiently made content.

 We all have our complaints about SL. The lag. The lack of visual fidelity. Poor framerates. The unreliable scripts. The lag. The expensive land. The lag!

 I'm sorry to say there is no "silver bullet" to solve these problems. There is no single problem LL can fix that will magic the lag away. That's reality, and it applies to the virtual world no matter how hard you click the heels of your no-mod ruby red slippers, with 600 resize/texture change/colour change scripts in each, together.

 However, there are little things you can do to alleviate these issues somewhat. They add up, so the more people who follow these tips, the better SL looks and runs for everyone.

Use fewer (and smaller) texture maps!

 This is a big one that few seem to consider.

 Textures eat up bandwidth to download, processing power for the sim to retrieve them from the asset server and deliver them to your viewer, and then your videocard needs to store them in memory and render them. Too many large textures are one of the biggest reasons SL gets such poor framerates and why everything takes so long to rez.

Here's some numbers for you, to help illustrate why slapping 1024x1024 textures on everything is bad;

64x64 : 16kb
128x128: 65kb
256x256: 262kb
512x512: 1MB!
1204x1024: 4MB!

 Most people only have 512MB of VRAM and Second Life refuses to use more than that for textures regardless.

 There is a really bad trend with mesh content. People using 1024x1024 textures on every surface, large and small. Often only utilizing small sections of these textures, the rest being unused data that you never see when looking at the object in-world. This is usually the result of applying the same texture to every surface in the 3D modelling program, using offsets for smaller surfaces, then baking shadows and exporting the full 1024x1024 textures even though the model only uses a small visible area.

 What you wind up with is something like this;
 A tiny bit of texture detail, huge area of unused black space. Additional texture detail is then added via multiple similar textures, usually at 1024x1024 resolution

 I've seen this on everything from houses to drinking cups. I bought a bar counter, basically a wooden box, which turned out to have eight unique 1024x1024 textures. In the same bar set was a tip jar, a small drinking cup with a sign reading "Tips" leaning against it. It used three 1024x1024 textures, a 1024x512 texture and a 512x512 texture. Everything in the set was like that. When I rezzed the set in an otherwise empty sim, my framerate dropped from 75fps to 5fps and remained that way until I removed all of the textures. With the geometry alone, my framerate shot straight back up to 75+.

 From another store I purchased a simple, one room house. Not counting the two windows and the single door, the house uses eighteen 1024x1024 textures. Realistically, this house could have been textured with no more than three 512x512 textures and looked more or less identical.

 Outside of the "Daikatana arrow" you never see texturing that inefficient in a videogame, and that is a part of why much prettier videgames run much more smoothly than SL. The performance impact of so many huge textures cannot be understated. This is why so many people experience poor performance in mesh-heavy environments. Mesh is great, low-poly builds allow for better performance than we could get from sculpts and prims, but overloading builds with too many huge textures extinguishes any performance gain.

 So how should texturing be done? More like this;

 Notice how the artist has combined as many elements as possible into a single texture, leaving very little unused black space. This reduces the amount of texture memory your creation eats up while also allowing you to maintain higher resolutions for your textures. The texture detail in the upper right corner is no less a resolution, but now we're using a single texture map instead of, potentially, upwards of six.

 Combine textures, use ALL the space in a texture map and wrap it around the visible surfaces of your mesh. There is no reason not to do this!

 And don't think this only applies to mesh! Those of you who work in prims and sculpts should also consider using fewer, smaller textures and wrapping textures around surfaces using texture offsets.

 A good rule of thumb, if a surface is smaller than 10x10m, use a 512x512 texture or smaller!   I'll get more into avatar textures when I get to draw weight but avatar attachments almost never need textures larger than 512x512 and rarely need textures even that large unless you're using a single texture on a mesh that covers your entire torso or lower body.

I've cut all the 1024x1024 textures and all but one or two of the
512x512 textures from my own avatar's attachments.
 Do you lose detail? Sure, but it's barely noticeable. The increased performance you gain, on the other hand, is substantial.

I've moved things around a bit and changes the trees to mesh since this screenshot.

 At my own fantasy build in Aleph (warning, it is an adult sim so you may encounter NSFW content there) I have used a variety of tricks to remove over sixty 1024x1024's worth of textures and saw my framerates jump from single digits to over 30fps in the worst areas. With shadows on. I'm seeing around 50-60fps in the best areas of the island, up from about 20 before I went gung-ho on texture use.

Use fewer, more efficient scripts!

 Full disclosure, I am not a scripter. I go cross-eyed when trying to cobble scripts together from code on the LSL wiki. If I'm wrong about anything, it will be in this section, but this is my understanding from years of managing sims and working extensively with very skilled scripters in SL. I've run these same recommendations past some of SL's top scripters and they agree with my assessment.

 Every script is a virtual machine which uses memory and processor time.

 Every sim in SL has a set amount of memory set aside for scripts. Now, relatively recently, LL did some things which give sims more memory for scripts, but it is still not an infinite amount!

 While there is memory available, scripts compete with each other for resources so a lot of scripts will, at first, only result in scripts themselves running slower. When the scripts running in that sim exceeds the amount of memory the sim has available, the server has to start using the swap file and that slows the sim down drastically.

 There are tricks to manage the amount of memory each script uses, but generally speaking the more scripts you use, the more memory you're using. This is why single script resizers are encouraged over putting a resize script in every prim of an object.

 Memory isn't the only thing. There's also processor time to consider. This is how much of the CPU resources scripts are using. Believe it or not, sims in SL do not have infinite processing power. So the more of a server's CPU time scripts are eating up, the less CPU there is for other scripts in the sim. This can make scripts run slowly, or not at all.

 So, if you can combine scripts, that's generally a good idea. If you have the option of using multiple scripts or one single script to do the exact same thing, use one single script even if it's more work to write.
You'd be amazed at how many features you can cram into a single avatar without exceeding 500k of script memory.

 Granted, we don't all script. I know my own avatar uses WAY more script memory and time than it should, but just being conscious of your script use, whether for your avatar or for things you build in the environment, can help you see ways to reduce your scripting footprint.

  A good idea is to check new purchases for scripts you don't need. I'm primarily talking items that may have scripted features for resizing, retexturing, etcetera, not scripted features you would use in regular, every day use of the item.

 Make a copy to wear around SL, and a copy to keep in your inventory in case you need the scripts later. Delete all of the unneeded scripts inside the attachment. Some TPVs make this easier. I believe Firestorm has a "delete all scripts in selection" feature which makes this as easy as a single click. Now use the script-free version as the copy you wear and you'll be sparing yourself, and everyone around you, potential lag.

Build small!

 "Oh, Penny! You're such a broken record! Why do you always go on about this?"

Because it works!

 The call for "realistic scale" isn't some irrational desire for everything to be "realistic", this is about design and it is about resource management.

 Constantly people complain about the cost of land! "Land is too expensive! LL should reduce tier!" Maybe so, but STOP BUILDING SO HUGE AND YOU CAN DO MORE WITH THE LAND YOU HAVE NOW!

 You cannot resize land. You want more? You gotta pay!

 If you know that much then it is crazy to blow things up to the sizes most people build at in SL. Larger objects eat up more space! That's not rocket science, that's 7th grade geometry. You can fit four times as many 10x10m squares as you can 20x20m in a given area.

 Most people build to around double scale (give or take), far exceeding the scale of most avatars contrary to the belief that everything is consistently scaled to the "average" avatar size). This is partially due to the default SL camera, partially due to people just eyeballing things and not even thinking about scale. This means your average SL sim holds only 1/4th a sim's worth of content. Or, to put it another way, if you build to scale you can fit about four times more content into a given space.

 "That's not true, Penny! What about prims? When you shrink stuff it uses the same amount of prims! You'll just wind up with an empty looking sim!"

 If you ONLY use prim content made after the release of mesh, then you kinda, almost, have a point. However, that describes almost nobody.

 Before mesh arrived along with the prim size increase to 64, prims were restricted to 10m to a side. Because of that, legacy content made before mesh is often bloated with redundant prims, far more than this content would have needed were it made to scale. Sometimes as much as four times as many prims.

 Now that we have mesh this isn't an issue, provided you're building your own content or have the skills to cull redundant prims from old prefabs. However, mesh itself increases in land impact cost the larger it is.
When working with mesh, whether it's furniture or full buildings, you can substantially reduce the LI cost simply by shrinking it down closer to 1=1 scale. This makes it easy for anyone, regardless of skill level, to reduce their LI footprint simply by reducing the size of their mesh objects.

 "Enough to make up for the 3/4 land area you free up in the process?"

  You tell me.

 Again, here is an SLURL to my M&C fantasy themed build in Second Life.

 I'll post some screenshots below, but I encourage you to go visit the island in person. It's an adult sim, so there's likely to be NSFW content and avatars around, but still, it's probably the best example of building a large, detailed environment while increasing framerates and reducing Land Impact via scale that you're likely to see in Second Life.

 Wander around. Don't just look with your camera. Building interiors are all done as skyboxes, there's tonnes of secret areas. A lot you can't see just by using your camera to snoop from afar. You are able to walk from the arrival point all the way up to the mountain at the far end of the sim.

 Try to do that. Walk all the way up there from the starting point, see the sim firsthand, then open the Land Information window and see how many prims are still available.


 That's right. That entire build is (at the time of this writing) using less than 1/3 of the sim's "prims". I could copy the whole thing twice over and still have LI free to add a bit more. I didn't have to mod anything, aside from resizing, to reduce it's LI, either. Thanks to mesh, you can reap all the LI savings of scaling down just by reducing the size of mesh content.

 I freed up so much LI this way that if I increased everything in the sim to it's original size, I'd not only fill up the sim's LI pool, but I'd exceed it and be forced to remove some of the content I currently have out.

 On top of that, at it's current scale, the island only uses about 2/3 of the sim's area. The entire 1/3 of the sim on the north side is empty. Meaning I could put more islands there on the same level as the rest of the floating island structure.

  The issue a lot of people worry about in building to a more reasonable scale is that many of SL's avatars are huge and may not be able to squeeze into such small environments. This worry is exaggerated somewhat, again people tend to build to a much larger scale than even SL's avatars tend to be. I've not had one single person complain to me that the island has been too small for them.

   You can design buildings so that larger avatars can squeeze through smaller doors by making doorframes phantom, making doors into teleporters, etcetera.

  The only real issue is the SL camera. The default camera placement is just plain bad. It was set up in 2002 or earlier, and LL has never updated it despite the strides the videogame industry has made in third person camera placement.

  Thankfully, it's a problem that is easily solved. Here are simple instructions for getting a much improved camera placement, with explanations which make it easy for you to tweak the camera to your personal liking.

  Also, third party viewers have begun adopting better camera placement, starting with the popular Nirans Viewer, known for it's visual improvements to the SL experience.

 If you're concerned about having traffic rates affected, the example I give here has very respectable traffic, then there are also Doomed Ship and 1920's Berlin. Both popular RP sims which have featured being built to scale for years.

 Now, if you're selling stuff there is an understandable concern about people being able to use your content right out of the box. If you're worried, I'd recommend including large and small copies of your items and letting the customer decide which to use. Give them information to let them make an informed decision. Such as the LI savings.

  The up side is, since the LI of mesh is reduced at smaller scales you can use that as a selling point.

 Selling smaller attachments is less of a problem. You should always, always, design attachments around the smallest possible size simply to make it usable by the largest potential market. It is easy, especially with resize scripts, to make an attachment larger, but it can be incredibly difficult to squeeze an attachment smaller when it was built around a larger size initially. Rigged mesh is a different issue, but rigged mesh is less affected by scale and more affected by body proportions due to its less than perfect implementation.

Draw Weight.

 Now, I just want to wrap this up with a few words on Draw Weight.

 Draw weight is by no means a perfect metric for how much of a burden your avatar is on anyone's hardware, but generally speaking if you can get your draw weight down you increase the framerates for yourself and those around you.

  The average SL user is often at the mercy of content creators as far as their ability to do so, and a lot of content creators do not provide much in the way of options.

 I'm going to pick on a couple of examples here but these are items I use myself, I think the creators did great work, I'm just trying to draw attention to efficiency issues very, very few people in SL ever even think to consider.

I am the prettiest princess!
 There's me, out on adventures. I love this hair, I purchased it at Wasabi Pills, great shop. I've bought a tonne of stuff there. I do have a couple issues with it, though.

  See the dark hair band? That originally had a 1024x1024 texture. That's pretty ridiculous. It's just a shaded cloth texture. I replaced it with a 64x64 texture that looks more or less the same unless you zoom in so close it fills your screen.

  Credit where due, the base hair texture is only 256x256, which is reasonable. Most people use 512x512 or 1024x1024 which is horrendously excessive. The alpha layer on this hair, however, is 512x512 and that's not really necessary at all.

 Then there's one more texture! Inside my head is a box with a 512x512 Wasabi Pills store logo on it.
Neither the prim nor the texture are necessary, both are entirely hidden yet place just as much extra rendering burden on the videocards of everyone who can see me as if it were a giant box on my head.
 People love those store logo root prims. I'm guilty of it, too. back when I was making avatar accessories before I got all efficiency conscious. They're unnecessary and just add to the pile of things SL is trying to make your hardware render.

  One prim and one 512x512 texture might seem small, but my hair doesn't exist in a vacuum. Every avatar you see has probably at least one attachment like that. If you're in a sim with thirty avatars, that's thirty 512x512 textures dumped into your video RAM and thirty extra cubes your videocard is processing.

  Chances are, those avatars have multiple attachments like that. A pair of sunglasses, each shoe! Maybe a hat, or even the root prim of their shirt or any prim/mesh body parts they're wearing. Suddenly, in a sim of thirty avatars you're already exceeding your texture memory just on textures you never even see! That's before getting into the textures they're wearing that you can see! Let alone the sim itself!
Content creators can help by ditching this bad habit!

  Alright, now look lower! Not that far! See the metal chain on the leather weapon harness I'm wearing? (Great looking work, by the way, I got it at Dark Prophet Designs.)

  The chain is a set of sculpts. Each link is a separate prim. Not great, considering you could do multiple links in a single sculpt, but what really shocked me was examining it to find that each link in the chain uses a separate, yet nearly identical 256x256 texture for each half of the chain (mirrored on the other half). That's a total of thirteen unique 256x256 textures, which look identical. Even worse, each of those thirteen prims also uses a separate sculpt map.

  Now, I took the time to remake that chain using just one of the prims, and replaced the texture with a 64x64 texture that looks identical unless you zoom in so close the chain fills the screen. Later, I replaced the chain entirely with a single sculpt.

  What's more, the rest of the harness is loaded with 1024x512 textures. Nothing in the harness needs a texture that large to look good, especially with the quality of the design.

 Now, being someone who can do graphics reasonably well, I can make my own replacement textures, I can rip apart prims and put them back together more efficiently. The average consumer cannot. Most of them don't even think about these things, nor should they ever need to!

  The people who make these things can, and I'm hoping that by making these issues more widely discussed, more content creators will make a point of working more efficiently.

  Make it a selling point! Advertise how little your work adds to avatar draw weight! (LL really should have made draw weight marketplace searchable information.) When it's pointed out to people as a feature like that, it is likely to influence their buying habits in a positive way and we all benefit with the performance boost that comes with more efficient content and avatars.

 Another tip for reducing draw weight is replacing sculpts with mesh. Sculpts are horribly inefficient with polygons and content creators are generally able to create far more detailed attachments using far fewer rendering resources just by using mesh. So, if you ever have the choice between similar attachments, one mesh and one sculpted, consider going with the mesh version.

I have, by far, the lowest Draw Weight in this screenshot.
 At the time of this writing, my draw weight is 68,445, down from about 210,000 in January. I've managed to do this without anyone being able to see much if any difference in my appearance. I've cut out every hidden prim, every invisible root prim, every unseen texture, every redundant texture, every too-large texture and by replacing sculpts with mesh where possible. I'm sure if I replaced my remaining sculpts with mesh then I could cut my draw weight in half.

 My goal is to eventually reduce my draw weight out of the red (I think it turns to orange around 35,000), at which point I'll see if I can squeeze down to green.

 With mesh, if content creators start taking efficiency seriously, we can reach a point where there is no reason for anyone's draw weight to be over 35,000 and we can do that without sacrificing the quality of our avatars.



6 comments:

  1. Here is why some of the above mentioned won't work, in m y opinion:

    http://yournymph.blogspot.de/2013/06/misconceptions-about-users.html

    ReplyDelete
    Replies
    1. It seems to me that you're not arguing that these tips won't work, but that the primary thrust of your argument is that the average SL user cannot make use of these tips.

      If that's the case, I agree. Replacing/resizing textures, reworking your scripts to be more efficient, etcetera...these are all advanced skills.

      However, that does not mean it's not worthwhile to put the information out there for those who can use it. Particularly content creators.

      Also, most users should be able to resize content down to more reasonable sizes, deleting unused scripts and other simple tips for improving performance.

      Delete
    2. Part of the problem is getting at the textures to change their size. The DRM built into SL is an obstacle here.

      (I do know ways of getting at textures. It doesn't need any evil viewer version.)

      I've seen some quite good furniture that is still open to improvement. One trick you miss is that textures do not have to be square. So there is an item I have which uses a single tiled 512-sq texture. Because the tiling is so enormously different, horizontal and vertical, 512x256 or even 512x128 should work.

      But I can't get the texture out of SL to do that. Not without breaking rules.







      Delete
    3. @zhochaka

      You're right on all counts. There's definitely no reason textures need to be square and, depending on the shape of the object or the way you tile the texture, you can often reduce the size of a texture, without noticeable quality loss just by using a another ratio. If your texture has a repeating pattern, see how much redundancy you can cut.

      Also right about being unable to, legitimately, resize textures in SL (unless they're your own of course). There's really no reason we shouldn't be able to resize textures right in SL itself. Might be worth getting a bunch of people to submit this as a new feature request.

      Delete
  2. This is useful and interesting concept about Online Reputation Management services and usefulness. Strategies is great and is one of the very strong benfits.You can also visit my site. Building Plans I am impresed form your blog.

    ReplyDelete
  3. If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job. Starls

    ReplyDelete