Jump to content
DJLoom

Automatic Light, Glow

Recommended Posts

Simple and easy to use light and glow scripts. They turn on when the sun goes down and turn off when it comes up. Scripts look for sun position every 150 seconds, Can easly be changed.

 

Light Script

float   sun_height;
vector  sun_position;
default
{
       state_entry() {
      llSetTimerEvent(150);
   }
   timer() {
        sun_position = llGetSunDirection();
        sun_height = sun_position.z;
        
        if(sun_height < 0.0)
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,<1.0, 1.0, 1.0>,1.0,15,0.750]);
        }
        else
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT,FALSE,<1.0, 1.0, 1.0>,1.0,15,0.750]);
        }
    }
}

 Glow Script

float   sun_height;
vector  sun_position;
default
{
       state_entry() {
      llSetTimerEvent(150);
   }
   timer() {
        sun_position = llGetSunDirection();
        sun_height = sun_position.z;
        
        if(sun_height < 0.0)
        {
            llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.4]);
        }
        else
        {
            llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.0]);
        }
    }
}

 Simple and easy :)

 

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites


Morrdecai wrote:

Can the output light color be set or is it forced white?

In the line...

llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,<1.0, 1.0, 1.0>,1.0,15,0.750]);

The vector <1.0, 1.0, 1.0> is the color in <R, G, B> form which is white in that example. Change the vector, change the color!

  • Like 1

Share this post


Link to post
Share on other sites

Why not combining both scripts if this is needed for a street lamp or something? :smileyhappy:

float   sun_height;vector  sun_position;default{       state_entry() {      llSetTimerEvent(150);   }   timer() {        sun_position = llGetSunDirection();        sun_height = sun_position.z;                if(sun_height < 0.0)        {            llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,<1.0, 1.0, 1.0>,1.0,15,0.750, PRIM_GLOW, ALL_SIDES, 0.4]);        }        else        {            llSetPrimitiveParams([PRIM_POINT_LIGHT,FALSE,<1.0, 1.0, 1.0>,1.0,15,0.750, PRIM_GLOW, ALL_SIDES, 0.0]);        }    }}

 Or add a random timer to it to simulate a broken flourecent light...:smileysurprised:

float glow;float time;//-------------------------------------// Main programdefault{    state_entry()    {  llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);        state begin;    }}//-------------------------------------// Begin statestate begin    {        state_entry()        {        glow = (integer) llRound(llFrand(1)); // Random on or off        time = (float) llFrand(2); // Random wait time            llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 1.0>, glow, 5.0, 0.5, PRIM_GLOW, ALL_SIDES, glow]); // Set prim light on/of            state wait; // Go to the Wait State        }    }//-------------------------------------// Wait statestate wait    {        state_entry()        {            llSetTimerEvent(time); //Wait        }        timer()        {           llSetTimerEvent(0.0); //remove the timer           state begin; // Go back to the Begin State        }    }

 Have fun!

 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 28.09.2012 at 11:13 PM, Oddball Otoole said:

Why not combining both scripts if this is needed for a street lamp or something? :smileyhappy:


float   sun_height;vector  sun_position;default{       state_entry() {      llSetTimerEvent(150);   }   timer() {        sun_position = llGetSunDirection();        sun_height = sun_position.z;                if(sun_height < 0.0)        {            llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,<1.0, 1.0, 1.0>,1.0,15,0.750, PRIM_GLOW, ALL_SIDES, 0.4]);        }        else        {            llSetPrimitiveParams([PRIM_POINT_LIGHT,FALSE,<1.0, 1.0, 1.0>,1.0,15,0.750, PRIM_GLOW, ALL_SIDES, 0.0]);        }    }}

 Or add a random timer to it to simulate a broken flourecent light...:smileysurprised:


float glow;float time;//-------------------------------------// Main programdefault{    state_entry()    {  llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);        state begin;    }}//-------------------------------------// Begin statestate begin    {        state_entry()        {        glow = (integer) llRound(llFrand(1)); // Random on or off        time = (float) llFrand(2); // Random wait time            llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 1.0>, glow, 5.0, 0.5, PRIM_GLOW, ALL_SIDES, glow]); // Set prim light on/of            state wait; // Go to the Wait State        }    }//-------------------------------------// Wait statestate wait    {        state_entry()        {            llSetTimerEvent(time); //Wait        }        timer()        {           llSetTimerEvent(0.0); //remove the timer           state begin; // Go back to the Begin State        }    }

 Have fun!

 

Hello! How to make the second script react on sun too?

Share this post


Link to post
Share on other sites
39 minutes ago, Sunbleached said:

Hello! How to make the second script react on sun too?

Duplicate post.  Original is at

Please do not post the same question in two places. That makes it difficult for others to see what people have already suggested.  Besides, this question does not belong in the script Library.

Edited by Rolig Loon

Share this post


Link to post
Share on other sites
18 minutes ago, Rolig Loon said:

Duplicate post.  Original is at

Please do not post the same question in two places. That makes it difficult for others to see what people have already suggested.  Besides, this question does not belong in the script Library.

 

Edited by Sunbleached
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks for sharing this, question what would I need to add to make it when the glow comes on to cycle or pulse colors at various speeds as well. ? I love the idea of it changing based on time of day or night.

Share this post


Link to post
Share on other sites

I tried the approach of turning lights on and off on the basis of the sun's Z position but had poor results, so I created a prim and had it report the sun position every 10 seconds:

default
{
    state_entry()
    {
        llSetTimerEvent(10.0);
    }

    timer()
    {
        vector sun = llGetSunDirection();
        llSetText("Sun X = " + (string)sun.x + "\nSun Y = " + (string)sun.y + "\nSun Z = " + (string)sun.z, <1.0,1.0,0.0>, 1.0);
    }
}

What I found is that one "evening" the Sun was still casting shadows when Z was -0.47; the next "morning" the sun resumed casting shadows when it was at Z = -0.87, so the method of using Z < 0 for night seems like it won't work reliably?

Some math makes more sense of this, maybe. Z = -.87 and Z = -.47 are when the sun is 60 and 28 degrees below the horizon, respectively. This means the sun was "up" for a total of 60+28+180, or 268 degrees. Probably if I had measured more carefully that would be 270 degrees, or exactly 3/4 of a circle. This makes sense because the sun is "up" for three hours out of four. For some reason there's a 15 degree offset included in this.

 

 

Edited by QuietWren

Share this post


Link to post
Share on other sites

Just as in RL, you can still see sunlight in the sky when the sun is below your horizon.  We never see a sharp, instantaneous change from sunlight to total darkness.  It's that way by design.

The Z component of llGetSunDirection is the sine of the sun's angle above the horizon.  I have found experimentally that the period of dawn (or dusk) occurs when  Z is within 0.2 > Z > -0.2, or roughly 12 degrees above or below the horizon.

BTW, a ten second timer is WAY too fast.  The sun does not change its position enough to be perceptible in ten seconds.  Try at least a minute.

Share this post


Link to post
Share on other sites

See my simultaneous edited comment above :) I think this is more about LL's geometry than a horizon effect...and I was using shadows, not twilight.

I agree, for any meaningful purpose 10s was far too short, but this was just an ad hoc thing to pin down sunrise/sunset times.

Edited by QuietWren

Share this post


Link to post
Share on other sites
7 minutes ago, QuietWren said:

I think this is more about LL's geometry than a horizon effect...and I was using shadows, not twilight.

It amounts to the same thing, in the end. SL is actually a 2D virtual world, not a sphere, so any virtual process that simulates behavior in our 3D world is at best an approximation, and has some unusual side effects.  Shadows, for example.  Also, don't forget that SL also has a simulated moon, which also casts light (and shadows).  In the first version of the SL wiki there was some pseudo-erudite discussion about how daylight behaves in SL.  It's all gone now, but from what I recall the bottom line is that Corey and others in the early days were not trying to do things scientifically. Our daylight/nighttime system was a seat of the pants approximation -- enough to fool the natives but not real astronomers.

Share this post


Link to post
Share on other sites

I wish they would bring that discussion back!  But to return to the original topic of turning lights on and off--

The black box that is SL day simulation suggests that (without the 15 degree offset) a Z test value of -.71 would give you actual daylight, and maybe use something more negative to capture twilight. I wonder if that 15 degrees offset is a universal constant, or it varies from place to place, or from day to day?

And don't start me on the way they do the moon and stars! :)

Edited by QuietWren

Share this post


Link to post
Share on other sites
15 minutes ago, QuietWren said:

I wonder if that 15 degrees offset is a universal constant, or it varies from place to place, or from day to day?

As far as I know, there are no latitude effects in SL, so the sun behaves the same way everywhere.  Of course, it has always been true that people can ignore the real sun but tweaking their personal settings.  Now, especially with EEP, more and more landowners are creating local effects that override the standard.  All bets are off.

18 minutes ago, QuietWren said:

And don't start me on the way they do the moon and stars! :)

I promise.  No.

Share this post


Link to post
Share on other sites

llGetSunDirection is, I think, reporting the EEP sun direction while your viewer is rendering the Windlight settings, and I don't think these are necessarily the same. It may be worth taking a look using the EEP project viewer.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...