Difference between revisions of "Category:LSL Light"

From Second Life Wiki
Jump to navigation Jump to search
(Adding a second script that's configurable.)
m (updated limits to same as PRIM_POINT_LIGHT and added intra-wiki links)
Line 2: Line 2:
== Properties of light ==
== Properties of light ==


The quality of light cast by an object is determined by five parameters found on the "Features" page of the Edit dialog, which can also be set by script commands. The controls appear in the dialog in the same order as used in the script commands (see example below).
The quality of a [[PRIM_POINT_LIGHT]] cast by an object is determined by five parameters found on the [[Building_Tools#Features_Tab|features tab]] of the [[Building_Tools#Edit_Tool|edit tool]], which can also be set by script commands. The controls appear in the dialog in the same order as used in the script commands (see example below).


The first is a simple '''on/off switch''': either the object is a light source (checkbox activated or TRUE) or it isn't. The light's '''colour''' is set by a colour picker (dialog) or as an RGB vector (script) as usual. The '''intensity''' of light is a measurement of how strong in absolute terms the light is. This is a floating-point number ranging from 0 to 1, where 1 is fully on and 0 is equivalent to "off."
The first is a simple '''on/off switch''': either the object is a [[PRIM_POINT_LIGHT]] source (checkbox activated or [[TRUE]]) or it isn't. The light's '''color''' is set by a color picker (dialog) or as an RGB vector (script) as usual. The '''intensity''' of light is a measurement of how strong in absolute terms the light is. This is a floating-point number ranging from 0.0 to 1.0, where 1.0 is fully on and 0.0 is equivalent to "off."


The two remaining settings are trickier, because their effects are quite subtle and they do interact with each other. '''Radius''' is the distance that light will travel from the centre of the object before it blends into and becomes indistinguishable from the scene's natural ambient lighting. This is a floating-point number measured in metres. '''Falloff''' is the extent to which light "decays" as it travels away from the object. This is a floating-point number ranging from 0 to 2, where 2 is an abrupt falling-off of intensity and 0 is relatively little change over distance.  
The two remaining settings are trickier, because their effects are quite subtle and they do interact with each other. '''Radius''' is the distance that light will travel from the centre of the object before it blends into and becomes indistinguishable from the scene's natural ambient lighting. This is a floating-point number measured in metres. '''Falloff''' is the extent to which light "decays" as it travels away from the object. This is a floating-point number ranging from 0.01 to 2.0, where 2.0 is an abrupt falling-off of intensity and 0.01 is relatively little change over distance.  


To illustrate how these settings work, imagine—or better still: build—a hollow grey cube 8 by 8 by 8 metres on the inside, with a light source hovering in the middle of one end-wall, and yourself standing below the light source looking at the opposite wall. (Hint: if you do actually build this, turn the sun off while you are testing; you may also need to close the curtains and extinguish all lights in the real-life room you're working in.)
To illustrate how these settings work, imagine—or better still: build—a hollow grey cube 8 by 8 by 8 metres on the inside, with a light source hovering in the middle of one end-wall, and yourself standing below the light source looking at the opposite wall. (Hint: if you do actually build this, turn the sun off while you are testing; you may also need to close the curtains and extinguish all lights in the real-life room you're working in.)


While the radius is less than 4 metres (i.e. under halfway to the opposite wall), it remains fairly dark. Turning the falloff up to 2 (maximum decay) makes the room somewhat darker.
While the '''radius''' is less than 4 metres (i.e. under halfway to the opposite wall), it remains fairly dark. Turning the falloff up to 2.0 (maximum decay) makes the room somewhat darker.


As the radius approaches 8 metres (the distance to the wall), the room is only slightly brighter; at maximum falloff, the room is about as dark as it was when the radius was 4 metres and falloff was 0.
As the '''radius''' approaches 8 metres (the distance to the wall), the room is only slightly brighter; at maximum '''falloff''', the room is about as dark as it was when the '''radius''' was 4 metres and '''falloff''' was 0.01.


Only after the radius is greater than the distance to the opposite wall does it become significantly brighter. The effect of falloff is greater: when it is zero, direct illumination begins to make concentric circles on the wall, centred on the point where it intersects the light's axis; at maximum the room is again as dark as it was when the radius was only 4 metres.
Only after the '''radius''' is greater than the distance to the opposite wall does it become significantly brighter. The effect of '''falloff''' is greater: when it is 0.01, direct illumination begins to make concentric circles on the wall, centred on the point where it intersects the light's axis; at the maximum of 2.0 the room is again as dark as it was when the '''radius''' was only 4 metres.


== Controlling light sources ==
== Controlling light sources ==


Light in SL is determined by the OpenGL standard which allows for eight lights.  
Light in Second Life is determined by the OpenGL standard which allows for eight sources. Traditionally and practically, two sources are reserved for the Sun and Moon, leaving six for incidental lighting.  All eight are really generated on the client-side video card, so different video card models may show the same scene slightly differently.  If more than six [[PRIM_POINT_LIGHT]] sources are present in a scene, only the light from the closest six will show in the environment.
Traditionally and practically, two sources are reserved for the Sun and Moon, leaving six
for incidental lighting.  All eight are really generated on the client-side video card, so  
different video card models may show the same scene slightly differently.  If more than six  
user light sources are present in a scene, only the light from the closest six will show in the environment.


An example - How to generate, switch and change light from LSL:
An example - How to generate, switch and change light from LSL:


<lsl>
<lsl>
// simple light source demonstrator
integer isLightTurnedOn;
// 8feb07 "tetsumo kuri"
   
// thanks to squee janitor for line to dissect
 
integer light_s = TRUE;     // "_s" for status
 
default
default
{
{
    state_entry()
    {
      //  llSetText("click me",<1,0,0.6>,.5);  // in case you like labels
    }
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
        if ( light_s )
//      toggle isLightTurnedOn between TRUE and FALSE
         {
         isLightTurnedOn = !isLightTurnedOn;
            light_s = FALSE;
 
        if (isLightTurnedOn)
            // fullbright doesn't have anything to do with light in NEW(2006?) lighting model
        {
            // setting fullbright does look good though
             llSetPrimitiveParams([
             llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE]);
                PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
             
                PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 1.0, 10.0, 0.6]);
            llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE,   // if this is false, light is off,
         }
                                    <0.0,1.0,0.0>,1.0, 10.0, 0.5]); // rest of params don't matter
         }          
         else
         else
         {
         {
             light_s = TRUE;
             vector COLOR_ORANGE  = <1.000, 0.522, 0.106>;
            //llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,TRUE]);  //leave fullbright commented for now
            llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,
             llSetPrimitiveParams([
                                    <1.0,0.7,1.0>,  // light color vector range: 0.0-1.0 *3
                PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
                                    1.0,            // intensity    (0.0-1.0)
                PRIM_POINT_LIGHT, TRUE, COLOR_ORANGE, 1.0, 10.0, 0.6]);
                                    10.0,          // radius      (.1-10.0)
                                    0.6 ]);         // falloff      (.01-1.0)
               
             // this could have been done in one line, like this   
            //llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE,PRIM_POINT_LIGHT,TRUE,<1.0,1.0,0.5>,20,1.0,0.5]);
            //      ... but thats kinda hard to take in...     
         }
         }
        //llSay(0, " Click!");
     }
     }
}
}
</lsl>
</lsl>


The following example shows how to create a configurable light that turns itself on and off when touched.  The light's properties can be edited by changing the values defined at the top of the script.  This script illustrates the lighting attributes PRIM_POINT_LIGHT, PRIM_FULLBRIGHT and PRIM_GLOW.
The following example shows how to create a configurable light that turns itself on and off when touched.  The light's properties can be edited by changing the values defined at the top of the script.  This script illustrates the lighting attributes [[PRIM_POINT_LIGHT]], [[PRIM_FULLBRIGHT]] and [[PRIM_GLOW]].


<lsl>
<lsl>
Line 78: Line 56:
// Lighting is configurable.
// Lighting is configurable.


integer light_s = TRUE;
integer light_s   = TRUE;
vector lightcolor = <1.0, 0.75, 0.5>;
vector lightcolor = <1.0, 0.75, 0.5>;
float intensity = 1.0; // 0-1
float   intensity = 1.0;             // 0.0 <= intensity <= 1.0
float radius = 10.0;   // 0-10
float   radius     = 10.0;           // 0.1 <= radius <= 20.0
float falloff = 0.0;   // 0-1
float   falloff   = 0.01;           // 0.01 <= falloff <= 2.0
float glow = 1.0;
float   glow       = 0.05;


switchit()
toggle()
{
{
     float thisglow = 0.0;
     float thisglow = 0.0;
     light_s = !light_s;
     light_s = !light_s;
     if (light_s)
     if (light_s)
    {
         thisglow = glow;
         thisglow = glow;
    }
 
     llSetPrimitiveParams([
     llSetPrimitiveParams([
         PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,
         PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,
         PRIM_FULLBRIGHT, ALL_SIDES, light_s,
         PRIM_FULLBRIGHT, ALL_SIDES, light_s,
         PRIM_GLOW, ALL_SIDES, thisglow
         PRIM_GLOW,       ALL_SIDES, thisglow
     ]);
     ]);
       llSetColor(lightcolor, ALL_SIDES);
       llSetColor(lightcolor, ALL_SIDES);
Line 105: Line 83:
     state_entry()
     state_entry()
     {
     {
      llSetText("Touch for light",<0,0,0>,1);
        llSetText("Touch for light", <1.0, 1.0, 1.0>, 1.0);
      switchit();
        toggle();
     }
     }
   
   
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         switchit();
         toggle();
     }
     }
}
}
</lsl>
</lsl>

Revision as of 12:51, 8 January 2014

Properties of light

The quality of a PRIM_POINT_LIGHT cast by an object is determined by five parameters found on the features tab of the edit tool, which can also be set by script commands. The controls appear in the dialog in the same order as used in the script commands (see example below).

The first is a simple on/off switch: either the object is a PRIM_POINT_LIGHT source (checkbox activated or TRUE) or it isn't. The light's color is set by a color picker (dialog) or as an RGB vector (script) as usual. The intensity of light is a measurement of how strong in absolute terms the light is. This is a floating-point number ranging from 0.0 to 1.0, where 1.0 is fully on and 0.0 is equivalent to "off."

The two remaining settings are trickier, because their effects are quite subtle and they do interact with each other. Radius is the distance that light will travel from the centre of the object before it blends into and becomes indistinguishable from the scene's natural ambient lighting. This is a floating-point number measured in metres. Falloff is the extent to which light "decays" as it travels away from the object. This is a floating-point number ranging from 0.01 to 2.0, where 2.0 is an abrupt falling-off of intensity and 0.01 is relatively little change over distance.

To illustrate how these settings work, imagine—or better still: build—a hollow grey cube 8 by 8 by 8 metres on the inside, with a light source hovering in the middle of one end-wall, and yourself standing below the light source looking at the opposite wall. (Hint: if you do actually build this, turn the sun off while you are testing; you may also need to close the curtains and extinguish all lights in the real-life room you're working in.)

While the radius is less than 4 metres (i.e. under halfway to the opposite wall), it remains fairly dark. Turning the falloff up to 2.0 (maximum decay) makes the room somewhat darker.

As the radius approaches 8 metres (the distance to the wall), the room is only slightly brighter; at maximum falloff, the room is about as dark as it was when the radius was 4 metres and falloff was 0.01.

Only after the radius is greater than the distance to the opposite wall does it become significantly brighter. The effect of falloff is greater: when it is 0.01, direct illumination begins to make concentric circles on the wall, centred on the point where it intersects the light's axis; at the maximum of 2.0 the room is again as dark as it was when the radius was only 4 metres.

Controlling light sources

Light in Second Life is determined by the OpenGL standard which allows for eight sources. Traditionally and practically, two sources are reserved for the Sun and Moon, leaving six for incidental lighting. All eight are really generated on the client-side video card, so different video card models may show the same scene slightly differently. If more than six PRIM_POINT_LIGHT sources are present in a scene, only the light from the closest six will show in the environment.

An example - How to generate, switch and change light from LSL:

<lsl> integer isLightTurnedOn;

default {

   touch_start(integer total_number)
   {

// toggle isLightTurnedOn between TRUE and FALSE

       isLightTurnedOn = !isLightTurnedOn;

       if (isLightTurnedOn)
       {
           llSetPrimitiveParams([
               PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
               PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 1.0, 10.0, 0.6]);
       }
       else
       {
           vector COLOR_ORANGE  = <1.000, 0.522, 0.106>;

           llSetPrimitiveParams([
               PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
               PRIM_POINT_LIGHT, TRUE, COLOR_ORANGE, 1.0, 10.0, 0.6]);
       }
   }

} </lsl>

The following example shows how to create a configurable light that turns itself on and off when touched. The light's properties can be edited by changing the values defined at the top of the script. This script illustrates the lighting attributes PRIM_POINT_LIGHT, PRIM_FULLBRIGHT and PRIM_GLOW.

<lsl> // Touch the object to light it up. // Lighting is configurable.

integer light_s = TRUE; vector lightcolor = <1.0, 0.75, 0.5>; float intensity = 1.0; // 0.0 <= intensity <= 1.0 float radius = 10.0; // 0.1 <= radius <= 20.0 float falloff = 0.01; // 0.01 <= falloff <= 2.0 float glow = 0.05;

toggle() {

   float thisglow = 0.0;
   light_s = !light_s;
   if (light_s)
       thisglow = glow;
   llSetPrimitiveParams([
       PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,
       PRIM_FULLBRIGHT, ALL_SIDES, light_s,
       PRIM_GLOW,       ALL_SIDES, thisglow
   ]);
     llSetColor(lightcolor, ALL_SIDES);

}

default {

   state_entry()
   {
       llSetText("Touch for light", <1.0, 1.0, 1.0>, 1.0);
       toggle();
   }

   touch_start(integer total_number)
   {
       toggle();
   }

} </lsl>