Polycode allows you to create point and spot lights and use them to light entities and cast shadows.

Contents

Creating and using lights in the IDE.

To add a light in the IDE entity editor, click on the add entity button in the top left corner of the editor screen. After creating the light, you can edit its settings in the entity properties to the right.

Creating lights in code.

You can create lights dynamically in code via the SceneLight class.

Polycode's lights get automatically sorted by the renderer and passed to materials based on distance to the rendered entity and the light's importance setting. Material shaders can define how many lights of each type they accept.

There are currently two types of lights you can create.

SceneLight::POINT_LIGHT - A positional light that shines in all directions.

SceneLight::SPOT_LIGHT - A positional, directional spot light that shines light in a cone. Can cast shadows.

To create a light, instantiate a SceneLight class and use Scene's addLight to add it to the scene. This adds it as a light to the scene, but it doesn't add it to the root entity as a child, so you can add it as a child to another entity if you need to attach the light to something else.

C++
SceneLight *light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5.0);
scene->addLight(light);
Lua
light = SceneLight(SceneLight.POINT_LIGHT, scene, 5.0)
scene:addLight(light)

Casting shadows

Spot lights can cast realtime shadow-mapped shadows on materials that support them.

In order to receive shadows, a SceneMesh must be using a shader that supports shadows. Polycode comes with a default material that can receive shadows called DefaultWithShadows.

To enable shadow casting on a light, you need to call endableShadows(true, 256) on the SceneLight instance. The second argument to this method is the shadow map resolution (more on that below). In the IDE, you can check the "Cast shadows" checkbox in the SceneLight properties.

There are two parameters that control the quality of the shadows. One is the shadow map resolution and the other is the field of view of the spotlight camera that is used to render the depth image used to calculate shadows (see the Shadow Mapping article on Wikipedia for more details on how it works).

The shadow map resolution setting controls the pixel resolution of the shadows are they are projected onto the material. The lower the resolutio, the more pixelated the shadows, but faster the shadow depth buffer rendering. The higher the resolution, the better the shadows look, but their rendering is slower. You can control how wide the shadow stretches in front of the spot light by changing the field of view of the spotlight camera. The wider the angle, the more it can see around the spotlight, but the more the resolution of the shadow map buffer is stretched across, making it more pixellated. Use this setting in conjunction with the spotlight angle setting to control the desired quality of the shadows.

You can change the spotlight camera FOV using the setShadowMapFOV method in code or in the SceneLight properties in the IDE entity editor.