LENS EFFECTS INCLUDE FILE for Persistence of Vision 3.x

Created by Chris Colefax, 18 July 1997
Updated 9 August 1998: updated for POV-Ray 3.1, added spots_contract_to_centre option, fixed Domain Error caused by some compilers


INSTALLATION

QUICK START

CAMERA OPTIONS

LENS EFFECTS OPTIONS

LENS EFFECTS ANIMATION OPTIONS

DESIGNING YOUR OWN LENS EFFECTS

TROUBLESHOOTING

COPYRIGHT AND LEGAL INFORMATION

CONTACTING THE AUTHOR


INSTALLATION
The Lens Effects Include File actually consists of two files, LnsEfcts.inc and Lens.inc, which should both be copied to one of the directories (folders) in your POV-Ray library path. Normally this is the INCLUDE sub-directory of the directory where you installed POV-Ray, so if you installed POV-Ray in C:\POVRAY you should copy the files to C:\POVRAY\INCLUDE. On a Windows 95 system, this is probably something like:

C:\Program Files\POV-Ray for Windows\Include

On UNIX and similar systems, where filenames are case-sensitive, you may have to rename the include files so the filenames are all capitals. This will enable you to render the sample files without modification.


QUICK START
The Lens Effects Include File allows you to add a whole range of different lens effects (including lens flares, glows, sparkles, etc.) to any POV-Ray scene. To add a simple lens flare to a scene, add the following lines to your POV file:

#declare camera_location = < 6, 20, -30> ;
#declare camera_look_at = < 0, 3, 3> ;
#declare effect_location = < -3, 4, 3> ;
#include "Lens.inc"

changing the values shown above to match the camera in your scene (the effect_location specifies the location of the light_source or object that you want to add a lens effect to). When you render the scene, you should now see the default "Rainbow" lens effect added to it. In addition to this one lens effect, you can choose from 18 other predefined lens effects, or create your own completely custom effects. You can also use a range of options to fine-tune the lens effect to suit your scene. To use any of these options just add the following line to your scene file, before including Lens.inc:

#declare [variable-name] = [value]

substituting the desired variable name and value where appropriate. Note that Lens.inc (or LnsEfcts.inc) should never be included at the start of a scene (like colors.inc or textures.inc). They should only be included after declaring the desired lens effect and camera options. To create more than one lens effect in a scene, you should declare the first set of options and include Lens.inc. Then declare the next set of options and include Lens.inc again, but note that you don't have to redeclare the camera options, or any other options that remain the same for both lens effects, eg. if you were creating two "Sparkle" effects in different locations, you would only have to redeclare the effect_location the second time, rather than all the other options.

Note that the Lens Effects Include File supports both British and American English, eg: effect_colour and effect_color are interchangeable, as are spots_to_centre and spots_to_center, etc.


CAMERA OPTIONS
To add a lens effect to your scene, you must properly declare the camera options (which should always match those found in the camera {} statement). Depending on the camera options you have used, you will have to declare some or all of the following options:

camera_location, camera_look_at, camera_sky camera_direction, camera_angle

Correctly declaring these options will ensure that the lens effects are created properly. Note that if you transform (ie. rotate, translate) the camera, you should do the same to the variables, eg. if you had:

camera {location -z * 10 look_at y * 2
rotate x * 45
translate < -5, 10, 2>
rotate y * clock * 360}

you should perform the same operations on the camera_location and camera_look_at options, eg:

#declare camera_location = -z * 10;
#declare camera_location = vrotate(camera_location, x * 45);
#declare camera_location = camera_location + < -5, 10, 2> ;
#declare camera_location = vrotate(camera_location, y * clock * 360);

#declare camera_look_at = -z * 10;
#declare camera_look_at = vrotate(camera_look_at, x * 45);
#declare camera_look_at = camera_look_at + < -5, 10, 2> ;
#declare camera_look_at = vrotate(camera_look_at, y * clock * 360);

Note that the Lens Effects Include File will always create the camera for you, using the values you specify for the above options (so there is actually no need to have a separate camera {} statement in the POV file).


LENS EFFECTS OPTIONS
This section explains the different effects that can be created using Lens.inc, and the options you can use to fine-tune a lens effect.

effect_type


Use this option to choose a different lens effect from the default "Rainbow" lens flare. To use a different effect type, just add the line (before including Lens.inc):

#declare effect_type = "Sun"

substituting the name of the desired effect. The available effect types are Camera, Camera2, Candle, Diamond, Headlight, Headlight2, Rainbow, Rainbow2, SoftGlow, Sparkle, Sparkle2, Spotlight, Spotlight2, Star, Star2, Sun, Sun2, Sun3, and Undersea. You can see a sample of all of these effect types by rendering the LE_SAMP*.POV scenes. In addition, there is the Random lens effect. Note that this option is case-insensitive, ie. effect_type = "HEADLIGHT" is the same as effect_type = "headlight".

effect_location


This option specifies the location of the object that you want to add the lens effect to. With light_sources this should be the same as the location vector in the light_source {} statement, and with other objects it is usually the centre of the object. Note that if you use rotate and translate to move the light_source or object, you should follow the directions above to do the same to the effect_location option.

effect_colour


Use this option to change the overall colour of the lens effect. You can use predefined colours (eg. #declare effect_colour = Red) or colour vectors (eg. #declare effect_colour = < 1.3, .3, .2>). When using vectors, note that the components are relative to each other, so you can use decimal percentages, integer percentages, or other values, eg. < 1, .2, .2> is the same as < 100, 20, 20> or < 5, 1, 1>. Also, this option will affect different lens effects in different ways, eg. using:

#declare effect_colour = < 1, .5, .5>

will make a yellowish effect like "Sun3" become orange, while a bluish effect like "Spotlight2" will become purple.

source_colour


Normally all the lens effects have a white centre. You can use this option to change this to a different colour. Unlike the effect_colour option, the vector components of this option are not relative. This means that you can use larger numbers to create a brighter centre, eg:

#declare source_colour = < 2, 2, 1>

will give a much brighter yellow centre than:

#declare source_colour = < 1, 1, .2>

effect_scale


Use this option to change the size of the lens effect. You can use a single number, or a vector, eg:

#declare effect_scale = 2

will make the lens effect twice as large, while:

#declare effect_scale = < .3, .1, 1>

will make the lens effect 30% as wide and 10% as high (the z-component is not used).

effect_rotate


Use this option to rotate the lens effect around its own centre (the effect location will not change). You can also use the effect_spin option to change the rotation during an animation.

effect_brightness


All the various lens effects are generally designed to look best on a dark background. Therefore, if your scene does not have a dark background the lens effect may not be visible enough. You can use this option to increase (or decrease) the brightness of the lens effect for a particular scene. Good values range from 1 (the default) to 2 (for an effect twice as bright). Any number can be used, and you can even use negative numbers to create a black hole type of effect.

effect_intensity


Use this option to make the lens effect more (or less) visible. Setting this option to 0 will make the lens effect disappear, while numbers less than 1 will make the lens effect fainter than usual. Numbers larger than one will make the lens effect less transparent, and therefore more visible (without increasing the brightness of the effect). You can also use negative numbers, which have the strange effect of making the lens effect invisible except when there are other objects behind it.

effect_always_on_top


Normally the lens effects always appear on top of all the other objects in the scene. You can set this option to false to make the lens effect disappear behind other objects that are in front of it. This makes the lens effect an actual object in the scene, and so it will be reflected by other mirrored objects, and it will be affected by fogs, media, refraction, etc. This can also be used to make the lens effect compatible with certain camera options (eg. focal blurring, orthographic projection), which may not otherwise work properly with the Lens Effects Include File.


LENS EFFECTS ANIMATION OPTIONS
This section lists the various options that can be used to animate the lens effects in a scene.

effect_shrink


Use this option to make the lens effect decrease in size as the effect_location moves further from the camera. Note that you will generally have to increase the effect_scale to quite a large number, depending on the size of the object you are adding the glow to (eg. if you want to add a glow to a sphere with a radius of 1, you will probably need to use an effect_scale of 6 or larger).

effect_falloff


Normally the lens effect is brightest when it is located at the centre of the screen/image. As the lens effect moves away from the image centre it begins to fade, until at some point it disappears altogether. You can use this option to set the angle at which the lens effect disappears. It is similar to the falloff option of a spotlight, eg. if you imagine the camera as a cone (with its tip at the camera_location, and its base centred on the camera_look_at point), this option specifies the angle made by the centre line of the cone and its sides. The lens effect disappears when it moves beyond the sides of the cone. The default value is 60 degrees, but you can use any number between 0 and 90 degrees.

effect_falloff_power


Use this option to change the rate at which the lens effect fades as it moves away from the centre of the image. The default is 1, which gives a linear falloff (eg. when the lens effect is halfway between the image centre and the angle specified by the effect_falloff option, it is created at half the normal intensity). Numbers larger than 1 will the make the falloff rate slower (ie. the effect only begins to fade closer to the effect_falloff angle), while numbers less than 1 will make the lens effect fade quicker as it moves away from the image centre.

effect_spin


Use this option to automatically change the effect_rotate value as the POV-Ray clock changes. The number used specifies the number of rotations per clock unit, eg. #declare effect_spin = 3 will make the lens effect spin 3 times between clock = 0 and clock = 1. Positive numbers specify an anti-clockwise rotation, while negative numbers specify a clockwise rotation.

effect_jitter


Use this option to randomly move the lens effect by a certain amount for each frame of the animation. Setting this option to 0 will make the lens effect stationary; setting this option to 1 will move the lens effect by up to 10% of the image width in any direction. You can use any number to increase or decrease the amount of jittering, and you can use a vector to move the effect more in one direction than another (the x-component controls the horizontal movement, the y-component controls the vertical movement).

effect_flicker


Use this option to randomly alter the size, brightness, and intensity of the lens effect for each frame of the animation. Setting this option to 0 specifies a constant lens effect, while setting this option to 1 will flicker the lens effect by up to 100% of it's normal size, brightness, and intensity. You can use numbers smaller than 1 to reduce the flicker, or larger numbers to increase the amount of flickering.

rays_flicker


Most lens effects include some sort of rays, which start at the centre of the lens effect and move outwards. Setting this option to true will randomly change the direction and size of these rays for each frame of the animation, adding to the flickering effect of certain lens effects (this is especially useful with the Candle and Sun effect types).

spots_contract_to_centre


This option controls the behaviour of the lens effect spots as they approach (and reach) the centre of the image. If this option is false (the default), the spots expand and contract as they near the centre of the image, while always keeping around the same number of spots visible. This usually looks best for still scenes, but when rendered in an animation the lens effect may not behave quite the way you want, especially if it reaches the direct centre of the image (where the angle of the spots will probably be incorrect). You can set this option to true to make the spots fully contract when they reach the centre of the image (so all spots are located at the same place), avoiding any problems in animations.

effect_anim_seed


The effect_jitter and effect_flicker options can be used to add a certain amount of randomness to the lens effect. You can use this option to change the random number seed used to calculate this randomness (the default is 0).


DESIGNING YOUR OWN LENS EFFECTS
In addition to using the many predefined lens effects included with Lens.inc (as well as using all of the above options to fine-tune these predefined effects) it is possible to use the Lens Effects Include File to create your own custom lens effects. This section details the various methods you can use to do this.


UNDERSTANDING THE LENS EFFECTS INCLUDE FILE
Before starting to create a custom lens effect, you should understand (at least partly) how the Lens Effects Include File works. The Lens Effects Include File actually consists of two files, Lens.inc and LnsEfcts.inc; LnsEfcts.inc contains the POV code to actually create the lens effects, while Lens.inc simply declares the necessary options needed to create the various predefined lens effects. LnsEfcts.inc is based on a component system; each lens effect is made up of a number of different features.

These features are:

LnsEfcts.inc includes 8 different glow types, 8 different ray types, 8 different streak types, and 8 different spot types. This gives a total of more than 5800 different combinations when using at least 1 of each type. In addition, each component includes a separate set of options that can be used to alter the characteristics of that individual component (the various options in the previous section alter every component that makes up a particular lens effect). Finally, you can create custom effect files that use any of POV-Ray's extensive texturing features, to create completely original lens effects that can be used on their own or combined with any of the existing lens effects components.


LENS EFFECTS COMPONENT OPTIONS
This section details the various component options that can be used when creating a custom lens effect. To create a custom effect, you simply declare all the following options that you want to use, and then include LnsEfcts.inc, eg:

#declare glow_type = 3;
#declare rays_type = 2;
#declare rays_intensity = 2;
#declare streak_type = 3;
#declare streak_seed = 1232;
#include "LnsEfcts.inc"

Any options you don't declare will be assigned default values.


GLOW OPTIONS
glow_type: a number between 1 and 8 that specifies which glow type to use (render the Glows.pov scene to see all the different glow types). Using 0 or another number outside of the 1 to 8 range will create a lens effect without a glow

glow_colour: changes the colour of the glow. See the explanation of source_colour to understand how this option works.

glow_scale: changes the size of the glow, relative to effect_scale

glow_rotate: rotates the glow, relative to effect_rotate

glow_intensity: changes the intensity of the glow, relative to effect_intensity


RAY OPTIONS
rays_type: a number between 1 and 8 that specifies which rays type to use (render the Rays.pov scene to see all the different ray types). Using 0 or another number outside of the 1 to 8 range will create a lens effect without any rays

rays_colour: changes the colour of the rays. See the explanation of source_colour to understand how this option works.

rays_scale: changes the size of the rays, relative to effect_scale

rays_rotate: rotates the rays, relative to effect_rotate

rays_intensity: changes the intensity of the rays, relative to effect_intensity

rays_seed: changes the random seed used to create the rays (default is 0)

rays_frequency: changes the number of rays created (numbers larger than 1 will create more rays, numbers less than 1 will create fewer rays)


STREAK OPTIONS
streak_type: a number between 1 and 8 that specifies which streak type to use (render the Streaks.pov scene to see all the different streak types). Using 0 or another number outside of the 1 to 8 range will create a lens effect without any streaks

streak_colour: changes the colour of the streaks. See the explanation of source_colour to understand how this option works.

streak_scale: changes the size of the streaks, relative to effect_scale

streak_rotate: rotates the streaks, relative to effect_rotate

streak_intensity: changes the intensity of the streaks, relative to effect_intensity

streak_seed: changes the random seed used to create the streaks (default is 0)

streak_to_centre: if true, the streaks will always rotate so they pass through the centre of the image.


SPOT OPTIONS
spots_type: a number between 1 and 8 that specifies which spot type to use (render the Spots.pov scene to see all the different spot types). Using 0 or another number outside of the 1 to 8 range will create a lens effect without any spots

spots_colour: changes the colour of the spots. See the explanation of source_colour to understand how this option works.

spots_scale: changes the size of the spots, relative to effect_scale

spots_rotate: rotates the spots, relative to effect_rotate

spots_intensity: changes the intensity of the spots, relative to effect_intensity

spots_seed: changes the random seed used to create the spots (default is 0)

spots_frequency: changes the number of spots created (numbers larger than 1 will create more spots, numbers less than 1 will create fewer spots)

spots_spacing: changes the space between the spots (numbers larger than 1 will increase the space between each spot, numbers less than 1 will bring the spots closer together)

spots_to_centre: if true, the spots will always rotate so that they pass through the centre of the image. If false, the spots will be horizontal (although you can use spots_rotate to change this).


USING THE RANDOM EFFECT TYPE
To get an indication of how the various lens effects component options work you can use the "Random" effect type, eg:

#declare effect_seed = 12398;
#declare effect_type = "Random"
#include "Lens.inc"

The Lens Effects Include File will assign random values to the various component options listed in the previous section, depending on the random seed specified by the effect_seed option. Each different number you use will create a new and different lens effect (but using the same number again will allow you to reproduce a particular effect). You can use any number allowed by POV-Ray, which means that you can create literally millions of random lens effects without even having to use any of the component options. For more information, see the Rand.ini file (which will allow you to automatically render as many different lens effects as you want).


MODIFYING A PREDEFINED LENS EFFECT
Sometimes you may find that you want to use a predefined lens effect, but wish to alter only certain features of that effect type. Also, you may discover a particular Random effect that you like, but want to know the options that were used to create that effect. There are two ways of doing this:

options_only


Setting this option to true before including Lens.inc will not actually create any lens effect - it will simply set the necessary options for that effect. You can then change any of the desired component options, and include LnsEfcts.inc to create the altered lens effect. For example, you may want to use the "Spotlight" effect_type, but use 6 streaks instead of 4, and add some spots:

#declare effect_type = "Spotlight"
#declare options_only = true; #include "Lens.inc"

#declare streak_type = 6;
#declare spots_type = 7;
#include "LnsEfcts.inc"

Or, you may have found a random effect type you like, but want to change the effect_colour and glow features, eg:

#declare effect_type = "Random" #declare effect_seed = -8732;
#declare options_only = true; #include "Lens.inc"

#declare effect_colour = < 10, 5, 2> ;
#declare glow_type = 6; #declare glow_scale = < 1.5, 1, 1> ;
#include "LnsEfcts.inc"

The options_only variable can also be useful when you want to create multiple copies of the same effect type; that way you only include Lens.inc once at the beginning of the file, and then declare LnsEfcts.inc each time you want to create a lens effect (this is faster than including Lens.inc multiple times), eg:

#declare effect_type = "Sparkle"
#declare options_only = true; #include "Lens.inc"

#declare effect_location = < -5, 10, -2> ; #include "LnsEfcts.inc"
#declare effect_location = < 15, 1, -5> ; #include "LnsEfcts.inc"
#declare effect_location = < 0, -10, 3> ; #include "LnsEfcts.inc"

debug_options


Setting this option to true will cause the Lens Effects Include File to print a copy of all the lens effects component options to POV-Ray's debug stream. You can then use the +GD command-line switch, or the Debug_File INI file setting, to direct the debug stream to a file. This file can then be altered as desired, and included directly into your scene before including LnsEfcts.inc. This is especially useful when you want to know the exact options used to create a particular Random effect (see the Rand.pov and Rand.ini files for an example of how this option can be used).


USING CUSTOM EFFECT FILES
If you find that none of the existing lens effects components (or their options) are able to give you the exact effect you want, you may wish to consider creating a custom effect file. This will let you use any and all of POV-Ray's texturing commands/patterns to create all sorts of different effects. The three custom effect files included with the Lens Effects Include File (Fireball.lfx, Spiral.lfx, and Custom.lfx) show just a few of the possibilities. Using a custom effect file is as simple as declaring the custom_effect_file option with the name of the file you want to use, eg:

#declare custom_effect_file = "Fireball.lfx"

You can then use this file alone, or combine it with other existing lens effects components, before including LnsEfcts.inc (see the CustLFX.pov file for some examples of this). You can also use multiple custom effect files by including LnsEfcts.inc multiple times, eg:

#declare custom_effect_file = "MyEffect1.lfx"
#include "LnsEfcts.inc"

#declare custom_effect_file = "MyEffect2.lfx"
#include "LnsEfcts.inc"

For instructions on how to actually create your own custom effect file see the Custom.lfx file (which you can copy and alter to create your own files).


TROUBLESHOOTING
This section contains some common problems you might encounter while using the Lens Effects Include File, and instructions on how to fix these problems.


TROUBLESHOOTING OPTIONS
The Lens Effects Include File uses layers of semi-transparent discs to create the various features of the lens effects. If effect_always_on_top is true, these discs are scaled very small and moved very close to the camera. If you are using larger numbers (ie. in the millions or larger) to position the camera and/or effect_location, the default numbers used when positioning the layers of discs may not work. Some symptoms of this include invisible lens effects, and opaque lens effects. If you encounter these problems, try using the following options.

lens_scale


Use this to increase the size of the imaginary lens used when creating the lens effects. If this number is too small relative to the camera_location the lens effects will become completely invisible. Try increasing this to 100, or further if this does not solve the problem.

layer_separation


Use this option to increase the distance between each layer of discs used to create the lens effects. If this number is too small relative to the camera_location the lens effect may become opaque, or you may get a strange speckled effect. Try increasing this number to 10, or further if this does not solve the problem.


TROUBLESHOOTING FAQ

Q) I added a lens effect to my scene but I can't see it?
A: There are various reasons why the lens effect may not be visible. First check that you have properly declared the camera options and effect_location according to the instructions above (especially if you have transformed the camera or effect_location). The effect may be invisible because it is outside of the camera's view, or because it is beyond the effect_falloff distance. Check for any lens effects warnings and make sure the effect_location is in view of the camera. Try increasing the effect_scale and effect_intensity to see if this makes the lens effect visible. Try increasing the lens_scale and/or layer_separation options. Finally, make sure you have included Lens.inc or LnsEfcts.inc after declaring all the correct options (any options declared after including the files will have no effect).


Q) I added a lens effect to my scene, and now I see black areas in the lens effect and/or on mirrors and glass in my scene?
A: You need to increase the max_trace_level, using the following line:

global_settings {max_trace_level 30}

Add this line after including Lens.inc or LnsEfcts.inc, and increase the number until the black areas disappear.


Q) I changed my camera {} statement, but the camera didn't move?
A: You must also make sure that you change the camera options, as described above.


Q) Some parts of the lens effects overlap others, and I can't see through them?
A: Try increasing the lens_scale and layer_separation options, as described above.


Q) I am using focal blurring, and I can't see the lens effect?
A: If you wish to use focal blurring you should set effect_always_on_top to false, and make sure that the effect_location is close to the focal_point vector.


Q) I am using a different camera projection, and the lens effect doesn't look right?
A: Try setting effect_always_on_top to false and see if this fixes the problem. Also, you can use the spots_spacing option to make the spots spread across the entire image if you are using a wide camera angle.


COPYRIGHT AND LEGAL INFORMATION
The Lens Effects Include File, including LnsEfcts.inc, Lens.inc, all documentation, and associated sample *.POV and *.LFX files are Copyright 1997, 1998 by Chris Colefax. Full permission is granted to the user to modify any or all of the files for his/her own use. If modified versions are to be distributed the user should make clear the modifications that have been made by him/herself.

The Lens Effects Include File may be bundled with or without other software on CD-ROM collections, Bulletin Board systems and other file archives, providing that all associated files, including documentation and samples, are included. I would also request that persons intending to distribute the Lens Effects Include File in this manner or otherwise would first contact me to ensure that they are in possession of the latest available version.

Further, no restrictions of any sort are placed on the usage of the include files themselves (LnsEfcts.inc and Lens.inc), and scene files or images created using the include files remain entirely the property of the user or users who have created them. I claim no liability or responsibility for damages or loss resulting from usage of the include files, or any part of the include file package.


CONTACTING THE AUTHOR
If you wish to contact me with bug reports, bug fixes, criticisms, comments, suggested improvements, questions, etc. you can reach me by email at:

ccolefax@geocities.com

or by regular mail at:


POV-RayTM and Persistence of VisionTM are registered trademarks of the POV-Ray TeamTM