Skip to content

Adding lights

Romain Milbert edited this page May 4, 2020 · 11 revisions

RaZ supports for now two types of lights:

  • A point light is a light source defined by its position; imagine a light bulb, for example.
  • A directional light is a light source defined by its direction; this is similar to the sun's behavior, being so distant that its light rays are seemingly parallel to each other.
#include <RaZ/Render/Light.hpp>

// White point light, floating above the ground

Raz::Entity& pointLight = world.addEntityWithComponent<Raz::Transform>(Raz::Vec3f(0.f, 1.f, 0.f));
pointLight.addComponent<Raz::Light>(Raz::LightType::POINT, // Type
                                    1.f,                   // Energy
                                    Raz::Vec3f(1.f));      // Color(RGB)

// Cyan directional light, pointing to the bottom left

// A directional light doesn't need transformations; no need for a Raz::Transform
Raz::Entity& directionalLight = world.addEntity();
directionalLight.addComponent<Raz::Light>(Raz::LightType::DIRECTIONAL, // Type
                                          Raz::Vec3f(-1.f, -1.f, 0.f), // Direction
                                          1.f ,                        // Energy
                                          Raz::Vec3f(0.f,  1.f, 1.f)); // Color (RGB)

Default shaders allow up to ten lights.

Clone this wiki locally