Feedback

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

Thursday, 19 December 2013

LScript - Image_TV


LScript (Layout) applies a crt television effect.

Changes
  • Added presets

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 - TV

    Image_TV.ls

*/

@version 2.5
@warnings
@script image
@name *TV

    // Title
    sTitle = "*TV";

    // Version
    sVersion = "v1.0";

    nApertureGrilleOpactiy = 0.05;
    nScanlineDistortion = 1;
    nScanlineOpacity = 0.1;
    nScanlineNoise = 0.05;
    nScanlineScale = 0.025;
    nScanlineSpeed = -0.5;
    nScanlineThickness = 2;
    nStaticOpacity = 0.05;

    // Control
    ctrl_c0,ctrl_c1,ctrl_c2,ctrl_c3,ctrl_c4,ctrl_c5,ctrl_c6,ctrl_c7,ctrl_c8; 

create
{
    setdesc(sTitle);
}

process: ifo
{
    _Thickness = 1 / nScanlineThickness;
    _ApertureColor = 1;

    nTime = Scene().currenttime;
    for(i = 1;i <= ifo.height;++i)
    {
    if(mod(ceil(i * _Thickness),2) == 0){_Scanline = nScanlineOpacity + (randu() * nScanlineNoise);}else{_Scanline = - nScanlineOpacity;}
    _Scanline += abs(sin(nTime + (i * nScanlineScale) * nScanlineSpeed) * nScanlineOpacity);
    _Distortion = sin(nTime + (i * nScanlineScale) * nScanlineSpeed) * nScanlineDistortion * randu();
                
      for(j = 1;j <= ifo.width;++j)
        {

        if(nScanlineDistortion <> 0) // Distortion
          {
          u = clip(1,ifo.width,round(j + _Distortion,0));
          v = clip(1,ifo.height,i + 1);
          ifo.red[j,i] = ifo.red[u,v];
          ifo.green[j,i] = ifo.green[u,v];
          ifo.blue[j,i] = ifo.blue[u,v];
          }

        if(nStaticOpacity > 0.0) // Static
          {
          _Static = randu() * nStaticOpacity; 
          ifo.red[j,i] = ifo.red[j,i] + _Static;
          ifo.green[j,i] = ifo.green[j,i] + _Static;
          ifo.blue[j,i] = ifo.blue[j,i] + _Static;
          }

        if(nApertureGrilleOpactiy > 0.0) // Aperture Grille
          {
          if(j == 1){_ApertureColor = 1;}
          if(_ApertureColor > 3){_ApertureColor = 1;}
          if(_ApertureColor == 1) // Red
            {
            ifo.red[j,i] = ifo.red[j,i] + nApertureGrilleOpactiy;
            ifo.green[j,i] = ifo.green[j,i] - nApertureGrilleOpactiy;
            ifo.blue[j,i] = ifo.blue[j,i] - nApertureGrilleOpactiy;
            }
          if(_ApertureColor == 2) // Green
            {
            ifo.red[j,i] = ifo.red[j,i] - nApertureGrilleOpactiy;
            ifo.green[j,i] = ifo.green[j,i] + nApertureGrilleOpactiy;
            ifo.blue[j,i] = ifo.blue[j,i] - nApertureGrilleOpactiy;
            }

          if(_ApertureColor == 3) // Blue
            {
            ifo.red[j,i] = ifo.red[j,i] - nApertureGrilleOpactiy;
            ifo.green[j,i] = ifo.green[j,i] - nApertureGrilleOpactiy;
            ifo.green[j,i] = ifo.green[j,i] + nApertureGrilleOpactiy;
            }
          ++_ApertureColor;
          }

        ifo.red[j,i] = clip(0.0,1.0,ifo.red[j,i] + _Scanline);
        ifo.green[j,i] = clip(0.0,1.0,ifo.green[j,i] + _Scanline);
        ifo.blue[j,i] = clip(0.0,1.0,ifo.blue[j,i] + _Scanline);
        }
    }
}

// CLIP

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

load: what,io
{
    if(what == SCENEMODE)
    {
        if(io.read().asStr() == sTitle + " " + sVersion)
            {
            nApertureGrilleOpacity = io.read().asNum(); // Aperture Grille Opacity
            nScanlineDistortion = io.read().asInt(); // Scanline Distortion
            nScanlineOpacity = io.read().asNum(); // Scanline Opacity
            nScanlineNoise = io.read().asNum(); // Scanline Noise           
            nScanlineScale = io.read().asNum(); // Scanline Scale           
            nScanlineSpeed = io.read().asNum(); // Scanline Speed           
            nScanlineThickness = io.read().asInt(); // Scanline Thickness
            nStaticOpacity = io.read().asNum(); // Static Opacity
            }
    }
}

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

        io.writeln(nApertureGrilleOpacity); // Aperture Grille Opacity
        io.writeln(nScanlineDistortion); // Scanline Distortion
        io.writeln(nScanlineOpacity); // Scanline Opacity
        io.writeln(nScanlineNoise); // Scanline Noise
        io.writeln(nScanlineScale); // Scanline Scale
        io.writeln(nScanlineSpeed); // Scanline Speed
        io.writeln(nScanlineThickness); // Scanline Thickness
        io.writeln(nStaticOpacity); // Static Opacity
    }
}

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

    // Control
    ctrl_c0 = ctlpopup("Preset",1, @"CRT",
                                    "Aperture Grille",
                                    "Scanlines",
                                    "Bad Signal",
                                    "Distortion"@);
    ctlsep();
    ctrl_c1 = ctlnumber("Aperture Grille Opacity",nApertureGrilleOpactiy);
    ctlsep();
    ctrl_c2 = ctlinteger("Scanline Distortion",nScanlineDistortion);
    ctrl_c3 = ctlnumber("Opacity",nScanlineOpacity);
    ctrl_c4 = ctlnumber("Noise",nScanlineNoise);
    ctrl_c5 = ctlnumber("Scale",nScanlineScale);
    ctrl_c6 = ctlnumber("Speed",nScanlineSpeed);
    ctrl_c7 = ctlinteger("Thickness",nScanlineThickness);
    ctlsep();
    ctrl_c8 = ctlnumber("Static",nStaticOpacity);

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

    // Refresh
    ctlrefresh(ctrl_c0,"refresh_preset"); // Preset

    return if !reqpost();

    nApertureGrilleOpactiy = getvalue(ctrl_c1); // Aperture Grille Opacity
    nScanlineDistortion = getvalue(ctrl_c2); // Scanline Distortion
    nScanlineOpacity = getvalue(ctrl_c3); // Scanline Opacity
    nScanlineNoise = getvalue(ctrl_c4); // Scanline Noise
    nScanlineScale = getvalue(ctrl_c5); // Scanline Scale
    nScanlineSpeed = getvalue(ctrl_c6); // Scanline Speed
    nScanlineThickness = getvalue(ctrl_c7); // Scanline Thickness
    nStaticOpacity = getvalue(ctrl_c8); // Static Opacity

    reqend();
}

refresh_preset:value
{
    if(value == 1) // CRT
      {
      setvalue(ctrl_c1,0.05); // Aperture Grille Opacity
      setvalue(ctrl_c2,1); // Scanline Distortion
      setvalue(ctrl_c3,0.1); // Scanline Opacity
      setvalue(ctrl_c4,0.05); // Scanline Noise
      setvalue(ctrl_c5,0.025); // Scanline Scale
      setvalue(ctrl_c6,-0.5); // Scanline Speed
      setvalue(ctrl_c7,2); // Scanline Thickness
      setvalue(ctrl_c8,0.05); // Static Opacity
      }

    if(value == 2) // Aperture Grille
      {
      setvalue(ctrl_c1,0.2); // Aperture Grille Opacity
      setvalue(ctrl_c2,0); // Scanline Distortion
      setvalue(ctrl_c3,0.0); // Scanline Opacity
      setvalue(ctrl_c4,0.0); // Scanline Noise
      setvalue(ctrl_c5,0.025); // Scanline Scale
      setvalue(ctrl_c6,-0.5); // Scanline Speed
      setvalue(ctrl_c7,1); // Scanline Thickness
      setvalue(ctrl_c8,0.0); // Static Opacity
      }

    if(value == 3) // Scanlines
      {
      setvalue(ctrl_c1,0.0); // Aperture Grille Opacity
      setvalue(ctrl_c2,0); // Scanline Distortion
      setvalue(ctrl_c3,0.1); // Scanline Opacity
      setvalue(ctrl_c4,0.0); // Scanline Noise
      setvalue(ctrl_c5,0.025); // Scanline Scale
      setvalue(ctrl_c6,-0.5); // Scanline Speed
      setvalue(ctrl_c7,2); // Scanline Thickness
      setvalue(ctrl_c8,0.0); // Static Opacity
      }

    if(value == 4) // Bad Signal
      {
      setvalue(ctrl_c1,0.1); // Aperture Grille Opacity
      setvalue(ctrl_c2,4); // Scanline Distortion
      setvalue(ctrl_c3,0.2); // Scanline Opacity
      setvalue(ctrl_c4,0.1); // Scanline Noise
      setvalue(ctrl_c5,0.025); // Scanline Scale
      setvalue(ctrl_c6,-0.5); // Scanline Speed
      setvalue(ctrl_c7,2); // Scanline Thickness
      setvalue(ctrl_c8,0.2); // Static Opacity
      }

    if(value == 5) // Distortion
      {
      setvalue(ctrl_c1,0.0); // Aperture Grille Opacity
      setvalue(ctrl_c2,10); // Scanline Distortion
      setvalue(ctrl_c3,0.01); // Scanline Opacity
      setvalue(ctrl_c4,0.2); // Scanline Noise
      setvalue(ctrl_c5,0.1); // Scanline Scale
      setvalue(ctrl_c6,-0.5); // Scanline Speed
      setvalue(ctrl_c7,2); // Scanline Thickness
      setvalue(ctrl_c8,0.1); // Static Opacity
      }
}


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

No comments:

Post a comment