Difference between revisions of "PRIM POINT LIGHT"

From Second Life Wiki
Jump to navigation Jump to search
m
(Update page to add definition between sRGB colour and Linear colour.)
 
(24 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{#if:
<onlyinclude>{{#if:
{{LSL_ConstHijack}}
{{#vardefine:light_const|{{LSL Const|PRIM_POINT_LIGHT|integer|23|c=Used to {{GetSet|{{{1|}}}|get|set|/}} the prim's point light configuration}}}}
{{{{#var:hijack}}LSL_Constants/PrimitiveParams}}
{{#vardefine:p_radius_desc|ranges from 0.1 to 20.0}}
{{#vardefine:p_falloff_desc|ranges from 0.01 to 2.0}}
{{#vardefine:p_intensity_desc|ranges from 0.0 to 1.0}}
}}</onlyinclude>{{#if:
{{LSL_Function/boolean|boolean}}
{{LSL_Function/linear_color|linear_color}}
}}{{LSL Constant
}}{{LSL Constant
|inject-2={{LSL PrimitiveParam Categorize|Prim}}
|name=PRIM_POINT_LIGHT
|name=PRIM_POINT_LIGHT
|type=integer
|type=integer
|value=23
|value=23
|desc=PRIM_POINT_LIGHT is used to configure the light status of the object
|desc=PRIM_POINT_LIGHT is used to configure the point light configuration of the prim
|pa_front=[&#32;
|pa={{LSL Constant/List|i_front=[&#32;{{#var:light_const}},&#32;|i_end=&nbsp;]
|pa_mid=,&#32;
|text=When used with [[llSetPrimitiveParams]] & [[llSetLinkPrimitiveParams]] & [[llSetLinkPrimitiveParamsFast]]
|pa_end=&nbsp;]
|toc=llSetPrimitiveParams
|pa_text=When used with [[llSetPrimitiveParams]] & [[llSetLinkPrimitiveParams]]
|i1_type=integer|i1_subtype=boolean|i1_name=boolean
|pa1_type=integer|pa1_name=boolean
|i2_type=vector|i2_name=linear_color
|pa2_type=vector|pa2_name=color
|i3_type=float|i3_name=intensity
|pa3_type=float|pa3_name=intensity
|i4_type=float|i4_name=radius
|pa4_type=float|pa4_name=radius
|i5_type=float|i5_name=falloff}}
|pa5_type=float|pa5_name=falloff  
|pb={{LSL Constant/List|i_front=[[llGetPrimitiveParams]]([&nbsp;{{#var:light_const}}|i_end=&nbsp;]);|
|pb_front=[&#32;
|r_front=Returns the list [&nbsp;|r_end=&nbsp;]
|pb_end=&nbsp;]
|text
|pb_text=When used with [[llGetPrimitiveParams]]
|toc=llGetPrimitiveParams
|r1_type=integer|r1_subtype=boolean|r1_name=boolean
|r2_type=vector|r2_name=linear_color
|r3_type=float|r3_name=intensity
|r4_type=float|r4_name=radius
|r5_type=float|r5_name=falloff
}}
|caveats=
* Viewers that do not have advanced lighting enabled can only render 6 lights at a time and projectors will be rendered as omnidirectional light sources. (OpenGL limitations allow for 8 light sources, SL appears to reserve one each for the Sun and Moon.)
** Viewers that '''do''' have advanced lighting enabled can render as many lights as their graphics card allows; it is not hard-limited by the viewer.
* Lights with a high intensity have a wash-out effect when overlapping. Keep this in mind when using multiple lights. '''''Never''' create an abundance of lights to get around the 6 light maximum in basic lighting'', as viewers with advanced lighting will be washed out and may suffer from client lag.
* Unlike most color in LSL, which expects a gamma-encoded value (sRGB), this expects a non-gamma-encoded value (linear RGB). This means that the value you set as the light color is not the same value you'd pass to make the source (e.g. filament ) glow the same color. You may wish to implement an [[llsRGB2Linear|sRGB Electro-Optical Transfer Function (EOTF)]] to bypass this.
|examples=
|examples=
<pre>
Set the prim's color and the color of the light it emits to the same color:-
// simple light source demonstrator
<syntaxhighlight lang="lsl2">
// 8feb07 "tetsumo kuri"
integer switch;
// thanks to squee janitor for line to dissect


integer light_s = TRUE;     // "_s" for status
vector gLampCol = <255,190,121>; //Light colour in regular (0-255) sRGB space. This will be converted to LSL later.


default
default
Line 31: Line 47:
     state_entry()
     state_entry()
     {
     {
      //  llSetText("click me",<1,0,0.6>,.5); // in case you like labels
        gLampCol /= 255; //Convert to LSL colour.
     }
     }


     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         if ( light_s )
         switch = !switch; //toggle the switch
        {
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
             light_s = FALSE;
            PRIM_POINT_LIGHT,switch,llsRGB2Linear(gLampCol),1,20,0, //Convert colour to linear RGB as PRIM_POINT_LIGHT requires, using llsRGB2Linear
            PRIM_COLOR,ALL_SIDES,gLampCol,1,
            PRIM_GLOW,ALL_SIDES,switch,
             PRIM_FULLBRIGHT,ALL_SIDES,switch]);
    }
}
</syntaxhighlight>


            // fullbright doesn't have anything to do with light in NEW(2006?) lighting model
Basic light script:-
            // setting fullbright does look good though
<syntaxhighlight lang="lsl2">
             llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE]);
integer isLightTurnedOn;
             
 
            llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE,   // if this is false, light is off,
default
                                    <0.0,1.0,0.0>,1.0, 10.0, 0.5]); // rest of params don't matter
{
         }          
    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
         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!");
     }
     }
}
}
</pre>
</syntaxhighlight>
|constants=
 
{{LSL ConstRow|CHANGED_SHAPE}}
A compact version of the above:-
<syntaxhighlight lang="lsl2">
integer switch;
default
{
    touch_start(integer total_number)
    {
        llSetPrimitiveParams(
        [      PRIM_FULLBRIGHT, ALL_SIDES, switch = !switch,
                PRIM_POINT_LIGHT, switch, <1, 0.5, 0.1> *  switch, 1, 10, 0.6 ] );     
    }
}
</syntaxhighlight>
|constants
|functions=
|functions=
{{LSL DefineRow||[[llSetPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParams]]|}}
{{LSL DefineRow||[[llSetLinkPrimitiveParamsFast]]|}}
{{LSL DefineRow||[[llGetPrimitiveParams]]|}}
{{LSL DefineRow||[[llGetPrimitiveParams]]|}}
|events=
{{LSL DefineRow||[[llGetLinkPrimitiveParams]]|}}
{{LSL DefineRow||[[changed]]|}}
{{LSL DefineRow||[[llsRGB2Linear]]|}}
|events
|location
|location
|cat1=Light
|cat1=Light

Latest revision as of 07:47, 30 June 2022

Description

Constant: integer PRIM_POINT_LIGHT = 23;

The integer constant PRIM_POINT_LIGHT has the value 23

PRIM_POINT_LIGHT is used to configure the point light configuration of the prim

llSetPrimitiveParams

[ PRIM_POINT_LIGHT, integer boolean, vector linear_color, float intensity, float radius, float falloff ]
• integer boolean TRUE enables, FALSE disables
• vector linear_color linear color in RGB <R, G, B> (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
• float intensity ranges from 0.0 to 1.0
• float radius ranges from 0.1 to 20.0
• float falloff ranges from 0.01 to 2.0

When used with llSetPrimitiveParams & llSetLinkPrimitiveParams & llSetLinkPrimitiveParamsFast

llGetPrimitiveParams

llGetPrimitiveParams([ PRIM_POINT_LIGHT ]);

Returns the list [ integer boolean, vector linear_color, float intensity, float radius, float falloff ]

• integer boolean TRUE enables, FALSE disables
• vector linear_color linear color in RGB <R, G, B> (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
• float intensity ranges from 0.0 to 1.0
• float radius ranges from 0.1 to 20.0
• float falloff ranges from 0.01 to 2.0

Caveats

  • Viewers that do not have advanced lighting enabled can only render 6 lights at a time and projectors will be rendered as omnidirectional light sources. (OpenGL limitations allow for 8 light sources, SL appears to reserve one each for the Sun and Moon.)
    • Viewers that do have advanced lighting enabled can render as many lights as their graphics card allows; it is not hard-limited by the viewer.
  • Lights with a high intensity have a wash-out effect when overlapping. Keep this in mind when using multiple lights. Never create an abundance of lights to get around the 6 light maximum in basic lighting, as viewers with advanced lighting will be washed out and may suffer from client lag.
  • Unlike most color in LSL, which expects a gamma-encoded value (sRGB), this expects a non-gamma-encoded value (linear RGB). This means that the value you set as the light color is not the same value you'd pass to make the source (e.g. filament ) glow the same color. You may wish to implement an sRGB Electro-Optical Transfer Function (EOTF) to bypass this.
All Issues ~ Search JIRA for related Bugs

Examples

Set the prim's color and the color of the light it emits to the same color:-

integer switch;

vector gLampCol = <255,190,121>; //Light colour in regular (0-255) sRGB space. This will be converted to LSL later.

default
{
    state_entry()
    {
        gLampCol /= 255; //Convert to LSL colour.
    }

    touch_start(integer total_number)
    {
        switch = !switch; //toggle the switch
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_POINT_LIGHT,switch,llsRGB2Linear(gLampCol),1,20,0, //Convert colour to linear RGB as PRIM_POINT_LIGHT requires, using llsRGB2Linear
            PRIM_COLOR,ALL_SIDES,gLampCol,1,
            PRIM_GLOW,ALL_SIDES,switch,
            PRIM_FULLBRIGHT,ALL_SIDES,switch]);
    }
}

Basic light script:-

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]);
        }
    }
}

A compact version of the above:-

integer switch;
default
{
    touch_start(integer total_number)
    {
        llSetPrimitiveParams(
        [       PRIM_FULLBRIGHT, ALL_SIDES, switch = !switch,
                PRIM_POINT_LIGHT, switch, <1, 0.5, 0.1> *  switch, 1, 10, 0.6 ] );      
    }
}

Deep Notes

Search JIRA for related Issues

Signature

integer PRIM_POINT_LIGHT = 23;