5.5. Lighting
Main Renderer-level methods:
setLight(int index, const Light& light)int addLight(const Light& light)removeLight(int index)Light* getLight(int index)clearLights()getLightCount()setMainDirectionalLight(...)setMainPointLight(...)setLightColor(...)setLightPosition(...)setLightDirection(...)setLightTemperature(...)setLightType(...)getLightColor()
Directional light example:
r.setMainDirectionalLight(
Vector3(-0.4f, -1.0f, -0.3f),
Color::fromTemperature(5200.0f),
1.0f
);
5.6. Shadows
Public methods:
setShadowsEnabled(bool enabled)getShadowsEnabled()setShadowOpacity(float opacity)setShadowColor(const Color& color)setShadowPlane(const Vector3& normal, float distance)setShadowPlaneY(float y)ShadowSettings& getShadowSettings()drawMeshShadow(Mesh* mesh)drawMeshInstanceShadow(MeshInstance* instance)
Typical setup:
r.setShadowsEnabled(true);
r.setShadowPlaneY(0.0f);
r.setShadowOpacity(0.6f);
5.7. Skybox and Background
Public methods:
setSkyboxEnabled(bool enabled)isSkyboxEnabled()setSkyboxType(SkyboxType type)setSkyboxWithLighting(SkyboxType type)Skybox& getSkybox()setClearColor(Color color)drawSkyboxBackground()
What setSkyboxWithLighting(...) does:
- switches the skybox preset
- picks the matching light color temperature
9. Lights
9.1. LightType
Supported types:
LIGHT_DIRECTIONALLIGHT_POINT
9.2. Light
Public fields:
typeintensitydirectionpositioncolorrange
Public methods:
setRange(float r)getCachedRGB(...)
Point light example:
Light lamp;
lamp.type = LIGHT_POINT;
lamp.position = Vector3(0.0f, 3.0f, 5.0f);
lamp.color = Color::fromRGB888(255, 210, 170);
lamp.intensity = 1.2f;
lamp.setRange(8.0f);
r.addLight(lamp);
12. Time of Day
12.1. TimeOfDayConfig
Fields:
dayLengthSecondsstartHourbaseIntensitynightIntensityautoAdvance
12.2. TimeOfDayController
Sky and main directional light controller based on the day cycle.
Main methods:
init(Renderer* r, const TimeOfDayConfig& cfg)setRenderer(Renderer* r)setDayLengthSeconds(float seconds)setAutoAdvance(bool enabled)setBaseIntensity(float intensity)setNightIntensity(float intensity)setTime(float hours, float minutes = 0.0f)getTimeHours() constgetTime01() constupdate(float deltaSeconds)
Example:
TimeOfDayController tod;
TimeOfDayConfig cfg;
cfg.dayLengthSeconds = 180.0f;
cfg.startHour = 8.0f;
tod.init(&r, cfg);
In the loop:
float dt = getDeltaTime();
tod.update(dt);
15.4. SceneHelper
Convenience helper for a simple scene.
Main methods:
addGround(...)addSun(...)renderGround()renderSun(...)setSunPosition(...)
This helper is meant for quick prototypes. For a more serious scene you usually work directly with Renderer, Light, SceneGraph and your own meshes.