Graphics.DefiningLenses - lordmundi/wikidoctest GitHub Wiki

Defining Lenses

« Setting up a Control Node | EDGE User’s Guide | Defining Materials In EDGE »

EDGE uses the "dsp_speedtest3" plugin for most of its rendering. The plugin supports many of the latest effects being used in todays games including shadows, reflections, exposure-control, blooming, and lens-flare effects. This tutorial will describe how you setup a light source so that it will be considered for inclusion in computing lens flares as well as how to configure different lenses so that when a camera that is specified as using one of the defined lens types it will produce the "lens-flare" effect unique to the lens type.

First we must specify which nodes in the scene are sources of lens flare (usually these are light nodes). To do this we specify the nodes in the "FLARE_SOURCES" sub-block of the DSP_SPEEDTEST block. See the following example:

DSP_SPEEDTEST
   {
        FLARE_SOURCES
        {
              node(SUN);
                 type(DIRECT,0.23);
                 color(1.0,1.0,0.95);
                 intensity(1.0);
        }
   }

Here we are specifing that a node called "SUN" will be the source of lens-flares and that it is a "DIRECT" type of light (which means it is located at infinity) with a conic coverage angle on the infinite sphere of 0.23 degrees. The saturated color of the source is specified with the "color(red,green,blue)" command and the relative intensity is specified with the "intensity(0.0–1.0)" command. The intensity command is used to vary the brightness of the resultant lens flare so that you can have some sources that are considered dim compared to the "SUN".

In the following example we show how to specify a "SPOT" type of light for sourcing lens-flares:"

DSP_SPEEDTEST
   {
        FLARE_SOURCES
        {
              node(CP9_FLOOD);
                 type(SPOT,4.0,−1.0,0.0,0.0,70.0,8.0);
                 color(1.0,0.9,0.8);
                 intensity(0.1);
        }
   }

Here we are specifing that node "CP9_FLOOD" will be the source of lens-flares and that it will behave like a "SPOT" light source. The parameters following the "SPOT" type are "diameter", "dir_x", "dir_y", "dir_x", "cone_angle", "falloff_exponent". Notice how the intensity is specified much lower than our previous example where we were defining the "SUN". The only other type of flare source is the "POINT" type which takes a single argument which is "size" which specifies the spherical size of the point representing the light source.

Next we need to define our lenses and how they should respond to flare sources. The lens definitions are specified in the "LENSES" sub-block of DSP_SPEEDTEST. Look at the following example:

DSP_SPEEDTEST
   {
        FLARE_SOURCES
        {
              node(SUN);
                 type(DIRECT,0.23);
                 color(1.0,1.0,0.95);
                 intensity(1.0);

              node(CP9_FLOOD);
                 type(SPOT,4.0,−1.0,0.0,0.0,70.0,8.0);
                 color(1.0,0.9,0.8);
                 intensity(0.1);
        }

        LENSES
        {
            lens(ISS);
              element(−0.35,4.31,0.3,0.2,0.5,0.06,hex1.tex)       fade_angles(30.0,50.0)
              element(−0.25,5.31,0.0,0.2,0.8,0.07,hex1.tex)       fade_angles(30.0,45.0)
              element(−0.25,3.31,0.0,0.0,0.8,0.07,hex1.tex)       fade_angles(30.0,45.0)
              element(−0.20,4.00,0.0,0.7,0.0,0.12,hex1.tex)       fade_angles(30.0,50.0)
              element(−0.17,2.31,0.2,0.0,0.8,0.05,hex1.tex)       fade_angles(20.0,35.0)
              element(−0.2,1.31,0.2,0.3,0.8,0.08,hex3.tex)        fade_angles(20.0,35.0)
              element(−0.7,0.20,0.0,0.4,0.3,0.35,hex3.tex)        fade_angles(70.0,90.0)
              element(−0.3,0.07,0.0,0.1,0.9,0.40,hex2.tex)        fade_angles(70.0,90.0)
              element( 0.1,0.03,0.0,0.3,0.7,0.30,hex3.tex)        fade_angles(70.0,90.0)
              element( −0.01,0.01,0.0,0.7,0.8,0.70,hex2.tex)      fade_angles(70.0,90.0)
              element( 0.01,0.02,0.0,0.3,1.0,0.70,hex3.tex)       fade_angles(70.0,90.0)
              element( 0.2,0.09,0.0,0.3,1.0,0.70,hex3.tex)        fade_angles(70.0,90.0)
              element( 0.3,0.13,0.0,0.6,0.4,0.61,hex2.tex)        fade_angles(70.0,90.0)
              element( 0.6,0.30,0.0,0.4,1.0,0.50,hex3.tex)        fade_angles(70.0,90.0)
              element( 0.9,2.00,0.2,0.0,1.0,0.05,hex3.tex)        fade_angles(20.0,35.0)
              element( 0.15,2.30,0.0,0.0,1.0,0.06,hex1.tex)       fade_angles(20.0,35.0)
              element( 0.25,3.00,0.0,0.5,1.0,0.07,hex1.tex)       fade_angles(30.0,45.0)
              element( 0.30,2.80,0.2,1.0,0.8,0.06,hex1.tex)       fade_angles(34.0,50.0)
              element( 1.0,−700.0,1.0,1.0,1.0,1.0,starburst.tex)  off_screen(off)
        }
   }

In the example above a lens type called "ISS" is defined. It is defined as having 19 elements where each element represents an internal reflection off an element in a physical lens. The following explains the "element" command and its arguments:

element( location, size, R, G, B, density, image_file )

  • localtion "-1.0..1.0" specifies where along the vector from the "flare-source" through the center of the viewport does the flare reside. A value of 1.0 means directly where the "flare-source" is in the viewport and a value of −1.0 means a position directly opposite side of the view origin of the "flare-source".
  • size "> 0.0" means size realtive to veiwport size, "< 0.0" means autoscale based on brightness
  • R,G,B "0..1" color to modulate image by (this makes it possible to use a single greyscale image for multiple colored reflections)
  • density "0..1" specifies how much to scale the color by before add blending it to the scene
  • imafe_file is the image to use for the flare

The "fade_angles" command lets you define angles off-axis to the lens overwhich the image of the flare will fade to off simulating the effect of internal lens elements being gradually occluded by the front lens apature.

fade_angles( begin_angle, end_angle )

  • begin_angle The angle overwhich fadeout begins
  • end_angle The angle at which fadout is complete and the lensflare is no loger visiable

The "off_screen" command allows you to disable the default behavior where a lens flare would be left on after the flare sources leaves the viewport. It is set to "off" for elements that represent a bloom effect on the camera sensor which would only happen if the "flare-source" was directly visiable.

off_screen( state )

  • state Specifies the display state either "off" or "on" of the lensflare when the "flare-source" is outside of the viewport.

Now the last thing to do is specify which cameras use the lens definition we have and that is done in the "CAMERAS" sub-block of the DSP_SPEEDTEST block. Look at the "CAMERAS" block in the following example config file.

DSP_SPEEDTEST
   {
        FLARE_SOURCES
        {
              node(SUN);
                 type(DIRECT,0.23);
                 color(1.0,1.0,0.95);
                 intensity(1.0);

              node(CP9_FLOOD);
                 type(SPOT,4.0,&minus;1.0,0.0,0.0,70.0,8.0);
                 color(1.0,0.9,0.8);
                 intensity(0.1);
        }

        LENSES
        {
            lens(ISS);
              element(&minus;0.35,4.31,0.3,0.2,0.5,0.06,hex1.tex)       fade_angles(30.0,50.0)
              element(&minus;0.25,5.31,0.0,0.2,0.8,0.07,hex1.tex)       fade_angles(30.0,45.0)
              element(&minus;0.25,3.31,0.0,0.0,0.8,0.07,hex1.tex)       fade_angles(30.0,45.0)
              element(&minus;0.20,4.00,0.0,0.7,0.0,0.12,hex1.tex)       fade_angles(30.0,50.0)
              element(&minus;0.17,2.31,0.2,0.0,0.8,0.05,hex1.tex)       fade_angles(20.0,35.0)
              element(&minus;0.2,1.31,0.2,0.3,0.8,0.08,hex3.tex)        fade_angles(20.0,35.0)
              element(&minus;0.7,0.20,0.0,0.4,0.3,0.35,hex3.tex)        fade_angles(70.0,90.0)
              element(&minus;0.3,0.07,0.0,0.1,0.9,0.40,hex2.tex)        fade_angles(70.0,90.0)
              element( 0.1,0.03,0.0,0.3,0.7,0.30,hex3.tex)        fade_angles(70.0,90.0)
              element( &minus;0.01,0.01,0.0,0.7,0.8,0.70,hex2.tex)      fade_angles(70.0,90.0)
              element( 0.01,0.02,0.0,0.3,1.0,0.70,hex3.tex)       fade_angles(70.0,90.0)
              element( 0.2,0.09,0.0,0.3,1.0,0.70,hex3.tex)        fade_angles(70.0,90.0)
              element( 0.3,0.13,0.0,0.6,0.4,0.61,hex2.tex)        fade_angles(70.0,90.0)
              element( 0.6,0.30,0.0,0.4,1.0,0.50,hex3.tex)        fade_angles(70.0,90.0)
              element( 0.9,2.00,0.2,0.0,1.0,0.05,hex3.tex)        fade_angles(20.0,35.0)
              element( 0.15,2.30,0.0,0.0,1.0,0.06,hex1.tex)       fade_angles(20.0,35.0)
              element( 0.25,3.00,0.0,0.5,1.0,0.07,hex1.tex)       fade_angles(30.0,45.0)
              element( 0.30,2.80,0.2,1.0,0.8,0.06,hex1.tex)       fade_angles(34.0,50.0)
              element( 1.0,&minus;700.0,1.0,1.0,1.0,1.0,starburst.tex)  off_screen(off)
        }

        CAMERAS
        {
              node(CP_9); lens(ISS); bloom_image(vstrip1.tex,2.0);
        }
   }

In the above example we are specifing the camera node "CP_9" to use the "ISS" lens definition and also display a bloom image when the flare-source is in view. The optional "bloom_image" command is defined below:

bloom_image( image_file, size )

  • image_file Is the image to blend with the scene to represent a camera specific blooming effect
  • size Is the size of the bloomimg image where 1.0 is the size of the viewport, if "< 0.0" then that means scale it by the brightness of the "flare-source".