Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
Light.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
21#pragma once
22
23#include "../../core/Types.hpp"
25#include "../../math/Math.hpp"
27
28namespace esengine::ecs {
29
35ES_ENUM()
36enum class LightType : i32 {
37 Point = 0,
40 Spot = 3,
41};
42
53ES_COMPONENT(renderable=enabled)
54struct Light {
56 ES_PROPERTY(enum=LightType, tooltip="Point, Directional, Ambient, or Spot.")
58
62 ES_PROPERTY(animatable)
63 glm::vec4 color{1.0f, 1.0f, 1.0f, 1.0f};
64
66 ES_PROPERTY(animatable, min=0, tooltip="Brightness multiplier of the light.")
68
70 ES_PROPERTY(animatable, min=0, shown_when=type:Point|Spot,
71 tooltip="Falloff reach in world units (Point / Spot).")
72 f32 radius{200.0f};
73
78 ES_PROPERTY(animatable, min=0, shown_when=type:Point|Spot,
79 tooltip="Radius held at full strength before the falloff starts.")
81
86 ES_PROPERTY(animatable, min=0, max=8, shown_when=type:Point|Spot,
87 tooltip="Falloff shape: 1 = linear, higher pools near the light, lower reaches further.")
88 f32 falloff{1.0f};
89
95 ES_PROPERTY(shown_when=type:Point|Spot,
96 tooltip="Fall off as 1/distance² in metres (a real lamp): intensity is the light 1 m away, radius only where it ends.")
97 bool inverseSquare{false};
98
103 ES_PROPERTY(animatable, min=0, max=1, slider,
104 shown_when=type:Point|Directional|Spot,
105 tooltip="How much of this light its shadows remove (1 = all of it).")
107
113 ES_PROPERTY(min=-128, max=127, step=1, optional, shown_when=type:Point|Directional|Spot,
114 tooltip="The lowest sprite layer this light reaches (default: every layer).")
116
118 ES_PROPERTY(min=-128, max=127, step=1, optional, shown_when=type:Point|Directional|Spot,
119 tooltip="The highest sprite layer this light reaches (default: every layer).")
121
127 ES_PROPERTY(asset = texture, shown_when=type:Point|Spot,
128 tooltip="A texture whose alpha shapes this light (a cookie).")
130
135 ES_PROPERTY(animatable, min=0, shown_when=type:Point|Spot,
136 tooltip="Cookie size in world units; 0 = the light's own reach.")
137 glm::vec2 cookieSize{0.0f, 0.0f};
138
140 ES_PROPERTY(animatable, min=0, max=180, unit="°", advanced, shown_when=type:Spot)
142
144 ES_PROPERTY(animatable, min=0, max=180, unit="°", advanced, shown_when=type:Spot)
146
152 ES_PROPERTY(animatable, min=0, shown_when=type:Point|Directional|Spot,
153 tooltip="Shadow softness (light-source size); 0 = hard edge.")
155
160 ES_PROPERTY(animatable, min=0, max=90, unit="°", advanced, shown_when=type:Directional,
161 tooltip="Angular size of a Directional light's source (the sun is 0.53); 0 = hard edge.")
163
167 ES_PROPERTY(animatable, min=0, advanced, shown_when=type:Directional,
168 tooltip="Directional shadow distance; 0 = no directional shadow.")
170
175 ES_PROPERTY(shown_when=type:Point|Directional|Spot,
176 tooltip="Cast a shadow map over 3D meshes (Directional, Spot, Point).")
177 bool meshShadows{false};
178
182 ES_PROPERTY(min=0, advanced, shown_when=type:Directional,
183 tooltip="Shadow map coverage radius; 0 = fit the view.")
185
186 ES_PROPERTY(min=0, max=1, slider, advanced, shown_when=type:Directional,
187 tooltip="Where a sun's cascades are cut: 0 = evenly along the view, 1 = each cascade a fixed multiple farther (sharpest near the camera).")
189
190 ES_PROPERTY(min=0, max=16, advanced, shown_when=type:Point|Directional|Spot,
191 tooltip="Shadow map texels a surface is moved toward the light and off itself before it is tested: more removes acne, too much lifts the shadow off its caster.")
193
194 ES_PROPERTY(min=0.01, max=1, advanced, shown_when=type:Point|Directional|Spot,
195 tooltip="The least light a grazed surface is treated as facing, which caps the extra bias it gets: lower clears acne on walls the light skims, higher keeps their shadows attached.")
197
203 ES_PROPERTY(shown_when=type:Directional,
204 tooltip="Take direction and strength from the environment's sun, and light the sky without it.")
206
212 ES_PROPERTY(shown_when=type:Directional, advanced,
213 tooltip="With Follow Environment Sun: aim by this light's Transform, not by the panorama.")
214 bool aimFollowedSun{false};
215
221 ES_PROPERTY(asset = environment, shown_when=type:Ambient,
222 tooltip="Baked environment (.esenv) this Ambient light casts.")
223 resource::EnvironmentHandle environment;
224
229 ES_PROPERTY(unit=deg, shown_when=type:Ambient,
230 tooltip="Turn the environment about the up axis, in degrees.")
232
237 ES_PROPERTY(shown_when=type:Ambient,
238 tooltip="Draw this environment as the sky behind the scene.")
239 bool drawEnvironment{false};
240
245 ES_PROPERTY(min=0, shown_when=type:Ambient, advanced,
246 tooltip="Scale what baked reflection probes show (1 = as baked).")
248
254 ES_PROPERTY(min=0, animatable, shown_when=type:Ambient,
255 tooltip="Scale the light the environment gives surfaces, not what they reflect of it (1 = as the sky gives it).")
257
259 ES_PROPERTY(animatable, shown_when=type:Ambient,
260 tooltip="Tint the light the environment gives surfaces, not what they reflect of it (white = as the sky gives it).")
261 glm::vec4 diffuseTint{1.0f, 1.0f, 1.0f, 1.0f};
262
265 ES_PROPERTY(min=0, max=1, shown_when=type:Ambient, advanced,
266 tooltip="How much colour baked reflection probes keep (0 = grey).")
268
274 ES_PROPERTY(shown_when=type:Ambient, advanced,
275 tooltip="Multiply baked indirect light (lightmaps, probe volumes) by this colour (1 = as baked).")
276 glm::vec4 bakedTint{1.0f, 1.0f, 1.0f, 1.0f};
277
282 ES_PROPERTY(shown_when=type:Ambient,
283 tooltip="Light from above in Color, from below in Ground Color, blended by which way a surface faces.")
284 bool hemisphere{false};
285
288 ES_PROPERTY(animatable, shown_when=type:Ambient,
289 tooltip="The ambient colour a surface facing straight down receives (Hemisphere).")
290 glm::vec4 groundColor{0.35f, 0.3f, 0.25f, 1.0f};
291
294 bool enabled{true};
295};
296
309 ES_PROPERTY(asset = probeVolume, tooltip="Baked probe grid (.esprobes) filling this box.")
310 resource::ProbeVolumeHandle probes;
311
315 ES_PROPERTY(tooltip="Fill this box at run time from a capture at its centre (the room as lit now), not from a bake.")
316 bool capture{false};
317
320 ES_PROPERTY(min=0, shown_when=capture:true, tooltip="Seconds between captures (0 = once). Each one adds a bounce.")
322
324 ES_PROPERTY(min=0, tooltip="Half the box this volume covers, from the entity's position.")
325 glm::vec3 halfExtents{100.0f, 100.0f, 100.0f};
326
330 ES_PROPERTY(min=1, tooltip="World units between probes the next bake lays down.")
331 f32 spacing{100.0f};
332
335 bool enabled{true};
336};
337
338} // namespace esengine::ecs
Type-safe resource handle system.
Math utilities and GLM configuration for ESEngine.
Reflection and metadata system for automatic binding generation.
#define ES_COMPONENT(...)
Mark a struct/class as a component that should be exposed to scripts.
#define ES_ENUM(...)
Mark an enum that should be exposed to scripts.
#define ES_PROPERTY(...)
Mark a field as a property that should be exposed to scripts.
Core type definitions and utilities for ESEngine.
LightType
2D light kind. Point uses the Transform position + radius falloff; Directional uses the Transform's f...
Definition Light.hpp:36
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
float f32
32-bit floating point
Definition Types.hpp:59
A box of baked irradiance: the light for what a bake cannot hold still.
Definition Light.hpp:306
f32 spacing
World units a bake puts between probes. What the BAKE reads — the grid it produced carries its own re...
Definition Light.hpp:331
resource::ProbeVolumeHandle probes
The grid this box is read through. Invalid = nothing baked yet, which leaves everything inside lit ex...
Definition Light.hpp:310
f32 captureInterval
Seconds between captures; 0 captures once. Each lit view of the room includes the last capture's fill...
Definition Light.hpp:321
bool enabled
Disabled volumes are skipped during collection.
Definition Light.hpp:335
glm::vec3 halfExtents
Half the box's size, in world units, from the entity's position.
Definition Light.hpp:325
bool capture
Fill the box at run time from what a camera at its centre sees, all round: the walls as the lights li...
Definition Light.hpp:316
A 2D light contributing to Lit-shaded materials.
Definition Light.hpp:54
f32 environmentRotation
Turn the environment about +Y, in degrees. One number turns all three of it — sky,...
Definition Light.hpp:231
i32 layerMin
The lowest sprite layer this light reaches. A sprite on a layer below it is not lit by this light,...
Definition Light.hpp:115
i32 type
Light kind: 0 = Point, 1 = Directional, 2 = Ambient (see LightType).
Definition Light.hpp:57
bool followEnvironmentSun
Be the sun of the frame's environment. The direction and strength come from the panorama,...
Definition Light.hpp:205
glm::vec2 cookieSize
How big cookie is drawn, in world units. 0 on an axis covers the light's own reach on it — a square o...
Definition Light.hpp:137
bool drawEnvironment
Draw environment as the background as well as reflecting it. Off by default, so a scene that adopts a...
Definition Light.hpp:239
f32 innerRadius
How far the light stays at full strength before it starts falling off, in world units....
Definition Light.hpp:80
f32 shadowSoftness
Shadow penumbra softness = the light source's half-extent in world units; 0 is a hard edge (default)....
Definition Light.hpp:154
f32 radius
Point/Spot falloff radius in world units (ignored by Directional/Ambient).
Definition Light.hpp:72
bool meshShadows
Casts a shadow map over 3D meshes. Every type but Ambient can: a sun's map is cascades over the view,...
Definition Light.hpp:177
glm::vec4 groundColor
What a surface facing straight down receives with hemisphere on. Scaled by intensity,...
Definition Light.hpp:290
f32 innerAngle
Spot inner cone angle in degrees (full angle; fully lit inside).
Definition Light.hpp:141
f32 shadowDistance
Directional-light shadow reach in world units: how far its shadows are carried from whatever cast the...
Definition Light.hpp:169
bool inverseSquare
Falls off as the inverse square of the distance, in metres, as a real light does (glTF's and three....
Definition Light.hpp:97
f32 reflectionScale
What baked reflection probes show, scaled. A probe was baked under one sky, so it goes on showing tha...
Definition Light.hpp:247
bool hemisphere
Make this Ambient light two colours: color from above, groundColor from below, blended by which way a...
Definition Light.hpp:284
f32 sourceAngle
How wide a Directional light's source is, as the angle it subtends — the full angular diameter in deg...
Definition Light.hpp:162
glm::vec4 diffuseTint
The colour diffuseScale's light is tinted by, authored as color is. White = as the sky gives it.
Definition Light.hpp:261
f32 outerAngle
Spot outer cone angle in degrees (full angle; fades to dark by here).
Definition Light.hpp:145
i32 layerMax
The highest sprite layer this light reaches. See layerMin.
Definition Light.hpp:120
f32 falloff
The shape of the falloff between innerRadius and radius, as the power the linear ramp is raised to....
Definition Light.hpp:88
f32 shadowStrength
How much of this light a shadow takes away, 0..1. 1 (the default) is the whole of it; 0....
Definition Light.hpp:106
bool aimFollowedSun
With followEnvironmentSun, aim this light by its own Transform instead of by where the panorama's sun...
Definition Light.hpp:214
f32 diffuseScale
What the light this Ambient light's environment gives a surface (its diffuse half,...
Definition Light.hpp:256
glm::vec4 bakedTint
What baked INDIRECT light (a lightmap, a probe volume) is multiplied by. A bake holds the light of on...
Definition Light.hpp:276
glm::vec4 color
Light color, multiplied by intensity. RGBA for editor color-picker consistency with every other engin...
Definition Light.hpp:63
f32 intensity
Light strength multiplier.
Definition Light.hpp:67
f32 reflectionSaturation
How much colour baked reflections keep: 1 as baked, 0 grey. An overcast sky drains colour from what i...
Definition Light.hpp:267
f32 shadowExtent
Half-extent of the shadow map's world coverage: one map of this radius, centred on the middle of the ...
Definition Light.hpp:184
resource::EnvironmentHandle environment
What this Ambient light IS, when it is more than one colour: a baked panorama's irradiance and reflec...
Definition Light.hpp:223
bool enabled
Disabled lights are skipped during collection.
Definition Light.hpp:294
resource::TextureHandle cookie
A texture whose ALPHA is this light's shape — a lantern's glow, a window's shaft. Drawn at the light'...
Definition Light.hpp:129