Feedback

Please leave feedback and comments. I am always interested to hear how people get on using these LScripts!

Monday 4 February 2013

LScript - Channel_VolumeTrick

LScript (Layout) to shift channel values based on motion position during motion blur used to fake volume effects.

Compatible with Newtek LightWave 9.6 and above.

// LScript Channel Filter - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/* 
    LScript Channel Filter - Volume Trick

    Channel_VolumeTrick.ls

*/

@version 2.2
@warnings
@script channel
@name *Volume Trick

    // Title
    sTitle = "*Volume Trick";

    // Version
    sVersion = "v1.1";

    // Variable
    nMin = 0.0;
    nMax = 1.0;

create: channel
{
    setdesc(sTitle);

    // Info
    info("*Volume Trick - Motion blur must be enabled.");
}

destroy
{
    // take care of final clean-up activities here
}

process: ca, frame, time
{
    nValue = ca.get(time);

    if(Camera().blurLength(time) <> 0.0)
      {
      // Map Range
      n01 = maprange01(frame * (1 / Scene().fps),(frame + 1) * (1 / Scene().fps),time);
      nValue = linear1D(nValue + nMin,nValue + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
      }

    // ca    
    ca.set(nValue);
}

// INTERPOLATION

linear1D: n1,n2,i // i = interpolation point (0-1)
{
    return(n1 * (1 - i) + n2 * i);     
}

// MAP RANGE

maprange01: n1,n2,i

{    
    if(n2-n1 == 0.0){return(0.0);}
  else
    {return((1/(n2-n1)) * (i-n1));}
}

load: what,io
{
    if(what == SCENEMODE)   // processing an ASCII scene file
    {
        if(io.read().asStr() == sTitle + " " + sVersion)
            {
            nMin = io.read().asNum(); // Min
            nMax = io.read().asNum(); // Max
            }
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {
        // Header
        io.writeln(sTitle + " " + sVersion);
        io.writeln(nMin); // Min
        io.writeln(nMax); // Max
    }
}


options
{
    if(reqisopen())
        {
        reqend();
        return;
        }

    reqbegin(sTitle + " " + sVersion);

    ctrl_c0 = ctlnumber("Min",nMin);   
    ctrl_c1 = ctlnumber("Max",nMax);   

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    // Refresh
    ctlrefresh(ctrl_c0,"refresh_c0"); // Min
    ctlrefresh(ctrl_c1,"refresh_c1"); // Max

    reqopen();
}

refresh_c0:value // Min
{
    nMin = value;
}

refresh_c1:value // Max
{
    nMax = value;
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

No comments:

Post a Comment