Posts Tagged ‘tutorial’

Second Life Prim Lights – 3

Saturday, July 10th, 2010

Full-bright and Glow

This is the last article in my short (and rather infrequent) series about lights in Second Life. I’m going to take a look at two elements of textures which are often used in conjunction with lights, and which are also widely misunderstood and misused.

Let’s start with Full-bright. This can be switched on or off on the Texture tab of the Build dialog, and applies to the currently selected texture, or to all the textures on the currently selected object if you haven’t selected an  individual face.

What does it actually do? The most obvious effect is that during SL ‘night’ the texture will appear bright (as the name of the option suggests). During daylight the effect is, predictably, less obvious. In fact, sometimes the object might actually appear to be darker in daylight.

Here is the same scene in both day and night. The picture on the wall has full-bright set on it, and you can probably see that the picture is displayed identically in both light settings.

Full-bright example

Let’s step back a moment. How does Second Life create the ‘night-time’ effect? Well, apart from changing the sky, it obviously makes all the objects in the world darker. It does this by taking the colour which they should be, and blending it with the ‘nighttime’ colours.

What might be less obvious, is that it does something similar during daylight. It takes the colours, and adjusts them according to the current lighting. This is how you get the distinctive orange lighting effect at sunset that some people  complained about when Windlight was first released.

When you set a texture to full-bright, this blending is switched off for that texture, so it always displayed at it’s actual colour, regardless of the current lighting. At night, this has the effect of making the object seem to light up — in fact, it is simply not being darkened.

So much for full-bright. Now what about its companion, Glow? Unlike full-bright, this is exactly what it says. When you set a glow value for an object, it acquires a glowing halo around it. This can range from a subtle, barely visible aura, up to a near-blinding glare.

Glow example

Transparency tends to lessen the effect of glow slightly (the lower row in the picture has transparency applied).

Under most circumstances, using low values is best, usually no more than about 0.25, and often less than that.

One thing to be aware of is that if two glowing objects overlap in the viewer, the glow effect is doubled. This is not always what you want to happen, so you probably need to be careful if you place glowing objects close together.

Overlapped glow example

Another unfortunate effect that I’ve often seen is where the glow is being used with an object which has a partially-transparent texture. For the glow to show up in this case it needs to be set quite high. When the texture is fully loaded, the effect is subtle and often beautiful. Unfortunately, while the texture is still being loaded, the glow is in full force, and often overwhelmingly bright. There is not much that can be done about this, but if you intend to use this kind of effect, you should be aware of this pitfall.

Partially-rezzed glow example

Glow and full-bright work very effectively together when creating a light. As a simple example, rez a prim, set its transparency to 25 (if you set it too high you will lose some of the effect), then switch full-bright on and set the glow to 0.2. The result will, of course, not actually illumine the surroundings unless you set the Light feature on, but this kind of ‘fake light’ can give the illusion of there being more lights than SL actually supports, especially if you use several of these in conjunction with a single ‘real’ light.

Full-bright and glow lighting example

Some SL photographers make use of a interesting effect which happens when an avatar stands in front of a ‘glowing’ texture. This is easier to show than to describe, although the effect is quite subtle, and is caused by the glow slightly spilling over the edges of anything in front of it. Here are ‘without’ and ‘with’ glow versions (this is a rather exaggerated version, with the glow set quite high to make the effect obvious):

Photo-glow effect

However, if you intend to save your photos, there is an issue to be aware of, which is that the Second Life snapshots tend not to capture glow correctly. For example, the scene of streetlights on a wall (above) was captured using my computer’s screen-capture, rather than the Second Life screenshot, which looked like this:

Glow snapshot problem

Finally, ‘glow’ works best when it is used for subtle effect, and with some restraint. Whatever you do with ‘glow’, please don’t do this:

Glow abuse example

A Not-So-Brief Guide to SLurls

Thursday, May 20th, 2010

This started out as ‘A Brief Guide…’, but I found that there was more to say about them than I thought!

If you are familiar with SecondLife, you will certainly have come across SLurls. In-world, they appear as hyperlinks (you can see them as such in chat or in notices, amongst other places). They look like normal web addresses, like this:

http://slurl.com/secondlife/Ling/183/113/54

When you click on them in-world, instead of launching a browser they will display a landmark, from which you can teleport to the location.

So far, not very interesting. Where things get a little more interesting is when you come across an SLurl on a normal web-page, outside of Second Life. If you click on one of these, you will end up on a web-page that shows the Second Life world map, highlighting the location that the SLurl points at:

What happens when you click on the ‘Teleport’ button depends on whether you have Second Life installed, and (if it’s installed), whether it is running at the time.

If Second Life is already running, a landmark for the location will be displayed for you in the Viewer.

If you have Second Life installed, but it is not currently running, it will be launched, and when you log-in you will be taken directly to the location indicated by the SLurl (although the exact details of what happens will depend on the browser you are using, and possibly the Second Life Viewer as well).

One thing to note is that SLurls work like landmarks, in that if the location has a fixed teleport point, you will be taken there, rather than to the exact location specified in the SLurl.

This is all quite straight-forward, even if it takes several paragraphs to explain. But what if you want to create your own SLurls?

There are three ways to do this. Let’s take the simplest one first. In Second Life, visit the location that you want the SLurl to point to, open up the World Map, and click the ‘Copy SLurl’ button that you should find somewhere near the bottom of the right-hand side.

This will copy the SLurl to the clipboard — you can open up a text or document editor, and simply paste it in.

If you are using Viewer 2, you will also find a ‘Copy SLurl’ option on any landmarks that are stored in your inventory. Right-click the landmark to open the menu that has this option:

Speaking of Viewer 2, it uses a different style of SLurl, and takes you to a different web-page (if you click on an SLurl outside Second Life), but you still get a world map with a teleport button. The main difference is that the web-page is in Viewer 2 style.

If you are interested, here are examples of the old and the new versions:

Old version: http://slurl.com/secondlife/Ling/183/113/54

New version: http://maps.secondlife.com/secondlife/Ling/183/113/54

Ok, so much for the easiest way of creating SLurls. The second way is slightly more complicated, but adds some very nice features.

Before you begin, you’ll need to know the details of the location that you want the SLurl to point to. To do this, visit the location in Second Life, then open up the world map and take a note of the region name, and the x, y, and z values for the location.

Now visit the SLurl website, simply by using your favourite browser to go to http://maps.secondlife.com (or http://slurl.com if you prefer the old version). On this page you will see a ‘Build your own SLurls’ link, near the top right. This will take you to a new page with various edit boxes on it.

Fill in the Region name, and the x, y, and z boxes, with the values you noted earlier.

For now, leave the other boxes empty, and click the ‘Generate’ button. Your SLurl will appear in the edit box at the bottom. Test it by clicking the ‘Go’ button. You should be taken to a new page showing the World Map for the location which you entered.

Returning to the Build SLurl page, select the generated SLurl, copy it, and paste to wherever you want to use it.

This SLurl will be exactly the same as the one generated by the World Map inside Second Life. However, you can improve on this by filling in the other edit boxes on the Build SLurl page.

The Window Title is the simplest. If you enter some text here and generate an SLurl, when you visit the World Map using it you will see the title appear on the ‘pop-up’ marker for the location.

The Window Message works in a very similar way, adding some descriptive text to the pop-up.

The Window Image is more complicated. For this to work, you need to be able to specify the web address of a picture. If you have your own web-site, you can upload a picture to your site, then fill in the address for it here.

Generate the SLurl again, and click ‘Go’, and now you should see your picture in place of the default picture. As far as I can tell, any size of picture will be accepted (within reason!).

Using the Picture and Description together can be a good advertising tool if you are a Second Life merchant. Here’s an example of what I could do to advertise one of my prefabs:

View the Medieval Farmhouse in-world

I mentioned that there were three ways to create an SLurl, but so far I’ve only shown you two ways. The third way is to construct one manually. This would be a whole post in its own right, but if you are familiar with URLs it isn’t too difficult to roll your own SLurl.

I won’t go into details, but here is a quick breakdown, using the Version 2 format, and taking my ‘Medieval Farmhouse’ SLurl as an example (see the link above):

The basic template is this:

http://maps.secondlife.com/secondlife/Region/x/y/z?img=[address]&title=[title]&msg=[description]

The first part is the basic URL:

http://maps.secondlife.com/secondlife

This is followed by the Region name and the x, y, z values:

/Ling/193/113/54

There are then three optional parameters: img, title, and msg (the description):

img=http%3A//www.templarcreations.com/blogpics/blog_prefab_0001a.png

title=Medieval%20Farmhouse

msg=22%20prims%2C%2016m%20x%2016m%2C%20L%24250

As you can see, the ‘msg’ parameter can easily get messy, because you have to replace any special characters.

And finally … the Teleport button on the World Map page conceals another URL, but in a different format, like this: secondlife://Ling/193/113/54. It is possible to link directly to a location using this format. This will by-pass the
World Map, and (assuming that Second Life is installed) go straight to Second Life. It probably isn’t a good idea to use this, because it is not exactly user-friendly, and if the user doesn’t have Second Life installed, instead of ending up on the World Map page (which will lead them to more information about Second Life) it will simply display an error. On the other hand, for Second Life users it gives more direct access (I can imagine it being used to create a web-page of useful landmarks, for example).

Second Life Viewer 2.0 — Some Brief Tips

Monday, April 5th, 2010

I don’t like it, you don’t like it, but LL is determined to force it down our throats. There’s plenty of discussion elsewhere about the pros and cons of the new Viewer 2.0, so I won’t pick that up here. Instead, I’ll just bring a few tips that might make your experience a little bit better.

Skins
Because I’m a builder, I’m approaching this mainly from the point of view of a creator in Second Life, but my first tip is one that will be useful for anyone: download the Starlight skin!

Let me explain (if you don’t already know). Viewer 2.0 comes with the ability to change ‘skins’ — in other words, the appearance of the interface. At the moment, unfortunately, they don’t seem to have put in place an easy mechanism for installing and switching between skins, so for now it is a case of copying and renaming folders. If you are comfortable with doing this, there is already one third-party skin which is well worth having, which is the Starlight skin created by Hitomi Tiponi.

Starlight, Viewer 2.0 skin

The most significant thing that is does is to change the right-hand slidebar so that it overlays the main viewer screen, rather than squashing the display. This squashing of the display seems to be a major complaint about the new Viewer (and I certainly don’t like it myself, and find it very disconcerting and distracting), so a fix to this is more than welcome.

Viewer 2.0 Starlight sidebar

Debug Menu

If you do regular building or scripting in Second Life, you probably find the Advanced/Debug menu invaluable. Under Viewer 2.0, the Advanced menu can be summoned up using the traditional CTRL+ALT+D incantation. At the bottom of this menu you will find a ‘Developer Menu’ option — select this, and a Developer menu (essentially the old Debug menu) will appear, will the old familiar options in it.

Activate Group

Bizarrely, this seems to be a well-hidden option, unless I am missing something obvious (which is always possible). To get to this, open the sidebar, and select the Groups tab. It is not immediately obvious, but there is a right-click menu available for the group names, and this menu has the ‘Activate’ option.

It took me quite a while to find that one…

Shared Media

Possibly the only reason to really celebrate the arrival of Viewer 2.0 is that we finally have the long-awaited HTML-on-a-prim. Some people have reported problems with getting this to work, but so far it has worked impeccably for me.

To display a resource from the web (usually a webpage), create a new prim and size it appropriately. Select a single face before continuing. On the texture tab of the build menu, there is a new ‘Media’ option at the bottom, with a small plus sign. Click the plus, and a new dialog will appear. Fill in the URL of the page you want to display, and click Apply.

Shared media on build dialog

If all goes well, the page should display on the selected face of the prim. The page will be fully active — if there are links, they can be clicked on.

Note that you can apply different media sources to different faces. Here’s a cube running two YouTube videos simultaneously:

Shared media example

For a jaw-dropping example (and a hint of what might now be possible), try applying http://collabedit.com/ to a prim face, then clicking the ‘Click here to create a new document’ button.

In a few seconds you will have a document which you can edit directly from Second Life. On a prim.

Editing on a prim

What’s more, it’s collaborative, so in theory someone else can edit the same document with you (I’ll admit that I haven’t had a chance to try the ‘collaborative’ part, so I’m not sure how or even whether it will work…once I find out, I’ll let you know).

Second Life Prim Lights – 2

Wednesday, March 24th, 2010

After the previous introduction to prim lights, let’s look at some technical (but not too technical!) background, and a few things about the lighting system which are not immediately obvious:

The graphics system which Second Life uses (OpenGL if you are interested) only allows 6 lights to be visible at any time. If a new light becomes visible, one of the other lights will be disabled, so you should avoid having too many lights too close together.

(As an aside, this is one of the reasons why some people complain about facelights, and especially about facelights which make use of multiple lights — every one of those lights uses up one of the available lights.)

A light has no visible appearance. When you turn a prim into a light by ticking the ‘Light’ checkbox on the Features tab, the prim itself doesn’t change in any other way, it simply has an invisible light-source attached to it. This light source will move with the prim, but is otherwise completely unaffected by anything that you do to the prim, apart from changes to the actual light parameters.

This means that the size and the shape of the prim have absolutely no effect on the light, because the light source is always a single point at the centre of the prim. This might not be what you expect. For example, if you turn on light for a prim cube, then stretch the prim out into a long rectangle, you won’t get an elongated light-source, you will still get a sphere of light originating at the centre of the prim (well … not exactly a sphere — see this previous post if you want to know more about that).

Light example

The light is not blocked by prims. Ok, it isn’t quite as simple as that…

Lights won’t illumine prim faces which are facing away from the light-source. This sometimes makes it look as if the light is blocked by prims. Suppose there is a wall in-between you and the light source. You won’t see any light on your side of the wall, because it is facing away from the light, and it looks as if the wall is blocking the light. However, if the light is low  enough, you will see light on the ground outside the wall.

This is easier to show than explain, so here is an example. The small cube on the right-hand side of the wall is the light-source. You can see that it lights up the floor on both sides of the wall, but doesn’t light up the side of the wall which faces away from it (the wall is standing directly on the floor):

Blocked light example

Another effect of this is that the prim itself is not illumined, because all the visible sides of the prim are facing away from the light. To make it actually look like a light-source you can turn on full-bright for it, and perhaps apply a small amount of glow (a setting of 0.02 is usually sufficient).

Finally, prim lights don’t cast shadows (except as an experimental feature in some third party viewers). If you want to provide a shadow effect, the usual way to do this is by texturing the surface that you want the shadow to appear on, or by creating a thin ‘shadow’ prim with a semi-transparent shadow texture.

Second Life Prim Lights – 1

Thursday, March 18th, 2010

In Second Life constructions few things are more misused and misunderstood than lights, full-bright, and glow. In this post, I’ll start looking at lights (!), and I will cover full-bright and glow in subsequent posts.

To begin with, let’s create a simple light. Start by rezzing a sphere, which will act as the light source. On the third tab of the Build dialog (Features) you will see the light options in the lower half. Tick the ‘Light’ checkbox, and the sphere will start to cast light (you might want to set your environment to midnight to see this to best effect).

Features tab on the Build dialog

You’ll notice that the sphere doesn’t light up in any way — it still looks like a plain plywood sphere. I’ll talk more about this in the next post, but in the meantime you can make it more realistic by going to the texture tab, setting the texture to blank, turning on Full-bright, and setting the Glow value to something like 0.02. You could also set the transparency (try a value of 25.0).

There are four basic parameters for lights, as you can see on the build dialog. The first is the colour. Clicking the colour square will bring up the standard colour selector.

The Intensity value is simply how bright the light is, and can take values from 0 (where the light is effectively off) to 1.0, at which point the light is at its brightest.

Well…”brightest” is perhaps misleading. You’ll notice that even at maximum intensity the light isn’t really very bright. It’s possible to create an even brighter light by putting a second light source right next to the first one. The light from both will combine where they overlap, and become even brighter.

The only problem with this is that you are using up another of your very limited number of lights (more on that in the next post).

The Radius value is, predictably, the size of the area that the light will be cast over. This isn’t a precise value, because there is a certain ‘fuzziness’ at the edges. It can range from 0.0 to 20.0.

The Falloff value describes how quickly the light ‘fades’ as it approaches the radius limit. In theory, a Falloff of 0.0 will stay at full intensity right to the edge, whereas a Falloff of 2.0 (yes, it goes to 2.0, don’t ask me why!) will fade away very quickly.

In practice, the Falloff is a much more subtle effect, and combines with the Radius value (which also has a rather subtle impact). Experimenting with them is the only way to really understand what their final effect is.

And that’s your basic light. More next time…

Textures – A Few Quick Tips

Friday, November 20th, 2009

Some hints and tips that might make working with textures quicker and more efficient.

1. Instantly apply a texture

…without even opening the Build dialog! Simply drag a texture from your inventory onto the surface that you want to texture. The texture will instantly be applied to that face. Obviously this will only work on prims that you have modify permissions for.

2. Applying a texture to multiple faces

In the Build menu, tick ‘Select Texture’ as usual, and select the first face. Then hold down the Shift key and click on any other faces that you want to texture, even on completely different prims. Then apply the texture that you want, via the Texture tab. The texture will be applied to all the selected faces.

The only catch to this is that sometimes Second Life is a bit flaky about actually texturing all the selected faces, so don’t unselect straight away, and simply re-apply the texture if it doesn’t ‘take’ to all the faces.

3. Using the dropper

On the Texture tab, click the texture image to bring up the texture selection dialog. There is a small ‘dropper’ icon at the bottom of this. Click this icon, then click on any other prim face, and the texture from that face will be selected for the current face. This will only work to pick up textures that you have copy permissions for.

4. Choose between the texture selection dialog or your inventory

There are two ways to directly get a texture onto the texture tab (and hence on to the selected prim or face), either by dragging a texture from your inventory onto the texture image, or by clicking the texture image to call up the texture selection dialog.

Both have their pros and cons.

The Texture Selection dialog will search through your Inventory, and will only show you the textures or snapshots that you can apply as a texture. It will hide everything else, including textures that you cannot use (probably because you don’t have copy permissions for them). This is useful, but if you have an
inventory of any size it can take some time for the list of textures to fill up.

If you use your inventory instead, you don’t have this delay, but of course you will be shown everything, including textures/snapshots that you cannot actually use. If you try to drag these onto the texture image, the cursor will change to a ‘stop’ icon to show that you cannot use them.

5. Use the Library

Down at the bottom of your inventory is a folder called Library, which contains a default collection of stuff that Linden supplies to every avatar (they sometimes add to this collection, so it’s a good idea to take an occasional look here for new things). It includes a useful and varied collection of textures. Before you spend your hard-earned Linden Dollars buying a new texture, look here first, to see if there is already something which suits your needs.


6. Use the Library’s default transparent and media textures.

If you need a fully transparent texture, or a texture to display videos on (a subject which is beyond the scope of this blog entry), the Library has default textures for these (they are at the top of the Library ‘tree’, not in the Textures folder). The advantage to using these is that they are very likely to already be in the viewer’s cache, and hence won’t need to be downloaded, which means that they will rez much faster.

8. Use the bumpmaps and colors

I’ve mentioned this in a previous post, but it’s worth repeating: experiment with the bumpmaps option on the Texture tab. Using bumpmaps, and applying colors, can create good textures without making use of a texture image at all (simply change the default ‘plywood’ texture to ‘blank’), or can create useful variations of existing textures.

Also worth repeating is the example to illustrate this technique:

Animated Textures – Tutorial 3

Saturday, October 24th, 2009

In the previous two articles you saw how to use llSetTextureAnim() to activate conventional animated textures. This is the usual way of animating textures in Second Life.

There is another way, which involves using a script and a timer, along with the ‘offset texture’ function. This is far less efficient than using a normal animated texture, but there are occasions when it can be useful.

Let’s have an example. In the first set of animated textures released by Templar Creations you will find an animated gauge, with three frames of animation. If this is animated in the normal way, the effect is like this:

Animation example

Although this works, it’s rather ineffective. It would be better if the needle moved randomly. That can’t be done with a normal animation, but it is possible using the timer system.

The way this works is that the script sets up a timer, and each time the timer event fires, the script selects a random frame and displays it. I can’t easily demonstrate this is on a webpage, but if you visit the main Templar Creations store you will find a running example.

So, how do you display a specific frame?

In the previous article you saw how to display a single frame of an animation, using the ‘repeats’ setting on the texture tab of the Build dialog, and the llOffsetTexture() function.

For this example, let’s set the repeats in the script itself. The texture in question has three frames, so the horizontal repeats must be set to 0.333. The script will put the offset at 0.0, which will display the second frame, with the needle pointing straight up.

Why does an offset of 0.0 display the middle frame? Because the offset is from the middle of the texture. An offset of 0.333 will move the texture to the left so that the third frame is displayed. An offset of -0.333 (or 0.666, because textures wrap around) will move the texture to the right, so that the first frame is displayed.

Imagine that the texture is a long strip extending out from both sides of the visible prim face. Here it is at the default offset of 0.0, so that the middle frame is visible:

Offset 0.0, Frame 1

Offset 0.0, Frame 1

Setting the offset to 0.3333 shifts the strip of frames to the left, displaying the third frame:

Offset 0.3333, Frame 3

Offset 0.3333, Frame 3

Setting the offset to -0.3333 shifts the strip to the right, displaying the first frame:

Offset -0.3333, Frame 1

Offset -0.3333, Frame 1

Naturally, if you have a different number of frames, these numbers will also be different.

The script makes use of the llFrand() function to return a random number between 0 and 2, which it then uses to select the correct frame, and sets the offset for that frame. It also uses this to set the delay between frames to a random amount.

It also sets the texture scale, so that one frame at a time is displayed.

[sourcecode language="cpp"]
list Offsets = [0.666, 0.000, 0.333];
integer Frame = 1;
default
{
    state_entry()
    {
        llScaleTexture(0.333, 1.0, ALL_SIDES);
        llOffsetTexture(llList2Float(Offsets, Frame), 0.0, ALL_SIDES);
        llSetTimerEvent(llFrand(0.5) + 0.1);
    }
    timer()
    {
        Frame = (integer)llFrand(3);
        llOffsetTexture(llList2Float(Offsets, Frame), 0.0, ALL_SIDES);
        llSetTimerEvent(llFrand(0.5) + 0.1);
    }
}
[/sourcecode]

That concludes this short series of articles on animated textures.

Animated Textures – Tutorial 2

Thursday, October 1st, 2009

In the previous blog you saw how to use the SMOOTH option for simple animation. Although this is useful, it is also rather limited. The usual way of creating animated textures is by way of a texture which contains a set of ‘frames’, in a way very similar to that used in traditional animation.

Note: the examples from this blog are available as full-perm pre-built prims at the Templar Creations sandbox (behind the main store), for you to copy and experiment with, and use in your own builds if you wish.

Let’s have an example. Here is a texture which has three frames, to create a rotating gear:

Gears example

Gears example

Gears example (animated)

Gears example (animated)

Let’s assume you are starting from scratch. When you apply the texture to the prim, all three frames will be displayed (and will be ‘squashed’ horizontally):

Gears image applied as texture

Gears image applied as texture

This will be corrected when the animation starts running, but it is often useful to have a single frame displayed when the animation is not active. To do this for this particular texture (and any texture which has just three horizontal frames), you need to set the horizontal repeat to 0.333, so that just 1/3 of the texture is displayed. Set the horizontal offset to 0.666 to display the first frame (understanding the offsets, and how to calculate the offsets you need in order to display specific parts of a texture is an entire future blog article in itself!).

When the texture is not being animated, it will revert to this display.

To start the animation, you need a script. On the Contents tab of the Build dialog, click the New Script button, and double-click the script that appears, to edit it.

For this demonstration, the script will switch the animation on and off when the prim is clicked on, so delete the contents of the script, and replace it with the following:

[sourcecode language='cpp']
integer isRunning = FALSE;
default
{
    touch_start(integer count)
    {
        if (isRunning)
        {
            llSetTextureAnim(0, 0, 1, 1, 1, 1, 5.0);
            isRunning = FALSE;
        }
        else
        {
            llSetTextureAnim(ANIM_ON | LOOP, 0, 3, 1, 0, 3, 5.0);
            isRunning = TRUE;
        }
    }
}
[/sourcecode]

The script uses the isRunning variable to keep track of whether the animation is on or off. When someone touches the prim, if this is FALSE (the animation is not running) it starts the animation, otherwise it stops the animation.

So, what are the parameters?

The first parameter is a set of flags, which in this case switch the animation on (ANIM_ON), and set it to play continuously (LOOP). The next parameter is the side of the prim which is to be animated. Use ALL_SIDES to animate all the sides of the prim. In our example, only side 0 is animated.

The next two parameters describe the layout of the frames — how many there are horizontally (3 in this case), and how many there are vertically (1 in this case).

Suppose we had a texture which contained two vertical rows of three frames each. The frames in this texture would get displayed in the following order:

Animated frames example

Frame order example

The next two parameters are the first frame, and the number of frames. This means that you can display only part of an animation if you want to. Some of the animations in the Animated Texture pack make use of this by having the very first frame as the ‘off’ frame, and displaying frames 2 to the end for the actual animation.

Note that the frames are numbered from 0, so in our three-frame example the frames are 0, 1, and 2.

The last parameter is the frame-rate — the number of frames per second.

In the previous blog post, the animation used the SMOOTH flag to scroll a single frame smoothly across the prim surface. Let’s take another look at this, because there is a little more to the SMOOTH option.

To demonstrate this, let’s have an image of 6 numbers:

Scrolling frames example

Scrolling frames example

Apply this texture in place of the original and replace the second llSetTextureAnim call in the script with the following:

llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, 0, 6, 1, 0, 6, 0.5);

Save it, and touch the prim again to restart the animation. This time, you will see each number smoothly scroll into view.

In the next tutorial blog, I’ll show a third way of animating textures, which doesn’t make use of llSetTextureAnim() at all.

Animated Textures – Tutorial 1

Saturday, September 19th, 2009

With the recent release of the Animated Steampunk Textures pack, this would be a good time to do some tutorials on animated textures, so here we go…

This is the first of a three-part tutorial about using animated textures in Second Life. There three parts, because there are three different ways of animating textures, each with their own use. Two of them make use of the LSL function, llSetTextureAnim, which is the usual way of animating textures. The third way uses a timer and offsets to manually animate the texture — it is a lot less efficient, but can occasionally be useful.

In this first part, however, I’ll look at the simplest and easiest way of animating a texture, using the ‘smooth scroll’ option. This simply moves the texture across the surface of the prim, and doesn’t need a specially designed texture — any texture can be scrolled, although some will obviously work better than others!

A common use of this is to create a flowing water animation, and that’s the example I’ll use here, especially as suitable textures are available from the built-in Library in every Second Life avatar’s inventory.

So…

Rez a simple cube, and apply a water texture to it — the Water – ripple layer 1 texture in the Library\Textures\Waterfalls folder should work well. Resize it into something fairly long and flat (5 x 2 should be effective).

On the Contents tab of the Build window, click the ‘New Script’, and wait for it to appear in the Contents list (if SL is being laggy this might take a few seconds). Double-click to open it.

Replace the existing code with the following:

[sourcecode language="cpp"]
default
{
    state_entry()
    {
        llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, 0, 1, 1, 1, 1, 0.12);
    }
}
[/sourcecode]

Save the script, and the texture will start scrolling. Assuming that you haven’t rotated the prim, this will scroll the top surface.

Ok, now you’ve seen it in action, let’s look at the parameters.

The first parameter is a set of flags which specify how the texture should be animated. You can string together several flags (as in the above example) by using the ‘|’ symbol (technically an ‘OR’ operator). Note that some combinations don’t make sense.

You can check the LSL Wiki page for details of what each flag means, but in the example we are switching the animation on (rather important!), and we are saying that we want a ‘SMOOTH’ animation, which means that the texture will simply be scrolled across the surface of the prim (actually, this is not quite an accurate description of what SMOOTH does, but I’ll explain it in more detail in the next article).

Finally we are specifying ‘LOOP’, which means that the animation will keep going continuously.

Instead of LOOP we could have specified PING-PONG, which reverses the animation when it reaches the end. In the case of a smooth animation, it will scroll the texture for the entire length, then reverse direction and scroll it back again.

If you want to stop an animation, simply set this parameter to 0. All the other parameters are irrelevant in this case.

The next parameter — 0 in this example — is the face of the prim that the animation should be applied to. All the other faces will be static. However, if you use ALL_SIDES for this parameter, all the faces of the prim will animate.

Unfortunately, it isn’t possible to animate some but not all of the faces – it’s either 1 face or all faces.

A couple of final notes. You’ll notice that the Repeat and Flip options for textures don’t have any effect on animated textures. Rotate, however, does.

That will do for now. In the next article, I’ll take a look at the traditional animated texture, which uses a sequence of frames like an animated movie.

Transparently Obvious

Monday, June 8th, 2009

Montague: Carruthers, look at this. Observe it closely.

Carruthers: There appears to be nothing there, Montague.

Montague: So it would appear, my dear Carruthers, but appearances can be deceptive…

I briefly looked at transparency in the third of my Texture tutorials, but it’s a subject which deserves a more in-depth look, because in spite of the title of this blog entry, there are aspects of transparency in SL which are far from obvious.

There are two ways to apply transparency to a prim (or to one face of a prim). The simplest is to use the Transparency setting on the Texture tab, the second is apply a texture which has transparency.

Let’s start with the Transparency setting, which is the simpler way. Select a prim, or a prim face, and set the Transparency to something other than 0. The prim will become partially transparent.

In theory, you can set the transparency to 100%, but you will find that SL will set it back to 90% if you do (it is possible to have 100% transparency using a script, but it is easier to use a transparent texture).

If you have applied the transparency to an entire prim, the result will probably be what you expect. Suppose however, you apply transparency to just one side of a cube — the result might not be what you expect:

Simple transparency

Simple transparency

This is because SL does not draw the inside of prims, even when you make one side of the prim transparent. If you are creating windows for a building, you will find that this can cause you some difficulties, but that’s a subject for another blog entry.

Applying transparency to an entire prim, or the entire side of a prim, can be useful, but not very flexible. It’s much more useful to be able to have a texture which contains a mixture of non-transparent and transparent (or maybe semi-transparent) sections.

To do this needs a special texture, and also means that I need to introduce you to…

…The Fiendish Alpha-Plane!

Carruthers: Great heavens, Montague, the evil Count Nefarious has escaped again!

Montague: On the contrary, Carruthers, he has merely boarded the fiendish Alpha Plane, which has the property of rendering everything within it utterly invisible.

Carruthers: Astonishing, Montague!

Montague: Transparently obvious, my dear Carruthers.

Yes, well, let us leave Montague and Carruthers in pursuit of the villainous Count, and turn our attention to the afore-mentioned Alpha-Plane.

If you want to avoid the painful technical details, all you need to know is that the alpha-plane applies levels of transparency to individual pixels in a texture. You can now skip the next section. If want to know more details, read on.

Geek Stuff

If you already understand all about alpha transparency (why are you reading this article?), I’m aware that what I’m about to say is somewhat simplified!

Every computer-generated image consists of a set of pixels. Think of them as a mass of dots in an electronic version of Pointillism. Each individual pixel has  a numeric value that determines how much red, how much green, and how much blue should be applied to the paint mixture for that particular dot.

The value for every pixel, then, can be broken down into three separate numbers, for Red, Green, and Blue.

The so-called Alpha-Plane adds a fourth value. The fourth value represents the amount of transparency for the pixel, in other words, the amount by which anything ‘behind’ the pixel will be visible (what happens is that the colours of the pixels ‘behind’ the texture are blended to a greater or lesser extent with the red, green, and blue values of the texture pixel).

A value of 0.0 means that the pixel is completely opaque, and nothing behind it can be seen. A value of 1.0 means that it is completely transparent (and effectively invisible).

Using the Alpha Plane

The alpha-plane allows you to have different levels of transparency in one texture, ranging from completely transparent to completely opaque. To create a transparent texture needs the help of a graphics package, of course. I can’t go into detail on this, because I am only familiar with a small number of graphics packages, and this does not include the ubiquitous Photoshop. Every program tends to handle transparency differently, but you should be able to find plenty of tutorials for your package of choice.

Personally, I use the Gimp, which is both free and powerful. Transparency is relatively straight-forward, though there are multiple ways to do it. Make sure that the image you are working on has an Alpha channel (in Gimp 2.4 you can create an Alpha channel from the Layer | Transparency | Add Alpha Channel menu option). Alternatively, you can create a new layer or image and specify it as transparent. Once your image or layer has an alpha-channel you can create a transparent section by selecting an area and then using the Edit | Clear menu option. You can also use the Layer | Transparency | Color To Alpha menu option, which applies graduated transparency to pixels of a selected colour — this can be very useful for creating windows — select the area that should be glass, and use this option to make it partially transparent.

Here are a couple of examples:

Transparent Window, Example 1

Transparent Window, Example 1

Transparent Window, Example 2

Transparent Window, Example 2

Unfortunately, having created your transparent texture, and applied it to your Second Life build, you might find that you have another problem to deal with, namely…

…the Dreaded Z-Order Bug

Carruthers: Great heavens, Montague! The beast appeared out of nowhere, and my bullets have no effect — the horrid thing does not seem to be where it appears to be.

Montague: Precisely, Carruthers. It is the dreaded Zorder Bug, which cannot be slain — one must simply hope to evade it.

Construct two flat prims, and apply a texture with transparency to both of them. For best effect, make them 3m or 4m tall and wide. Place them at right-angles to one another (as if they were the corner of a wall). Now walk round them.

You will probably notice that at certain positions the prims display incorrectly, seemingly interpenetrating one-another.

The problem is most pronounced when you have two transparent objects which are one in front of the other or, worse, interpenetrating each other, as in this example:

Z-Order Bug Example

Z-Order Bug Example

These days, a lot of hair textures use partially transparent textures, and you might have noticed the very odd effect which happens when someone with one these hairstyles walks in front of a transparent window.

This is known as the Z-Order bug (a reference to the way in which the computer renders the prims onto the display). It is not a bug in Second Life itself, but is rather a bug in the OpenGL system which Second Life uses for the 3D display. Simplistically, the graphics system cannot work out which prim should be displayed in front of another when they both have transparency.

(You won’t generally won’t come across this effect in 3D games which use OpenGL, because the level-designers are usually careful to avoid situations where the bug would show itself. In Second Life, however, you are the designer!)

If you have two adjoining prims which display this bug, one fix (assuming that you have to have both prims with a transparent texture) is to insert a prim in between them with a non-transparent texture. For example, if you have a wall corner, try putting a non-transparent column at the intersection. This sometimes cures the problem.

Having two transparent prims, one in directly in front of the other, however, is not fixable like this. The only thing you can do is to try to avoid this situation.

And Finally

If you want complete transparency, Linden supply a transparent texture, which you will find in the Textures section of the library in your inventory. It’s worth using this rather than creating your own, because it is more likely to be in viewers’ cache, for quicker loading.

Of course, completely transparent objects can be a bit difficult to work with, and easy to lose! Fortunately, there is a menu option which can help: View | Highlight Transparent — this gives all transparent objects a garish red glow, making them easy to spot.