Feedback

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

Monday, 4 March 2013

LScript - Image_DepthDesaturation


LScript (Layout) desaturates the image based on depth buffer.

Compatible with Newtek LightWave 9.6 and above.

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

/* 
    LScript Image Filter - Depth Desaturate

    Image_DepthDesaturate.ls

*/

@version 2.5
@warnings
@script image
@name *Depth Desaturate

    // Title
    sTitle = "*Depth Desaturate";

    // Version
    sVersion = "v1.0";

    nAmount = 1.0;  
    nMin = 1.0;
    nMax = 10.0;

    // Control
    ctrl_c0;  

create
{
    setdesc(sTitle);
}

process: ifo
{
    iProgress = ifo.height;
    if(runningUnder() != SCREAMERNET) moninit(iProgress);
    for(i = 1;i <= ifo.height;++i)
      {
      for(j = 1;j <= ifo.width;++j)
        {
        nAverage = (ifo.red[j,i] + ifo.green[j,i] + ifo.blue[j,i]) * 0.3333333333;
        nDepth = clip(0.0,1.0,maprange01(nMin,nMax,ifo.depth[j,i]));        
        ifo.red[j,i] = ifo.red[j,i] - (nAmount * nDepth) * (ifo.red[j,i] - nAverage);
        ifo.green[j,i] = ifo.green[j,i] - (nAmount * nDepth) * (ifo.green[j,i] - nAverage);
        ifo.blue[j,i] = ifo.blue[j,i] - (nAmount * nDepth) * (ifo.blue[j,i] - nAverage);
        }
      if(runningUnder() != SCREAMERNET) if(monstep()) return;
      }
}

// CLIP

clip: min,max,n
{
    if(n < min) n = min;
    if(n > max) n = max;
    return(n);
}

// 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)
    {
        nAmount = io.read().asNum();
        nMin = io.read().asNum();
        nMax = io.read().asNum();
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {
        io.writeln(nAmount);         
        io.writeln(nMin);         
        io.writeln(nMax);         
    }
}


options
{
    reqbegin(sTitle + " " + sVersion);

    // Control
    ctrl_c0 = ctlpercent("Amount",nAmount);
    ctrl_c1 = ctlnumber("Min (m)",nMin);
    ctrl_c2 = ctlnumber("Max (m)",nMax);

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

    // Refresh
    ctlrefresh(ctrl_c0,"refresh_c0"); // Amount

    return if !reqpost();

    nAmount = clip(0.0,1.0,getvalue(ctrl_c0));
    nMin = getvalue(ctrl_c1);
    nMax = getvalue(ctrl_c2);

    reqend();
}

refresh_c0:value // Amount
{
    nAmount = clip(0.0,1.0,value);
    setvalue(ctrl_c0,nAmount);
}


All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

No comments:

Post a comment