Laser Sheet OSL

Just to put everything in the same place, here’s the OSL shader I created to simulate the Laser Sheet. Find the nodes and usability here.

/* * DESCRIPTION:

  • Simulates the emmission of a laser sheet with origin in point (laserx, lasery, laserz)
  • and with a normal (norx, nory, norz)
  • The output variable, laserout, defines the strength of the laser, which should be
  • connected to an emission shader, which is then added to the base material of the object.
  • The input parameters Thickness and Intensity allow the ajustment of the laser sheet.
  • High Intensity values might increase specle points
  • AUTHOR: written by Renato Sousa,
  •     http://renatogsousa.weebly.com/
    
  •     email: renatogsousa AT gmail DOT com
    
  •     last modified 27 December 2012
    

*/

#include “stdosl.h”

shader pattern (
float Thickness = 0.1,
float Intensity=1,
float laserx=0.0,
float lasery=0.0,
float laserz=0.0,
float norx=0,
float nory=0,
float norz=1,
output float laserout=0)
{
point Pos = P;
int light=0;

/* ***** plane definition ***** */
vector lasernormal=normalize(vector(norx,nory,norz));
float plane=lasernormal[0]*(laserx-Pos[0])+lasernormal[1]*(lasery-Pos[1])+lasernormal[2]*(laserz-Pos[2]);

/* ***** light direction search: from point P to laser origin ***** */

vector laserrelativepos=vector(laserx-Pos[0],lasery-Pos[1],laserz-Pos[2]);

/* ***** limit the search distance to the distance between object and laser ***** */
float maxdist=length(laserrelativepos);
laserrelativepos=normalize(laserrelativepos);

/* ***** trace if there is any object between point P and laser origin ***** */
int shadow=trace(Pos, laserrelativepos,"maxdist",maxdist);
   
light=(1-shadow);

/* **** laser light is maximum in the plane, limited by Intensity **** */
laserout=abs(Thickness / (plane))*light;
laserout=min(laserout,Intensity);

}

Very nice!

Hi Renato, can I use your code in my project?


Free hosting

Hi zaza13, sure, feel free to use it and modify it as you need.