Lights and Shadows: Physion's New Light Tool
Physion 0.8.5 adds Lights. A light shines in every direction or in a cone, stops at every body in its way, and leaves a shadow behind it. The shadows are worked out from the same physics world the bodies live in, so they move with the simulation: a box tumbling past a lamp drags its shadow along, frame by frame.
Placing a light
Pick the Light Tool in the Design Toolbar, click where the light should go and drag. The point you click is the light itself, and the drag sets how far it reaches and which way it faces, with a faint disc showing the reach as you go. Each new light gets a random color, which you can change in the Property Editor like everything else.
Start the drag on a body and the light is attached to it. It moves and turns with the body while the simulation runs, and that body never blocks its own light, so a car can carry its own headlights.
Its settings
Select a light and the Property Editor shows:
| Property | Default | What it does |
|---|---|---|
| Powered | on | Switches the light on and off. |
| Color | random | The color of the light and of its bulb. |
| Distance | the drag, or 10 m | How far the light reaches, in meters. It fades to nothing by the end. |
| Cone Angle | 360° | 360 is a point light shining every way. Lower it for a spotlight, which points the way the light is rotated. |
| Ray Count | 180 | Rays cast to find the shadows, from 3 to 720. More rays give smoother shadow edges and cost more. |
| Soft Edge Length | 0.5 m | How far a shadow's soft edge reaches past the body casting it. 0 gives hard shadows. |
| Cast Shadows | on | Off lets the light shine through every body, which is much cheaper, since no rays are cast at all. |
| Shadow Casters | all | The collision categories that block the light, so some bodies can cast shadows and others not. |
| Draw Body, Size | on | The bulb icon that marks the light. |
A light's Alpha works as its brightness.
Making the scene dark
A new scene has no darkness, so a light only adds a glow on top of it. The darkness belongs to the Scene: with nothing selected, click Select Scene in the Property Editor and lower Ambient Light. It is the brightness of every part of the scene that no light reaches, from 1 (fully bright) down to 0 (black).
Two more Scene properties go with it. Ambient Color tints the darkness, so a scene can be a moonlit blue rather than plain black. Light Map Blur softens the lights and their shadows, from 0 (sharp) to 32 pixels, with 8 by default.
In a dark scene the light reveals the scene's own colors rather than adding to them, so nothing gets brighter than its own fill color. A light Background Color gives the lit areas more to show.
Worth knowing
- Lights are visual only. Bodies block the light, but a light never touches the physics.
- Bodies cast shadows but are not lit themselves. A ray stops at a body's edge, so in a dark scene bodies show up as silhouettes against the lit area around them, as in the pictures above.
- Sensors and liquid particles never block light.
- Dark scenes have a quality setting. Light Map Quality, in the General section of the Settings Editor, sets the resolution of the darkness from Low to High (Medium by default). Off skips it entirely and draws every light as a plain glow, whatever the Ambient Light.
- Lights can be scripted. Every setting above can be changed from a
Node Script, and
contains(x, y)tells you whether a point in the scene is lit, which is enough for a light sensor or a guard's flashlight.
Frequently asked questions
How do I add a light in Physion?
Pick the Light Tool in the Design Toolbar, click where the light should go and drag. The drag sets how far the light reaches and which way it points. Everything else can be changed afterwards in the Property Editor.
How do I make a scene dark?
Select the Scene (with nothing selected, the Property Editor has a Select Scene button) and lower its Ambient Light. At 1 there is no darkness and lights only add a glow. At 0, everything a light does not reach is black.
Do lights affect the physics?
No. A light is not a body: it has no mass, collides with nothing, and the simulation runs exactly the same with or without it. Bodies block light, but light never pushes back.
Can a light move with a body?
Yes. Start the Light Tool's drag on a body and the light is attached to it. It moves and turns with the body while the simulation runs, and that body never blocks its own light, so a car can carry its own headlights.
Try it
Both pictures in this post came out of the running app. Open the app, drop a few bodies on a ground, set the Scene's Ambient Light to 0.15, and drag out a light.
