-
Notifications
You must be signed in to change notification settings - Fork 133
Lights
The render pipeline supports various types of lights.
To create a light, you have to import the light classes. You can do this by doing from rpcore import SpotLight
for example.
After doing that, you should create an instance of your light and set the light properties. Using a PointLight
is as simple as:
from rpcore import PointLight
my_light = PointLight()
# set desired properties, see below
self.render_pipeline.add_light(my_light)
To create lights in blender, just use blenders builtin lamps. E.g. hit space, then enter Add lamp
, then select Point
for example. You should see a Physically Based Shading Properties panel if you installed the BAM exporter.
Notice: Make sure you call render_pipeline.prepare_scene(my_model)
after loading your scene, so that the render pipeline is aware of your lights.
There are several light types in the Pipeline. All lights share some properties (explanation see below). Here are some example properties set on a light:
light.pos = (1, 2, 3)
light.color = (0.2, 0.6, 1.0)
light.energy = 1000.0
light.ies_profile = self.render_pipeline.load_ies_profile("x_arrow.ies")
light.casts_shadows = True
light.shadow_map_resolution = 512
light.near_plane = 0.2
# Convenience functions:
light.set_color_from_temperature(temperature_in_kelvin)
The light position specifies the lights position in world space.
The light color controls the appearance of the light. A value of (1.0, 1.0, 1.0)
means plain white. The color will be normalized. In order to control the brightness of your lights, see the energy property.
You can also set a color from a given color temperature in Kelvin, which is more physically correct. You should see the 04-Lights sample for detailed information. Kelvin usually ranges from 2,000 to 20,000, whereas lower values produce more reddish colors:
The energy of the light control its brightness. It is typically in the range 0.5 - 2000.0, and heavily depends on the environment.
See [IES Profiles](IES Profiles).
To enable shadows on the light, use light.casts_shadows = True
. You can control the resolution of the shadow map with light.shadow_map_resolution = resolution
.
To avoid artifacts from objects which are very close to the light, you can set the near plane with light.near_plane = near_plane
. This behaves like on a regular camera lens.
This is a radial light positioned at a point. Point Lights have an additional radius and inner radius property, which can be set with:
point_light.radius
point_light.inner_radius
The radius controls the maximum distance in world space, which the light affects. The inner radius controls the size of the light, for point lights this is 0.0, but if you want to have area spherical lights, set this to a value greater than zero.
This is a light with a direction and angle, behaving like a camera, or a flashlight. The radius controls the maximum distance after which the influence of the light gets zero. The direction is the forward vector of the light. The FoV just behaves like the FoV on a camera. You can set the properties with:
spot_light.radius
spot_light.fov
spot_light.direction
# Helper functions for setting the direction:
spot_light.look_at(Vec3 position)
spot_light.look_at(float x, float y, float z)
More light types will follow
By default, shadow maps will only get updated when the light is created or moved. However, if you have dynamic objects, the shadows will not get updated. To tell the render pipeline that a certain region changed, there are two methods:
You can call self.render_pipeline.invalidate_region(<bounding volume>)
to tell the render pipeline that a given region
changed. This will update all shadow sources in that region when called.
If you have a region which frequently changes, you can use self.render_pipeline.add_dynamic_region(<bounding voulme>)
.
This is equivalent to calling invalidate_region
each frame.
Rendering Pipeline by tobspr (c) 2014 - 2016
For developers: