Dynamic Lighting Demo for Adobe Atmosphere™ Ver 1.0
jim coe    12/04/2003
Dynamic Lighting Demo ver 1.1 download or view full screen Back to Lighting FX page
General
The new Preset Scripts:
Instead of using custom JavaScripts, which can be difficult for non-scriptors to understand or adapt, this demo uses only the new "Preset Scripts" that ship with your new version 1.0 Atmosphere.

Preset Scripts have two big advantages. You non-programmers can snap them into your scenes, modify the script behavior, and connect them to your objects, all without encountering any code. Preset Scripts also offer a standard way for you professional programmers or script-savvy builders to create, modify and distribute Atmosphere JavaScripts.
Dynamic Lighting:
"Dynamic Lighting" is a generic term for scene lighting that is calculated and rendered in real time as your world is viewed online, as opposed to the "static" or "pre-calculated" lighting that you render at build time in the Atmosphere authoring environment. In Atmosphere, you use dynamic lighting through what is called "distant light". So look for both terms: "dynamic lighting" and "distant light" as you learn.

You have two challenges in using dynamic lighting, besides just building your scene:
  1.  Using the authoring environment to properly install the preset scripts.
2.  Understanding and applying lighting values in the scripts, to get the look you want.

1 - Installing Your Scripts
(please refer to the Atmosphere User's Guide)
Using Preset Scripts:
1. Simply copy the scripts you need to the folder where you are building your world. Then import them using "File > Import > Script". You must be in the Scene Editor view to do this (double-clicking on the "Stage" icon in the Scene Hierarchy list is one way to get there, if you are currently in the Object Editor view). You will find the scripts in the "Extras" folder in the Atmosphere program files.

Alternately, you can right-click on the "Objects Presets" palette and select "Add Script Presets..." to retrieve the scripts. The "Presets" palettes act as libraries for storing your scene materials. To insert a script into your scene, click on a Preset Script, then on a wireframe view .

You use the "Object Inspector" to set your Preset Script values. Also, the "Script Editor" is available when you double-click a script object. The Script Editor is useful for reviewing any comments about how to use a script that may be included inside the script.
2.  You often need to use more than one copy of a script, applying each copy to a different Solid Object. For example, in my demo I used two copies of the script "rotateContinous.js" - one for each of my two rotating objects.

Because my two objects rotate around different centers and have different speeds of rotation, a separate copy of the rotate script is required for each, just as I had to place each rotating object under its own Solid Object. That is, each rotating object is a set of primitives which make up a separate Solid Object, so that each may be animated in different ways.

Multiple copies of scripts might get confusing, so feel free to rename your script objects (but not their file names) to make your scene construction easier to understand.
3.  Some scripts, such as those for rotation (but not Dynamic Lighting) must have their "script object" located in your scene at the center of action for the object to which they are applied.

For example, to install a rotate script, first verify the position of each rotating object in the Object Editor view (access the Object Editor by double-clicking on the Solid Object icon for the rotating object you are working on). Once the proper position is verified, you will probably want to lock your rotating objects so they are not moved accidentally. Then go into Scene Editor view and move your rotate script object to the center of rotation of your rotating Solid Object.

Most scripts require that you set user adjustable values. For instance, to do so for a rotation script, select the script object in your Scene Hierarchy, open the Object Inspector, select the "Target" value and drag the "Whip" tool over the correct Solid Object icon in the Scene Hierarchy. This applies the script to your desired object. Many Preset Scripts use the "Target" value and "Whip" to let you apply them to certain scene objects. Don't be confused by the addition of the "this" keyword to the target object name in the Object Inspector. That's just a standard way of preventing potential problems in your user-modified script.

Finally, set the other values you want. Do not be concerned if changing the values in one script seems to change other scripts at the same time. Only the value in the top "active edit" field will change. Your actual values, down in the values list, will not be affected. If you cannot get a value to "take" in Atmosphere, just use the Enter key to complete your value entry.

2 - Using Distant Light/Dynamic Light Preset Scripts
Unlike the rotation scripts, the Distant Light scripts I used are not attached to any particular Solid Object, nor positioned in any particular place in your scene. That's because I used the script which applies dynamic lighting to the whole scene at once. If you want, you may instead apply different dynamic lighting setups to individual Solid Objects or even to Viewpoint or Surface Objects.

Many scripts have useful comments that you should review. Double-click on a script in the Scene Hierarchy list to open it in the built-in Script Editor and read any comments.

Requirements for Distant Light
Be sure to prepare your scene for effective dynamic lighting:
1.  Only faces that you have previously lighted statically, that is, by the usual light rendering in the player view of the authoring environment, can take part in dynamic lighting.
2.  You don't want static lighting shadows or shading to conflict with the moving light and shadows of dynamic lighting. The best way to prevent this is to always do your static lighting in a way that is shadowless, when you are preparing a scene for dynamic lighting:
  • Turn off light rendering calculation for the Sun
  • Turn it on for the Background
  • Turn it on for Bounce (to help fill in holes and hollows)
  • Turn off all the shadow calculations
  • For your light source, use a pure white background (sky), that you set to emit light. I use an emit value of about 3 for the white background.
This will give you a very even and shadowless rendering. In fact it may be difficult for you to distinguish your objects. Not to worry, this is the right look for the dynamic lighting to come.

This might also result in a smaller light map file, speeding up your world. One Atmo beta tester even experimented with rendering a large world in pure black. They achieved a very small light map file size. Since the light map makes up a large part of the size of your scene file, careful static lighting and dynamic lighting could yield a significant savings in your scene's download time.

The Dynamic Lighting Preset Scripts
There are 6 dynamic lighting preset scripts supplied with version 1.0.

Dynamic light scripts always work in pairs. You must have a "distantLight" or "setDistantLight" script to enable dynamic lighting and control the light "source". You must also install a companion "useDynamicLighting" script to enable dynamic lighting for a particular target Solid Object in your scene - or one for the whole scene. I think of these as "Lights" and "Lit Objects".

Every scene has one built-in distant light by default and you can add more distant lights, using the proper script.
The 6 Dynamic Light Scripts   Script author, Gary Beardsley
* = the scripts I used in the demo                DL = Distant Light
1. distantLight-default.js Turns on the single default DL built into the scene and sets its qualities. You must also have a "usexxxx.js" script, Like "useDynamicLighting.js"
2. distantLight-new.js Adds a new DL to those already in your scene. You must also have a "usexxxx.js" script, like "useDynamicLighting.js"
3. * setDistantLight-default.js Sets the qualities of the DL source itself. Seems to be the same as "distantLight-default.js".
4. useDynamicLighting.js Enable the use of DL for a Solid Object or Surface Object.
5. useDynamicLightingForActor.js Enable the use of DL for an Avatar.
6. * useDynamicLightingForAll.js Enable the use of DL for everything in your scene, including all actors. Note: DL currently works with all scene objects! Avatars (Viewpoint of Atmo primitive), Viewpoint objects, Atmo primitives and Surface Objects are all nicely lit by DL.

Distant Light Script Values
The distant light scripts are very flexible, so they have several values. In the table below, I list these values for only the 2 scripts I used in this demo, but the others are very similar.
"setDistantLight-default.js" This adjusts the light "source"
Value My Setting Comment
Azimuth 208 degrees 0 to 360. Position around the horizon.
Brightness 0.8 0 to 10. Must be balanced against the brightness you want for your static lighting light maps and against the ambient light value.
CastShadows True Boolean (True or False)
Color 1, 0.75, 0 Red, Green, Blue. Mine is yellow-Orange
Cone angle 0.5 Default. Parallelism of the light rays ("collimation"). How much the light spreads out with distance. Very large values will cause light to spread around the sides of objects.
Elevation 10 degrees Distance above (+), or below (-) horizon. My demo has low sun.

"useDynamicLightingForAll.js" This adjusts the light's effect on the target(s)
- The 3 light sources you must balance are shown in red -
addDynamicHighlights True Enable specular hightlights/reflections for Viewpoint objects
ambientBrightness 0.05 Level of "environment" light (Vs static light Vs dynamic light)
anbientColor 0.25, 0, 1 Color of "environment" ambient light - I used bluish shadows
castShadowsOntoOthers True Target objects will make shadows onto other objects?
castShadowsOntoSelf True Target objects will make shadows onto parts of themselves?
diffuseBrightness 1.5 Level of dynamic light (Vs static light Vs ambient light)
diffuseColor 1, 0.75, 0 Color of dynamic light. I used yellow-orange. Notice that this allows you to set a color for each target that differs from the color of the distant light itself. For example, you could have distant light that is white, yet have it be red on one target and green on another.
lightMapBrightness 0.2 Level of static light (Vs dynamic light Vs ambient light)
lightMapColor 1, 1, 1 Color of static light. I used white.
receiveShadows True Receives shadows from DL? Note that objects can be made "transparent" to DL by setting this false, allowing DL to work inside enclosed spaces.
useDynamicLighting True Does the target object have dynamic lighting enabled?

Tips for Setting Your Scripts
A balancing act:
In using dynamic lighting, you are usually balancing 3 interacting lights. That is, the light maps from your static lighting during building, the dynamic light from distant light and the dynamic ambient light. Each of these three has a level ("brightness") and a color. These 3 lights are combined, according to your 3 brightness settings, when the dynamic lighting is calculated and rendered in real time in the player.

If you're not careful, this balancing act can lead to endless tweaking. I recommend that you leave the ambient brightness at zero while adjusting the other two lights. Then add in the ambient, a little at a time, until it just begins to "wash out" the shadows.

I find that if my static light maps are white (as in my demo) that I can use low levels of brightness for the static light maps and high values for the diffuse (dynamic) light.

You can see in the above table that I'm using only 0.2 brightness for static light maps but 1.5 for diffuse. In other words, I want the scene to be mostly lighted by dynamic light, with only enough static light to keep the textures visible and fill the shadows a bit.
But wait, there's more:
Getting the balance for three light sources is not enough. That just sets the "lighting ratio". You also have to arrive at a good combined brightness. For example, in my demo I want a sunset quality. So the level contributed by all three light types has to add up to be rather dark. If I had set all three brightnesses higher, I would still have the same lighting ratio, but the scene would be too bright.

The way I arrived at my levels was to adjust the shadows first, so that I could see some detail in the shadowed textures of the wall around the scene. Then I adjusted the diffuse (dynamic) light brightness until I got a bright level on one face of one of the white objects - a face that was reflecting the distant light directly at me. So, I used just enough light to provide good "form" to the large column - from the lightest value of one bright face reflecting the "sun" into my face, down through the darkest values of the shadowed faces.

Never forget that modeling your scene's forms is what lighting is all about. Before the dynamic lighting was applied, I had a pure white scene - a total "whiteout", where form was absent!

Colored Light
Be sure to consider the coloring of your lights. When you default to white light for all your lights you are throwing away an opportunity to add drama and realism (or surrealism) to your scene.

In the real world, lights are almost never pure white. In fact, when a scientist, photographer or engineer needs a source of pure white light it is not so easy to obtain! One of the strengths of our human visual system is that it rapidly adjusts to environments lighted by different colors and allows us to perceive a "white". But that does not mean we are not emotionally affected by these subtle color values and our adjustments to them.

Think about it. Even high noon sunlight is somewhat yellow. Sunset light is often orange or pink. Skylight (indirect sunlight provided by the scattered light of the sky) is light blue. Candle light and firelight are quite red. Incandescent lamps are yellow, while some fluorescent lamps are rather blue. Use color in your lighting to emphasize the qualities of your scene and provide clues about your light sources.

You are the Lighting Designer for your stage. If you add dynamic lighting to your Lighting Designer's toolkit, I think you will soon agree that it is a fun, flexible and beautiful creative tool.