Personal tools

Views

Colored Spotlight

From Adobe Labs

/*****************************************************************************

*
* Author: Andy Zupko 
* http://blog.zupko.info
* 
* Write me if you use this for anything cool!
*
*****************************************************************************/

kernel Spotlight {

   parameter float radius 
   <       
       minValue:float(0.1);
       maxValue:float(2000.0); 
       defaultValue:float(200.0);
   >;
   
    parameter float intensity
   <       
       minValue:float(0.1);
       maxValue:float(4.0); 
       defaultValue:float(2.0);
   >;
   
   parameter float lightSize
    <       
       minValue:float(0.1);
       maxValue:float(100.0); 
       defaultValue:float(4.0);
   >;
   parameter float2 center
   <
       minValue:float2(0.0, 0.0);
       maxValue:float2(2048.0, 2048.0);
       defaultValue:float2(256.0, 256.0);
   >;
   parameter float4 colors
   <
       minValue:float4(0.1, 0.1, 0.1, 0.1);
       maxValue:float4(2.1, 2.1, 2.1, 2.1);
       defaultValue:float4(1.0, 1.0, 1.0, 1.0);
   >;
   void evaluatePixel(image4 oImage, out float4 outputColor)
   {
       float2 relativePos = outCoord()-center;
       //get distance from center   
       float distFromCenter = length( relativePos );
       
       //get the "shade percent"
       float per = (distFromCenter < lightSize) ? intensity : intensity-((distFromCenter-lightSize)/radius);
      
       float4 shade = float4(per*colors.r, per*colors.g, per*colors.b, 1.0);
       
       //return new shaded pixel
       outputColor = shade*sampleNearest(oImage, outCoord());
       
   }

}

Retrieved from "http://labs.adobe.com/wiki/index.php/Colored_Spotlight"