Lighting
This chapter explains how the lighting works in the engine and which methods of lighting it uses. Fyrox uses industry-standard physically based rendering pipeline by default.
Ambient lighting
The engine uses PBR pipeline which supports two major ways of applying ambient lighting.
Environment lighting (via IBL)
Physically correct ambient image-based lighting (IBL). It uses an environment map as a source of lighting for the entire scene. By default, every scene has an environment map with bright-blue sky, and this bright lighting is used to light the scene. To change it, use the following code snippet:
#![allow(unused)] fn main() { async fn create_skybox(resource_manager: ResourceManager) -> SkyBox { // Load skybox textures in parallel. let (front, back, left, right, top, bottom) = fyrox::core::futures::join!( resource_manager.request::<Texture>("path/to/front.jpg"), resource_manager.request::<Texture>("path/to/back.jpg"), resource_manager.request::<Texture>("path/to/left.jpg"), resource_manager.request::<Texture>("path/to/right.jpg"), resource_manager.request::<Texture>("path/to/up.jpg"), resource_manager.request::<Texture>("path/to/down.jpg") ); // Unwrap everything. let skybox = SkyBoxBuilder { front: Some(front.unwrap()), back: Some(back.unwrap()), left: Some(left.unwrap()), right: Some(right.unwrap()), top: Some(top.unwrap()), bottom: Some(bottom.unwrap()), } .build() .unwrap(); // Set S and T coordinate wrap mode, ClampToEdge will remove any possible seams on edges // of the skybox. let skybox_texture = skybox.cubemap().unwrap(); let mut data = skybox_texture.data_ref(); data.set_s_wrap_mode(TextureWrapMode::ClampToEdge); data.set_t_wrap_mode(TextureWrapMode::ClampToEdge); skybox } fn set_scene_skybox(scene: &mut Scene, resource_manager: ResourceManager) { scene.set_skybox(create_skybox(resource_manager)); } }
This, however, may still produce weird lighting inside indoor scenes - all objects will be equally lit from the respective side of the skybox. The engine has a special mechanism to solve this issue called reflection probes. See the respective chapter for more info.
Single-color lighting
Simplest possible lighting, but not physically correct. Every scene has default ambient lighting setting, it is defined by a single RGB color. By default, every scene has some pre-defined ambient lighting, it is bright enough, so you can see your objects. In some cases, you may need to adjust it or even make it black (for horror games for instance), this can be achieved by a few lines of code:
#![allow(unused)] fn main() { fn set_ambient_lighting(scene: &mut Scene) { scene.rendering_options.ambient_lighting_color = Color::opaque(30, 30, 30); scene.rendering_options.environment_lighting_source = EnvironmentLightingSource::AmbientColor; }
Please keep in mind that ambient lighting does not mean global illumination, it is a different lighting technique which is not available in the engine yet.
Light Sources
There are number of built-in light sources:
- Directional Light
- Point Light
- Spot Light